File: index.docbook

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 (25921 lines) | stat: -rw-r--r-- 1,032,075 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
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book [
<!ENTITY url_refdocs_base_glib_html "https://gnome.pages.gitlab.gnome.org/glibmm/">
<!ENTITY url_refdocs_base_glib "&url_refdocs_base_glib_html;classGlib_1_1">
<!ENTITY url_refdocs_base_gio "&url_refdocs_base_glib_html;classGio_1_1">
<!ENTITY url_refdocs_base_gtk_html "https://gnome.pages.gitlab.gnome.org/gtkmm/">
<!ENTITY url_refdocs_base_gdk "&url_refdocs_base_gtk_html;classGdk_1_1">
<!ENTITY url_refdocs_base_gtk "&url_refdocs_base_gtk_html;classGtk_1_1">
<!ENTITY url_figures_base "figures/">
<!ENTITY url_examples_branch "master">
<!ENTITY url_examples_base "https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/&url_examples_branch;/examples/book/">
<!ENTITY url_gtkmm_base "https://gitlab.gnome.org/GNOME/gtkmm/tree/&url_examples_branch;/">
<!ENTITY gtkmm "<application xmlns='http://docbook.org/ns/docbook'>gtkmm</application>">
<!ENTITY uuml "&#252;">
<!ENTITY szlig "&#223;">
<!ENTITY verbar "&#124;">
<!ENTITY copy "&#169;">
<!ENTITY nbsp "&#160;">
]>
<!--
NOTE TO TUTORIAL DOCUMENTATION AUTHORS:
When referring to the gtkmm project in this document, please use the form
&gtkmm; so that the name is consistent throughout the document. This will wrap
gtkmm with <application></application> tags which can then be styled by CSS if
desired (e.g. boldface, monospace, etc) to make it stand out as the project
name
-->
<!--
Avoid <programlisting> elements within <para> elements.
In some situations (not quite clear exactly which situations) the translation
tools (itstool and friends) can't create translated index.docbook files if
a <programlisting> element occurs in a <para> element.
<programlisting> can be a direct child of e.g. <chapter>, <listitem>,
<sect1>, <sect2>, <sect3>, <sect4>, <sect5>, <section>.
See https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/merge_requests/11
-->
<book xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:id="index" xml:lang="cs">

  <info>
    <title xml:lang="en">Programming with <application>gtkmm</application> 4</title>
    <authorgroup>
      <author xml:lang="en">
        <personname><firstname>Murray</firstname><surname>Cumming</surname></personname>
      </author>
      <author xml:lang="en">
        <personname><firstname>Bernhard</firstname><surname>Rieder</surname></personname>
        <contrib>Chapter on "Timeouts".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Jonathon</firstname><surname>Jongsma</surname></personname>
        <contrib>Chapter on "Drawing with Cairo".</contrib>
        <contrib>Chapter on "Working with gtkmm's Source Code".</contrib>
        <contrib>Chapter on "Recent Files".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Ole</firstname><surname>Laursen</surname></personname>
        <contrib>Parts of chapter on "Internationalization".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Marko</firstname><surname>Anastasov</surname></personname>
        <contrib>Chapter on "Printing".</contrib>
        <contrib>Parts of chapter on "Internationalization".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Daniel</firstname><surname>Elstner</surname></personname>
        <contrib>Section "Build Structure" of chapter on "Wrapping C Libraries with gmmproc".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Chris</firstname><surname>Vine</surname></personname>
        <contrib>Chapter on "Multi-threaded programs".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>David</firstname><surname>King</surname></personname>
        <contrib>Section on Gtk::Grid.</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Pedro</firstname><surname>Ferreira</surname></personname>
        <contrib>Chapter on "Keyboard Events".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Kjell</firstname><surname>Ahlstedt</surname></personname>
        <contrib>Update from gtkmm 3 to gtkmm 4.</contrib>
        <contrib>Chapter on "Building applications".</contrib>
        <contrib>Chapter on "The DropDown Widget".</contrib>
        <contrib>Chapter on "ListView, GridView, ColumnView".</contrib>
      </author>
      <author xml:lang="en">
        <personname><firstname>Daniel</firstname><surname>Boles</surname></personname>
        <contrib>Notes on need to remove widgets in non-managed wrappers from parents to dispose, other tweaks.</contrib>
      </author>
    </authorgroup>

    <abstract>
      <!-- This text is copied from the introduction. -->
      <para>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.</para>
    </abstract>
    <copyright xml:lang="en">
      <year>2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010</year>
      <holder>Murray Cumming</holder>
    </copyright>

    <legalnotice>
      <para>Je 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.</para>
    </legalnotice>
  </info>

<chapter xml:id="chapter-introduction">
<title>Úvod</title>

<section xml:id="sec-this-book">
<title>O této knize</title>

<para>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.</para>

<para>Pro čtení této knihy se předpokládá dobrá znalost jazyka C++, včetně znalosti jak v C++ vytvořit program.</para>

<para>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>.</para>

</section>

<section xml:id="sec-gtkmm">
<title>gtkmm</title>

<para xml:lang="en">
<application>gtkmm</application> is a C++ wrapper for
<link xlink:href="http://www.gtk.org/">GTK</link>,
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.
</para>
<para xml:lang="en"><application>gtkmm</application> was originally named gtk-- because GTK was originally named GTK+
and had 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.</para>

<section xml:id="why-use-gtkmm">
<title xml:lang="en">Why use <application>gtkmm</application> instead of GTK?</title>

<para xml:lang="en"><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 realize that this leads to clearer and better organized code.</para>
<para><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.</para>
<para xml:lang="en">Inheritance 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.</para>
<para xml:lang="en">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.</para>
<para xml:lang="en"><application>gtkmm</application> involves less code compared to GTK, which uses prefixed function names and lots of cast macros.</para>
</section>

<section xml:id="gtkmm-vs-qt">
<title><application>gtkmm</application> ve srovnání s Qt</title>

<para>Nejbližší konkurencí <application>gtkmm</application> je Qt od Trolltechu, takže se na něj pojďme podívat blíže.</para>

<para xml:lang="en"><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 standardized 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 <link xlink:href="https://wiki.gnome.org/Projects/gtkmm/FAQ">FAQ</link> for more detailed differences.</para>
</section>

<section xml:id="gtkmm-is-a-wrapper">
<title><application>gtkmm</application> jen obaluje GTK+</title>

<para xml:lang="en">
<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.</para>
</section>
</section>

</chapter>

<chapter xml:id="chapter-installation">
<title>Instalace</title>

<section xml:id="sec-installation-dependencies">
<title>Závislosti</title>

<para xml:lang="en">
  Before attempting to install <application>gtkmm</application><application>-4.0</application>,
  you might first need to install these other packages.
</para>
<itemizedlist>
  <listitem><para xml:lang="en"><application>sigc++-3.0</application></para></listitem>
  <listitem><para xml:lang="en"><application>gtk4</application></para></listitem>
  <listitem><para xml:lang="en"><application>glibmm-2.68</application></para></listitem>
  <listitem><para xml:lang="en"><application>cairomm-1.16</application></para></listitem>
  <listitem><para xml:lang="en"><application>pangomm-2.48</application></para></listitem>
</itemizedlist>
<para>Tyto závislosti mají zase své vlastní závislosti, včetně následujících aplikací a knihoven:</para>
<itemizedlist>
  <listitem><para xml:lang="en"><application>pkg-config</application></para></listitem>
  <listitem><para xml:lang="en"><application>glib-2.0</application></para></listitem>
  <listitem><para xml:lang="en"><application>pango</application></para></listitem>
  <listitem><para xml:lang="en"><application>cairo</application></para></listitem>
  <listitem><para xml:lang="en"><application>gdk-pixbuf-2.0</application></para></listitem>
  <listitem><para xml:lang="en"><application>graphene-1.0</application></para></listitem>
</itemizedlist>
</section>

<section xml:id="sec-install-unix-and-linux">
<title>Unix a Linux</title>

<section xml:id="sec-linux-install-from-packages">
<title>Předem sestavené balíčky</title>

<para>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ší.</para>
<para xml:lang="en">
    The names of the <application>gtkmm</application> packages vary from distribution to distribution
    (e.g. <application>libgtkmm-4.0-dev</application> on Debian and Ubuntu or
    <application>gtkmm4.0-devel</application> on Red Hat and Fedora), so check
    with your distribution's package management program for the correct package
    name and install it like you would any other package.
</para>
<note>
<para xml:lang="en">
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> 4.8 supplied by Debian's
<application>libgtkmm-4.0-dev</application> package.
</para>
</note>
</section>

<section xml:id="sec-install-from-source">
<title>Instalace ze zdrojových kódů</title>

<para xml:lang="en">
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 <link xlink:href="https://download.gnome.org/sources/gtkmm/"/>.
</para>
<para xml:lang="en">
  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 with Meson. See the <filename>README</filename> file in the <application>gtkmm</application> version
  you've downloaded.
</para>
<note>
<para>Nezapomeň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.</para>
</note>
<para xml:lang="en">
    The <filename>configure</filename> script or <command>meson</command> 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.
</para>
<para xml:lang="en">
    By default, <application>gtkmm</application> if built with Meson or Autotools, 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
    one of:
<screen xml:lang="en">
# meson setup --prefix=/usr &lt;builddir&gt; &lt;srcdir&gt;
# meson configure --prefix=/usr
# ./configure --prefix=/usr
</screen>
</para>
<warning>
    <para>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ů.</para>
</warning>
<para>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>.</para>
</section>

</section>

<section xml:id="sec-packages-windows">
<title>Microsoft Windows</title>

<para xml:lang="en">GTK 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
<link xlink:href="https://wiki.gnome.org/Projects/gtkmm/MSWindows">Windows Installation</link>
page or the <link linkend="sec-windows-installation"><application>gtkmm</application> and Win32</link> appendix
for Windows-specific installation instructions and notes.</para>
</section>

</chapter>

<chapter xml:id="chapter-basics">
<title>Základy</title>

<para>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.</para>
<para>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++.</para>

<section xml:id="sec-basics-simple-example">
<title>Jednoduchý příklad</title>

<para>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ů.</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/base">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>base.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <gtkmm.h>

class MyWindow : public Gtk::Window
{
public:
  MyWindow();
};

MyWindow::MyWindow()
{
  set_title("Basic application");
  set_default_size(200, 200);
}

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.examples.base");

  return app->make_window_and_run<MyWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

<para xml:lang="en">We will now explain each part of the example</para>
<programlisting xml:lang="en"><code>#include &lt;gtkmm.h&gt;</code></programlisting>
<para>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.</para>

<para xml:lang="en">The next part of the program:</para>
<programlisting xml:lang="en"><code>class MyWindow : public Gtk::Window
{
public:
  MyWindow();
};

MyWindow::MyWindow()
{
  set_title("Basic application");
  set_default_size(200, 200);
}</code></programlisting>
<para xml:lang="en">
defines the <classname>MyWindow</classname> class. Its default constructor sets the
window's title and default (initial) size.
</para>

<para xml:lang="en">The <function>main()</function> function's first statement:</para>
<programlisting xml:lang="en"><code>auto app = Gtk::Application::create("org.gtkmm.examples.base");</code></programlisting>
<para xml:lang="en">
creates a <classname>Gtk::Application</classname> object, stored in a <classname>Glib::RefPtr</classname> smartpointer.
This is needed in all <application>gtkmm</application> applications. The <methodname>create()</methodname> method for this object initializes <application>gtkmm</application>.
</para>

<para xml:lang="en">
The last line creates and shows a 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 <parameter>argc</parameter> and <parameter>argv</parameter> arguments, passed to your application on the command line,
can be checked when <methodname>make_window_and_run()</methodname> is called, but this simple application does not use those arguments.
</para>
<programlisting xml:lang="en"><code>return app-&gt;make_window_and_run&lt;MyWindow&gt;(argc, argv);</code></programlisting>

<para xml:lang="en">
After putting the source code in <literal>simple.cc</literal> you can compile
the above program with <application>gcc</application> using:
</para>
<programlisting xml:lang="en"><code>g++ simple.cc -o simple `pkg-config --cflags --libs gtkmm-4.0` -std=c++17</code></programlisting>
<para xml:lang="en">
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. <literal>-std=c++17</literal> is necessary only if
your compiler is not C++17 compliant by default.
</para>
</section>

<section xml:id="sec-headers-and-linking">
<title>Hlavičkové soubory a linkování</title>

<para xml:lang="en">
Although we have shown the compilation command for the simple example, you really
should use the <link xlink:href="https://mesonbuild.com/">Meson build system</link>.
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.
The <filename>README</filename> file in <application>gtkmm-documentation</application>
describes how to build the examples.
</para>
<para>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.</para>
<para xml:lang="en">
However, this is even simpler when using the <function>dependency()</function> function
in a <filename>meson.build</filename> file with Meson. For instance:
</para>
<programlisting xml:lang="en"><code>gtkmm_dep = dependency('gtkmm-4.0', version: '&gt;= 4.6.0')</code></programlisting>
<para xml:lang="en">
This checks for the presence of gtkmm and defines <literal>gtkmm_dep</literal> for use
in your <filename>meson.build</filename> files. For instance:
</para>
<programlisting xml:lang="en"><code>exe_file = executable('my_program', 'my_source1.cc', 'my_source2.cc',
  dependencies: gtkmm_dep,
  win_subsystem: 'windows',
)</code></programlisting>
<para xml:lang="en">gtkmm-4.0 is the name of the current stable API. There are older APIs called gtkmm-2.4
and gtkmm-3.0 which install in parallel when they are available. There are 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. There might be a future gtkmm-5.0 API which would install in parallel
with gtkmm-4.0 without affecting existing applications.
</para>
<para xml:lang="en">If you start by experimenting with a small application that you plan to use just for yourself,
it's easier to start with a <filename>meson.build</filename> similar to the <filename>meson.build</filename> files
in the <link linkend="chapter-building-applications">Building applications</link> chapter.
</para>

<para xml:lang="en">If you use the older Autotools build system, see also the GNU site. It has more
information about <link xlink:href="https://www.gnu.org/software/autoconf/">autoconf</link>
and <link xlink:href="https://www.gnu.org/software/automake/">automake</link>.
There are also some books describing Autotools: "GNU Autoconf, Automake, and Libtool"
by Gary Vaughan et al. and "Autotools, A Practitioner's Guide to GNU Autoconf,
Automake, and Libtool" by John Calcote.
</para>

</section>

<section xml:id="sec-widgets-overview">
<title>Widgety</title>

<para>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.</para>
<para xml:lang="en">Widgets 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:
</para>
<programlisting xml:lang="en"><code>m_box.append(m_Button1);
m_box.append(m_Button2);</code></programlisting>
<para xml:lang="en">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:
</para>
<programlisting xml:lang="en"><code>m_frame.set_child(m_box);</code></programlisting>
<para>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>.</para>

<para xml:lang="en">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
<filename class="extension">.ui</filename> XML files and load them at runtime with
<classname>Gtk::Builder</classname>. See the <link linkend="chapter-builder">Gtk::Builder</link> chapter.
</para>

<para xml:lang="en">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. The <function>Gtk::make_managed()</function>
allows you to create a new widget and state that it will become owned by the
container into which you place it. This allows you to create the widget, add it
to the container and not be concerned about deleting it, since that will occur
when the parent container (which may itself be managed) is deleted. You can
learn more about <application>gtkmm</application> memory management techniques in the
<link linkend="chapter-memory">Memory Management chapter</link>.
</para>

</section>

<section xml:id="sec-signals-overview">
<title>Signály</title>

<para><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í.</para>
<para xml:lang="en"><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":
</para>
<programlisting xml:lang="en"><code>m_button1.signal_clicked().connect( sigc::mem_fun(*this,
  &amp;HelloWorld::on_button_clicked) );</code></programlisting>

<para>Více informací o signálech najdete v <link linkend="chapter-signals">dodatku</link>.</para>
<para>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>.</para>

</section>

<section xml:id="sec-basics-ustring">
<title>Glib::ustring</title>

<para>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.</para>
<para xml:lang="en">std::string uses 8 bits per character, but 8 bits aren't enough to encode languages such as Arabic, Chinese, and Japanese.
Although the encodings for these languages have been specified by the <link xlink:href="http://www.unicode.org/">Unicode Consortium</link>,
the C and C++ languages do not yet provide any standardized Unicode support for UTF-8 encoding.
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.</para>
<para>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>.</para>
<para>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“).</para>
<para>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ů.</para>

<para>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.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/classGlib_1_1ustring.html">Reference</link></para>

<para>Více informací o poskytování řetězcových literálů v UTF-8 viz kapitola <link linkend="chapter-internationalization">Internacionalizace</link>.</para>

</section>

<section xml:id="sec-basics-gobj-and-wrap">
<title>Míchání API z C a C++</title>

<para xml:lang="en">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 <classname>GObject</classname> system.</para>

<para xml:lang="en">
To use a <application>gtkmm</application> instance with a C function that requires a C
<classname>GObject</classname> instance, use the C++ instance’s
<function>gobj()</function> function to obtain a pointer to the underlying C
instance. For example:</para>
<programlisting xml:lang="en"><code>Gtk::Button button("example");
gtk_button_do_something_that_gtkmm_cannot(button.gobj());
</code></programlisting>

<para xml:lang="en">
To obtain a <application>gtkmm</application> instance from a C <classname>GObject</classname> instance,
use one of the many overloaded <function>Glib::wrap()</function> functions.
The C instance’s reference count is not incremented, unless you set the optional
<parameter>take_copy</parameter> argument to <literal>true</literal>. For
example:</para>
<programlisting xml:lang="en"><code>GtkButton* cbutton = get_a_button();
Gtk::Button* button = Glib::wrap(cbutton);
button-&gt;set_label("Now I speak C++ too!");
</code></programlisting>
<para xml:lang="en">The C++ wrapper shall be explicitly deleted if
<itemizedlist>
<listitem><para xml:lang="en">it's a widget or other class that inherits from <classname>Gtk::Object</classname>, and</para></listitem>
<listitem><para xml:lang="en">the C instance has a floating reference when the wrapper is created, and</para></listitem>
<listitem><para xml:lang="en"><function>Gtk::manage()</function> has not been called on it (which includes if it was created with <function>Gtk::make_managed()</function>), or</para></listitem>
<listitem><para xml:lang="en"><function>Gtk::manage()</function> was called on it, but it was never added to a parent.</para></listitem>
</itemizedlist>
<function>Glib::wrap()</function> binds the C and C++ instances to each other.
Don't delete the C++ instance before you want the C instance to die.
</para>
<para xml:lang="en">In all other cases the C++ instance is automatically deleted when the last reference
to the C instance is dropped. This includes all <function>Glib::wrap()</function>
overloads that return a <classname>Glib::RefPtr</classname>.</para>

</section>

<section xml:id="sec-helloworld">
<title>„Ahoj Světe“ v <application>gtkmm</application></title>

<para>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>:</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/helloworld">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>helloworld.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H

#include <gtkmm/button.h>
#include <gtkmm/window.h>

class HelloWorld : public Gtk::Window
{

public:
  HelloWorld();
  ~HelloWorld() override;

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

  //Member widgets:
  Gtk::Button m_button;
};

#endif // GTKMM_EXAMPLE_HELLOWORLD_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>helloworld.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "helloworld.h"
#include <iostream>

HelloWorld::HelloWorld()
: m_button("Hello World")   // creates a new button with label "Hello World".
{
  // Sets the margin around the button.
  m_button.set_margin(10);

  // When the button receives the "clicked" signal, it will call the
  // on_button_clicked() method defined below.
  m_button.signal_clicked().connect(sigc::mem_fun(*this,
              &HelloWorld::on_button_clicked));

  // This packs the button into the Window (a container).
  set_child(m_button);
}

HelloWorld::~HelloWorld()
{
}

void HelloWorld::on_button_clicked()
{
  std::cout << "Hello World" << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "helloworld.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<HelloWorld>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

<para>Než budeme pokračovat, zkuste si ji přeložit a spustit. Měli byste vidět něco takového:</para>

<figure xml:id="figure-helloworld">
  <title>Hello World</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/helloworld.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para>Pěkný výsledek, ne? Pojďme si kód vysvětlit. Nejprve třída <classname>HelloWorld</classname>:</para>

<programlisting xml:lang="en"><code>class HelloWorld : public Gtk::Window
{
public:
  HelloWorld();
  ~HelloWorld() override;

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

  //Member widgets:
  Gtk::Button m_button;
};</code></programlisting>

<para xml:lang="en">
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 initialization work for the window,
including setting up the signals. Here it is, with the comments
omitted:
</para>

<programlisting xml:lang="en"><code>HelloWorld::HelloWorld()
: m_button("Hello World")
{
  m_button.set_margin(10);
  m_button.signal_clicked().connect(sigc::mem_fun(*this,
    &amp;HelloWorld::on_button_clicked));
  set_child(m_button);
}</code></programlisting>

<para xml:lang="en">
Notice that we've used an initializer statement to give the <literal>m_button</literal>
object the label "Hello World".
</para>

<para xml:lang="en">
Next we call the Button's <methodname>set_margin()</methodname> method. This sets
the amount of space around the button.
</para>

<para>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>.</para>

<para xml:lang="en">
Next, we use the Window's <methodname>set_child()</methodname> method to put
<literal>m_button</literal> in the Window. The <methodname>set_child()</methodname>
method places the Widget in the Window.
</para>

<para>Nyní se pojďme podívat na funkci <function>main()</function> našeho programu. Zde je i s komentáři:</para>

<programlisting xml:lang="en"><code>int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");
  return app-&gt;make_window_and_run&lt;HelloWorld&gt;(argc, argv);
}</code></programlisting>

<para xml:lang="en">
First we instantiate an object stored in a <classname>Glib::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.
</para>

<para xml:lang="en">
Next we call <methodname>make_window_and_run()</methodname> which creates an object
of our <classname>HelloWorld</classname> class, shows that 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, <methodname>make_window_and_run()</methodname> will return,
causing our <function>main()</function> function to return. The application will then finish.
</para>

<para xml:lang="en">
Like the simple example we showed earlier, this Hello World program does not use
the command-line parameters.
</para>

</section>
</chapter>

<chapter xml:id="changes-gtkmm3">
<title>Změny v <application>gtkmm</application> 3</title>

<para xml:lang="en"><application>gtkmm</application>-3.0 is an old version of the <application>gtkmm</application> API that installs in parallel with the still older <application>gtkmm</application>-2.4 API and the new <application>gtkmm</application>-4.0 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.</para>

<para>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>.</para>

<para><application>gtkmm</application> 3 přidává některé nové třídy:</para>

<orderedlist inheritnum="ignore" continuation="restarts">
<listitem><simpara><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.</simpara></listitem>
<listitem><simpara><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í.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::Switch</classname> displays On/Off states more explicitly than <classname>Gtk::CheckButton</classname>. It may be useful, for instance, when allowing users to activate hardware.</simpara></listitem>
</orderedlist>

<para><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:</para>

<para>
<orderedlist inheritnum="ignore" continuation="restarts">

<listitem><simpara><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é.</simpara></listitem>

<listitem><simpara>Gtk::ComboBox nyní odvozuje z CellLayout, díky čemuž je rozvržení a zarovnání jeho instancí <classname>Gtk::CellRenderer</classname> snazší.</simpara></listitem>

<listitem><simpara><classname>Gtk::Adjustment</classname>, <classname>IconSet</classname> a <classname>Gdk::Cursor</classname> se teď používají přes <classname>Glib::RefPtr</classname>.</simpara></listitem>

<listitem><simpara><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>.</simpara></listitem>

<listitem><simpara><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.</simpara></listitem>

<listitem><simpara><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>.</simpara></listitem>

<listitem><simpara>Metoda 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>.</simpara></listitem>

<listitem><simpara><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.</simpara></listitem>

<listitem><simpara xml:lang="en"><classname>Gdk::Pixmap</classname> and <classname>Gdk::Bitmap</classname> were removed in favor of <classname>Gdk::Pixbuf</classname>.</simpara></listitem>

<listitem><simpara>Třída <classname>Gdk::Drawable</classname> byla odstraněn a jeho metody přesunuty do <classname>Gdk::Window</classname>.</simpara></listitem>

<listitem><simpara>Nyní v několika metodách používáme std::vector místo mezilehlého typu *Handle, aby bylo API čistší.</simpara></listitem>

</orderedlist>
</para>

<para xml:lang="en">All deprecated API was removed in <application>gtkmm</application> 3.0, though there have been new deprecations in later <application>gtkmm</application> 3.x versions.</para>

<para xml:lang="en">As 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 <link xlink:href="https://wiki.gnome.org/Projects/gtkmm/PortingToGtkmm3">gtkmm 3 porting wiki page</link> for more details.</para>

</chapter>

<chapter xml:id="changes-gtkmm4">
<title xml:lang="en">Changes in <application>gtkmm</application>-4.0 and <application>glibmm-2.68</application></title>

<para xml:lang="en"><application>gtkmm</application>-4.0 is a new version of the <application>gtkmm</application> API that installs in parallel with the
older <application>gtkmm</application>-2.4 and <application>gtkmm</application>-3.0 APIs. The last version of the <application>gtkmm</application>-3.0 API
is <application>gtkmm</application> 3.24. <application>gtkmm</application> 4 has no major fundamental differences to <application>gtkmm</application> 3 but
does make several changes (both small and large ones) that were not possible while
maintaining binary compatibility. If you never used the <application>gtkmm</application>-3.0 API then you
can safely ignore this chapter.
</para>

<para xml:lang="en"><application>gtkmm</application> 4's library is called <literal>libgtkmm-4.0</literal> rather than
<literal>libgtkmm-3.0</literal> and installs its headers in a similarly-versioned
directory, so your <application>pkg-config</application> check should ask for
<literal>gtkmm-4.0</literal> rather than <literal>gtkmm-3.0</literal>.
</para>

<para xml:lang="en"><application>gtkmm</application>-4.0 is used in combination with <application>glibmm-2.68</application>,
which sets the global locale for your program. The older <application>glibmm-2.4</application>
does not do that, and <application>gtkmm</application>-3.0 does it only to some extent. What this means is
briefly that if your <application>gtkmm</application>-3.0 program contains a call to
<function>std::locale::global(std::locale(""))</function>, you can probably remove it.
If you don't want <application>glibmm</application> or <application>gtkmm</application>
to set the global locale for you, you should add a call to
<function>Glib::set_init_to_users_preferred_locale(false)</function> before any call to
<function>Glib::init()</function> or <methodname>Gtk::Application::create()</methodname>.
See the <application>glibmm</application> <link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/namespaceGlib.html">
reference</link>.</para>

<para xml:lang="en">There are lots and lots of differences between <application>gtkmm</application>-3.0 and <application>gtkmm</application>-4.0.
The following lists are not complete.</para>

<para xml:lang="en">There are some important behavioural changes, to which you must adapt when migrating:</para>
<para>
<itemizedlist>
<listitem><simpara xml:lang="en">
Whereas in <application>gtkmm</application>-3.0, destruction of a non-managed C++ widget wrapper caused the wrapped GtkWidget
to be destroyed, changes in GTK4 mean that in <application>gtkmm</application>-4.0 this canʼt always be the case. GTK4 has no
uniform way to remove a widget from a parent, as GTK3 did with <methodname>Gtk::Container::remove()</methodname>,
so <application>gtkmm</application>-4.0 canʼt do the removal for you as <application>gtkmm</application>-3.0 did. Hence, if a non-managed C++ widget
instance is destructed while the widget is a child of another, <application>gtkmm</application>-4.0 wonʼt remove it from the
parent, the parent retains a ref that stops the child being disposed, and the GtkWidget stays alive.
The end result is that to destroy a non-managed widget with its C++ wrapper you must first remove it
from its parent (however that parent allows) so the C++ wrapperʼs dtor can drop the final reference.
</simpara></listitem>
</itemizedlist>
</para>

<para xml:lang="en">Some new classes were added in <application>gtkmm</application> 4 and <application>glibmm</application> 2.68:</para>
<orderedlist inheritnum="ignore" continuation="restarts">
<listitem><simpara xml:lang="en"><classname>Glib::ExtraClassInit</classname> and <classname>Gtk::Snapshot</classname>:
  These classes are needed only for writing custom widgets. See the
  <link linkend="sec-custom-widgets">Custom Widgets</link> section.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::EventControllerKey</classname>,
  <classname>Gtk::EventControllerMotion</classname>, <classname>Gtk::EventControllerScroll</classname>
  and <classname>Gtk::GestureStylus</classname></simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gdk::Paintable</classname>, <classname>Gdk::Texture</classname>,
  <classname>Gtk::Picture</classname> and <classname>Gtk::WidgetPaintable</classname>
  </simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gdk::Window</classname> has been renamed to <classname>Gdk::Surface</classname>.
  (<classname>Gtk::Window</classname> keeps its name.)</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gdk::DrawContext</classname> and <classname>Gdk::CairoContext</classname>
  are new. <classname>Gdk::DrawingContext</classname> has been removed.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::Clipboard</classname> has been replaced by the new
  <classname>Gdk::Clipboard</classname>.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gdk::DragContext</classname> has been split into
  <classname>Gdk::Drag</classname> and <classname>Gdk::Drop</classname>.</simpara></listitem>
</orderedlist>

<para xml:lang="en">There have also been several changes to the API, which you will probably encounter
when porting code that used <application>gtkmm</application>-3.0 and <application>glibmm</application>-2.4. Here is a short list:</para>
<para>
<orderedlist inheritnum="ignore" continuation="restarts">
<listitem><simpara xml:lang="en">A C++17 compiler is required.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::Button</classname>, <classname>Gtk::ToolButton</classname>,
  <classname>Gtk::MenuItem</classname> and <classname>Gtk::Switch</classname>
  implement the <classname>Gtk::Actionable</classname> interface instead of the removed
  <classname>Gtk::Activatable</classname> interface.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::FontButton</classname> implements the <classname>Gtk::FontChooser</classname> interface.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::Widget</classname>: The <methodname>get_preferred_*_vfunc()</methodname>s
  have been replaced by <methodname>measure_vfunc()</methodname>. This change only affects
  custom widgets.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>sigc::slot</classname>s use the <classname>sigc::slot&lt;R(Args...)&gt;</classname> syntax.
  Example: <classname>sigc::slot&lt;void(int, int)&gt;</classname> instead of <classname>sigc::slot&lt;void, int, int&gt;</classname>.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::DrawingArea</classname> uses a draw function instead of the draw signal.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Glib::ArrayHandle</classname>, <classname>Glib::StringArrayHandle</classname>,
  <classname>Glib::ListHandle</classname> and <classname>Glib::SListHandle</classname> have been removed.
  They were used in <application>glibmm</application>-2.4, but not used in <application>gtkmm</application>-3.0.
  If you've ever used these classes, replace them with a standard C++ container, such as <classname>std::vector</classname>.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::Container</classname> has been removed.</simpara></listitem>
<listitem><simpara xml:lang="en"><methodname>Gtk::Widget::show_all()</methodname> has been removed. The default value
  of <methodname>Gtk::Widget::property_visible()</methodname> has been changed from
  <literal>false</literal> to <literal>true</literal>.</simpara></listitem>
<listitem><simpara xml:lang="en">All event signals have been removed from <classname>Gtk::Widget</classname>.
  In most cases you can use one of the subclasses of <classname>Gtk::EventController</classname>
  as a replacement. For instance, use <classname>Gtk::GestureMultiPress</classname>
  instead of <methodname>signal_button_press_event()</methodname> and
  <methodname>signal_button_release_event()</methodname>, and <classname>Gtk::EventControllerKey</classname>
  instead of <methodname>signal_key_press_event()</methodname> and
  <methodname>signal_key_release_event()</methodname>.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Glib::RefPtr</classname> is an alias for <classname>std::shared_ptr</classname>.
  If you make your own <classname>Glib::ObjectBase</classname>-derived classes with
  <methodname>create()</methodname> methods that return a <classname>Glib::RefPtr</classname>,
  you must use <methodname>Glib::make_refptr_for_instance()</methodname> in your
  <methodname>create()</methodname> methods.</simpara></listitem>
<listitem><simpara xml:lang="en"><methodname>Gtk::Box::pack_start()</methodname> and <methodname>Gtk::Box::pack_end()</methodname>
  have been removed. Use the new <classname>Gtk::Box</classname> methods
  <methodname>append()</methodname>, <methodname>prepend()</methodname>,
  <methodname>insert_child_after()</methodname> and <methodname>insert_child_at_start()</methodname>.
  </simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::ButtonBox</classname> has been removed.</simpara></listitem>
<listitem><simpara xml:lang="en"><classname>Gtk::RadioButton</classname> and <classname>Gtk::RadioButtonGroup</classname>
  have been removed. Use <classname>Gtk::CheckButton</classname> or <classname>Gtk::ToggleButton</classname>
  with <methodname>set_group()</methodname>.</simpara></listitem>
</orderedlist>
</para>
<para xml:lang="en">All deprecated API was removed in <application>gtkmm</application> 4.0 and <application>glibmm</application> 2.68,
  though there will be new deprecations in future versions.</para>

<para xml:lang="en">As a first step to porting your source code to <application>gtkmm</application>-4.0 you should probably ensure
that your application builds with the deprecated <application>gtkmm</application>-3.0 and <application>glibmm-2.4</application>
API disabled, by defining the macros GTKMM_DISABLE_DEPRECATED, GDKMM_DISABLE_DEPRECATED,
GLIBMM_DISABLE_DEPRECATED and GIOMM_DISABLE_DEPRECATED. There are some autotools macros
that can help with this by defining them optionally at build time. See the
<link xlink:href="https://wiki.gnome.org/Projects/gtkmm/PortingToGtkmm3">Porting from
gtkmm-2.4 to gtkmm-3.0</link> wiki page for more details.</para>
<para xml:lang="en">See also <link xlink:href="https://docs.gtk.org/gtk4/migrating-3to4.html">
Migrating from GTK 3.x to GTK 4</link>.</para>

<section xml:id="sec-deprecations-4-10">
<title xml:lang="en">Deprecations in <application>gtkmm</application> 4.10</title>
<para xml:lang="en">Many classes are deprecated since <application>gtkmm</application> 4.10. They can still be used in
<application>gtkmm</application>4 applications, provided GTKMM_DISABLE_DEPRECATED and GDKMM_DISABLE_DEPRECATED
are not defined. There are also many new classes in <application>gtkmm</application> 4.10, which replace
some of the deprecated classes. Some example programs in this tutorial use classes
deprecated since <application>gtkmm</application> 4.10. Some other programs use classes available since <application>gtkmm</application> 4.10.
</para>
<para xml:lang="en">Deprecated classes:
  AppChooser, AppChooserButton, AppChooserDialog,
  AppChooserWidget, CellArea, CellAreaBox, CellAreaContext,
  CellLayout, CellRenderer, CellRendererAccel, CellRendererCombo,
  CellRendererPixbuf, CellRendererProgress, CellRendererSpin,
  CellRendererSpinner, CellRendererText, CellRendererToggle, CellView,
  ComboBox, ComboBoxText, EntryCompletion, IconView, ListStore,
  ListViewText, StyleContext, TreeDragDest, TreeDragSource,
  TreeIter and other classes in treeiter.h,
  TreeModel, TreeModelFilter, TreeModelSort, TreePath, TreeRowReference,
  TreeSelection, TreeSortable, TreeStore, TreeView, TreeViewColumn,
  namespace CellRenderer_Generation, namespace TreeView_Private,
  ColorButton, ColorChooser, ColorChooserDialog,
  FileChooser, FileChooserDialog, FileChooserNative, FileChooserWidget,
  FontButton, FontChooser, FontChooserDialog, FontChooserWidget,
  MessageDialog, TreeModelColumn, TreeModelColumnRecord, InfoBar,
  Assistant, AssistantPage, LockButton, Statusbar, VolumeButton.
</para>
<para xml:lang="en">New classes and enums:
  AlertDialog, ColorDialog, ColorDialogButton, ColumnViewSorter, FileDialog,
  FontDialog, FontDialogButton, FileLauncher, UriLauncher, ATContext,
  enums DialogError, FontLevel, Collation.
</para>
<para xml:lang="en">In most cases there are replacements for the deprecated classes.
See the reference documentation.
</para>
</section>

</chapter>

<chapter xml:id="chapter-button-widget">
<title>Tlačítka</title>

<para><application>gtkmm</application> poskytuje čtyři základní typy tlačítek:</para>

<variablelist>

<varlistentry>
<term xml:lang="en">Push buttons</term>
<listitem>
<para xml:lang="en">
<link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Button.html"><classname>Gtk::Button</classname></link>. Standard buttons, usually
marked with a label or picture. Pushing one triggers an action. See the <link linkend="sec-pushbuttons">Button</link> section.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Přepínací tlačítka (ToggleButton)</term>
<listitem>
<para xml:lang="en">
<link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ToggleButton.html"><classname>Gtk::ToggleButton</classname></link>.
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.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term xml:lang="en">Check buttons</term>
<listitem>
<para xml:lang="en">
<link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1CheckButton.html"><classname>Gtk::CheckButton</classname></link>.
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-checkbuttons">CheckButton</link> section.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Skupinové přepínače (RadioButton)</term>
<listitem>
<para xml:lang="en">
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 ToggleButtons or
CheckButtons (a small widget with a label at the side), but usually
look different. There is no separate radio button class. Check buttons
and toggle buttons can act as radio buttons.
See the <link linkend="sec-radio-buttons">Radio Button</link> section.
</para>
</listitem>
</varlistentry>
</variablelist>

<para xml:lang="en">
Note that, due to GTK's theming system, the appearance of these
widgets will vary. In the case of check buttons and radio buttons, they
may vary considerably.
</para>

<section xml:id="sec-pushbuttons">
<title>Tlačítko (Button)</title>

<para>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>.</para>

<para>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:</para>
<programlisting xml:lang="en"><code>Gtk::Button* pButton = new Gtk::Button("_Something", true);</code></programlisting>

<para><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>.</para>

<para xml:lang="en">
The <classname>Gtk::Button</classname> widget has the <literal>clicked</literal> signal
which is emitted when the button is pressed and released.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Button.html">Reference</link></para>

<section xml:id="pushbutton-example">
<title>Příklad</title>

<para>Tento příklad vytvoří tlačítko s obrázkem a popiskem.</para>

<figure xml:id="figure-buttons">
  <title>Příklad tlačítka</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buttons.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buttons/button">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>buttons.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_BUTTONS_H
#define GTKMM_EXAMPLE_BUTTONS_H

#include <gtkmm/window.h>
#include <gtkmm/button.h>

class Buttons : public Gtk::Window
{
public:
  Buttons();
  virtual ~Buttons();

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

  //Child widgets:
  Gtk::Button m_button;
};

#endif //GTKMM_EXAMPLE_BUTTONS_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>buttons.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "buttons.h"
#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include <gtkmm/label.h>
#include <iostream>

Buttons::Buttons()
{
  // This corresponds to Gtk::Bin::add_pixlabel("info.xpm", "cool button") in gtkmm3.
  //Create Image and Label widgets:
  auto pmap = Gtk::make_managed<Gtk::Image>("info.xpm");
  auto label = Gtk::make_managed<Gtk::Label>("cool button");
  label->set_expand(true);

  //Put them in a Box:
  auto hbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
  hbox->append(*pmap);
  hbox->append(*label);

  //And put that Box in the button:
  m_button.set_child(*hbox);

  set_title("Pixmap'd buttons!");

  m_button.signal_clicked().connect( sigc::mem_fun(*this,
              &Buttons::on_button_clicked) );

  m_button.set_margin(10);
  set_child(m_button);
}

Buttons::~Buttons()
{
}

void Buttons::on_button_clicked()
{
  std::cout << "The Button was clicked." << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "buttons.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<Buttons>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-toggle-buttons">
<title>Přepínací tlačítko (ToggleButton)</title>

<para><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.</para>

<para>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.</para>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ToggleButton.html">Reference</link></para>

</section>

<section xml:id="sec-checkbuttons">
<title>Zaškrtávací políčko (CheckButton)</title>

<para xml:lang="en">
<classname>Gtk::CheckButton</classname> inherits directly from
<classname>Gtk::Widget</classname>. It is similar to <classname>Gtk::ToggleButton</classname>.
The only real difference between the two is <classname>Gtk::CheckButton</classname>'s
appearance. You can check and set a check button using the same
member methods as for <classname>Gtk::ToggleButton</classname>.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1CheckButton.html">Reference</link></para>

<section xml:id="checkbutton-example">
<title>Příklad</title>

<figure xml:id="figure-checkbutton">
  <title>Zaškrtávací políčko (CheckButton)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/checkbutton.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buttons/checkbutton">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_BUTTONS_H
#define GTKMM_EXAMPLE_BUTTONS_H

#include <gtkmm/window.h>
#include <gtkmm/checkbutton.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_toggled();

  //Child widgets:
  Gtk::CheckButton m_button;
};

#endif //GTKMM_EXAMPLE_BUTTONS_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_button("something")
{
  set_title("checkbutton example");

  m_button.signal_toggled().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_toggled) );

  m_button.set_margin(10);
  set_child(m_button);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_toggled()
{
  std::cout << "The Button was toggled: state="
      << (m_button.get_active() ? "true" : "false")
      << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>

</section>

<section xml:id="sec-radio-buttons">
<title xml:lang="en">Radio Button</title>

<para xml:lang="en">
There is no separate class for radio buttons. Check buttons and toggle buttons
act as radio buttons when they form a group. Only one button in a group can be
selected at any one time.
</para>

<section xml:id="radiobutton-groups">
<title>Skupiny</title>
<para xml:lang="en">
You create the buttons, and set up their group afterwards. In the following example,
we put 3 radio buttons in a group:
</para>

<programlisting xml:lang="en"><code>auto rb1 = Gtk::make_managed&lt;Gtk::CheckButton&gt;("button1");
auto rb2 = Gtk::make_managed&lt;Gtk::CheckButton&gt;("button2");
auto rb3 = Gtk::make_managed&lt;Gtk::CheckButton&gt;("button3");
rb2-&gt;set_group(*rb1);
rb3-&gt;set_group(*rb1);
</code></programlisting>

<para xml:lang="en">
We told <application>gtkmm</application> to put all three <classname>CheckButton</classname>s in the
same group by using <methodname>set_group()</methodname> to tell the other
<classname>CheckButton</classname>s to share group with the first
<classname>CheckButton</classname>.
</para>

</section>

<section xml:id="radiobutton-methods">
<title>Metody</title>
<para xml:lang="en">
<classname>CheckButton</classname>s and <classname>ToggleButton</classname>s 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>.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1RadioButton.html">Reference</link></para>

</section>

<section xml:id="radiobutton-example">
<title>Příklad</title>
<para xml:lang="en">
The following example demonstrates the use of grouped
<classname>CheckButton</classname>s:
</para>

<figure xml:id="figure-radiobutton">
  <title>Skupinový přepínač (RadioButton)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/radiobuttons.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buttons/radiobutton">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>radiobuttons.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_RADIOBUTTONS_H
#define GTKMM_EXAMPLE_RADIOBUTTONS_H

#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/separator.h>

class RadioButtons : public Gtk::Window
{
public:
  RadioButtons();
  virtual ~RadioButtons();

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

  //Child widgets:
  Gtk::Box m_Box_Top, m_Box1, m_Box2;
  Gtk::CheckButton m_RadioButton1, m_RadioButton2, m_RadioButton3;
  Gtk::Separator m_Separator;
  Gtk::Button m_Button_Close;
};

#endif //GTKMM_EXAMPLE_RADIOBUTTONS_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "radiobuttons.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<RadioButtons>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>radiobuttons.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "radiobuttons.h"

RadioButtons::RadioButtons() :
  m_Box_Top(Gtk::Orientation::VERTICAL),
  m_Box1(Gtk::Orientation::VERTICAL, 10),
  m_Box2(Gtk::Orientation::VERTICAL, 10),
  m_RadioButton1("button1"),
  m_RadioButton2("button2"),
  m_RadioButton3("button3"),
  m_Button_Close("close")
{
  // Set title and border of the window
  set_title("radio buttons");

  // Gtk::CheckButton and Gtk::ToggleButton have set_group() methods.
  // They act as radio buttons, if they are included in a group.

  // Put radio buttons 2 and 3 in the same group as 1:
  m_RadioButton2.set_group(m_RadioButton1);
  m_RadioButton3.set_group(m_RadioButton1);

  // Add outer box to the window (because the window
  // can only contain a single widget)
  set_child(m_Box_Top);

  //Put the inner boxes and the separator in the outer box:
  m_Box_Top.append(m_Box1);
  m_Box_Top.append(m_Separator);
  m_Box_Top.append(m_Box2);
  m_Separator.set_expand();

  // Set the inner boxes' margins
  m_Box1.set_margin(10);
  m_Box2.set_margin(10);

  // Put the radio buttons in Box1:
  m_Box1.append(m_RadioButton1);
  m_Box1.append(m_RadioButton2);
  m_Box1.append(m_RadioButton3);
  m_RadioButton1.set_expand();
  m_RadioButton2.set_expand();
  m_RadioButton3.set_expand();

  // Set the second button active
  m_RadioButton2.set_active(true);

  // Put Close button in Box2:
  m_Box2.append(m_Button_Close);
  m_Button_Close.set_expand();

  // Make the button the default widget
  set_default_widget(m_Button_Close);

  // Connect the toggled signal of the button to
  // RadioButtons::on_button_toggled()
  m_Button_Close.signal_clicked().connect(sigc::mem_fun(*this,
              &RadioButtons::on_button_clicked) );
}

RadioButtons::~RadioButtons()
{
}

void RadioButtons::on_button_clicked()
{
  set_visible(false); //to close the application.
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-range-widgets">
<title>Widgety odvozené z Range</title>

<para xml:lang="en">
<classname>Gtk::Scale</classname> inherits from <classname>Gtk::Range</classname>.
<classname>Gtk::Scrollbar</classname> does not inherit from <classname>Gtk::Range</classname>,
but it shares much functionality with <classname>Gtk::Scale</classname>.
They both 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 behavior.
</para>

<para xml:lang="en">
As will be explained in the <link linkend="chapter-adjustment">Adjustments</link>
section, all range widgets are associated with an
<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 range
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.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Range.html">Reference</link></para>

<section xml:id="sec-scrollbar-widgets">
<title>Posuvníkové widgety</title>

<para xml:lang="en">
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.
</para>

<para>Orientace widgetu <classname>Gtk::Scrollbar</classname> může být vodorovná nebo svislá.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Scrollbar.html">Reference</link></para>

</section>

<section xml:id="sec-scale-widgets">
<title>Stupnicové widgety</title>

<para>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.</para>

<para xml:lang="en">
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 behavior.
</para>

<section xml:id="scale-useful-methods">
<title>Užitečné metody</title>

<para>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>.</para>

<para>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>.</para>

<para>Také může, pomocí metody <methodname>set_value_pos()</methodname>, nastavit místo pro vykreslování hodnoty, relativně k vodicí dráze.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Scale.html">Reference</link></para>

</section>
</section>

<section xml:id="sec-range-example">
<title>Příklad</title>

<para>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.</para>

<figure xml:id="figure-range-widgets">
  <title>Widgety odvozené z Range</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/range_widgets.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/range_widgets">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_RANGEWIDGETS_H
#define GTKMM_EXAMPLE_RANGEWIDGETS_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_checkbutton_toggled();
  void on_dropdown_position();
  void on_adjustment1_value_changed();
  void on_adjustment2_value_changed();
  void on_button_quit();

  //Child widgets:
  Gtk::Box m_VBox_Top, m_VBox2, m_VBox_HScale;
  Gtk::Box m_HBox_Scales, m_HBox_DropDown, m_HBox_Digits, m_HBox_PageSize;

  Glib::RefPtr<Gtk::Adjustment> m_adjustment, m_adjustment_digits, m_adjustment_pagesize;

  Gtk::Scale m_VScale;
  Gtk::Scale m_HScale, m_Scale_Digits, m_Scale_PageSize;

  Gtk::Separator m_Separator;

  Gtk::CheckButton m_CheckButton;

  Gtk::Scrollbar m_Scrollbar;

  Gtk::DropDown m_DropDown_Position;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLE_RANGEWIDGETS_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <array>
#include <iostream>

namespace
{
struct PositionTypeStruct
{
  Gtk::PositionType position;
  Glib::ustring text;
};

const std::array<PositionTypeStruct, 4> positionTypes =
{
  PositionTypeStruct{Gtk::PositionType::TOP,    "Top"},
  PositionTypeStruct{Gtk::PositionType::BOTTOM, "Bottom"},
  PositionTypeStruct{Gtk::PositionType::LEFT,   "Left"},
  PositionTypeStruct{Gtk::PositionType::RIGHT,  "Right"}
};

} // anonymous namespace


ExampleWindow::ExampleWindow()
:
  m_VBox_Top(Gtk::Orientation::VERTICAL, 0),
  m_VBox2(Gtk::Orientation::VERTICAL, 20),
  m_VBox_HScale(Gtk::Orientation::VERTICAL, 10),
  m_HBox_Scales(Gtk::Orientation::HORIZONTAL, 10),
  m_HBox_DropDown(Gtk::Orientation::HORIZONTAL, 10),
  m_HBox_Digits(Gtk::Orientation::HORIZONTAL, 10),
  m_HBox_PageSize(Gtk::Orientation::HORIZONTAL, 10),

  // Value, lower, upper, step_increment, page_increment, page_size:
  // Note that the page_size value only makes a difference for
  // scrollbar widgets, and the highest value you'll get is actually
  // (upper - page_size).
  m_adjustment( Gtk::Adjustment::create(0.0, 0.0, 101.0, 0.1, 1.0, 1.0) ),
  m_adjustment_digits( Gtk::Adjustment::create(1.0, 0.0, 5.0, 1.0, 2.0) ),
  m_adjustment_pagesize( Gtk::Adjustment::create(1.0, 1.0, 101.0) ),

  m_VScale(m_adjustment, Gtk::Orientation::VERTICAL),
  m_HScale(m_adjustment, Gtk::Orientation::HORIZONTAL),
  m_Scale_Digits(m_adjustment_digits),
  m_Scale_PageSize(m_adjustment_pagesize),

  // A checkbutton to control whether the value is displayed or not:
  m_CheckButton("Display value on scale widgets", 0),

  // Reuse the same adjustment again.
  // Notice how this causes the scales to always be updated
  // continuously when the scrollbar is moved.
  m_Scrollbar(m_adjustment),

  m_Button_Quit("Quit")
{
  set_title("range controls");
  set_default_size(300, 350);

  //VScale:
  m_VScale.set_digits(1);
  m_VScale.set_value_pos(Gtk::PositionType::TOP);
  m_VScale.set_draw_value();
  m_VScale.set_inverted(); // highest value at top

  //HScale:
  m_HScale.set_digits(1);
  m_HScale.set_value_pos(Gtk::PositionType::TOP);
  m_HScale.set_draw_value();

  set_child(m_VBox_Top);
  m_VBox_Top.append(m_VBox2);
  m_VBox2.set_expand(true);
  m_VBox2.set_margin(10);
  m_VBox2.append(m_HBox_Scales);
  m_HBox_Scales.set_expand(true);

  //Put VScale and HScale (above scrollbar) side-by-side.
  m_HBox_Scales.append(m_VScale);
  m_VScale.set_expand(true);
  m_HBox_Scales.append(m_VBox_HScale);
  m_VBox_HScale.set_expand(true);

  m_VBox_HScale.append(m_HScale);
  m_HScale.set_expand(true);

  //Scrollbar:
  m_VBox_HScale.append(m_Scrollbar);
  m_Scrollbar.set_expand(true);

  //CheckButton:
  m_CheckButton.set_active();
  m_CheckButton.signal_toggled().connect( sigc::mem_fun(*this,
    &ExampleWindow::on_checkbutton_toggled) );
  m_VBox2.append(m_CheckButton);

  //Position DropDown:
  //Create the StringList:
  auto string_list = Gtk::StringList::create({});
  m_DropDown_Position.set_model(string_list);

  // Fill the DropDown's list model:
  for (const auto& positionType : positionTypes)
    string_list->append(positionType.text);

  m_VBox2.append(m_HBox_DropDown);
  m_HBox_DropDown.append(*Gtk::make_managed<Gtk::Label>("Scale Value Position:", 0));
  m_HBox_DropDown.append(m_DropDown_Position);
  m_DropDown_Position.property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dropdown_position));
  m_DropDown_Position.set_selected(0); // Top
  m_DropDown_Position.set_expand(true);

  //Digits:
  m_HBox_Digits.append(*Gtk::make_managed<Gtk::Label>("Scale Digits:", 0));
  m_Scale_Digits.set_digits(0);
  m_Scale_Digits.set_expand(true);
  m_adjustment_digits->signal_value_changed().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_adjustment1_value_changed));
  m_HBox_Digits.append(m_Scale_Digits);

  //Page Size:
  m_HBox_PageSize.append(*Gtk::make_managed<Gtk::Label>("Scrollbar Page Size:", 0));
  m_Scale_PageSize.set_digits(0);
  m_Scale_PageSize.set_expand(true);
  m_adjustment_pagesize->signal_value_changed().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_adjustment2_value_changed));
  m_HBox_PageSize.append(m_Scale_PageSize);

  m_VBox2.append(m_HBox_Digits);
  m_VBox2.append(m_HBox_PageSize);
  m_VBox_Top.append(m_Separator);
  m_VBox_Top.append(m_Button_Quit);

  set_default_widget(m_Button_Quit);
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_button_quit));
  m_Button_Quit.set_margin(10);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_checkbutton_toggled()
{
  m_VScale.set_draw_value(m_CheckButton.get_active());
  m_HScale.set_draw_value(m_CheckButton.get_active());
}

void ExampleWindow::on_dropdown_position()
{
  const auto selected = m_DropDown_Position.get_selected();
  if (selected == GTK_INVALID_LIST_POSITION)
    return;

  const auto postype = positionTypes[selected].position;
  m_VScale.set_value_pos(postype);
  m_HScale.set_value_pos(postype);
}

void ExampleWindow::on_adjustment1_value_changed()
{
  const double val = m_adjustment_digits->get_value();
  m_VScale.set_digits((int)val);
  m_HScale.set_digits((int)val);
}

void ExampleWindow::on_adjustment2_value_changed()
{
  const double val = m_adjustment_pagesize->get_value();
  m_adjustment->set_page_size(val);
  m_adjustment->set_page_increment(val);

  // Note that we don't have to emit the "changed" signal
  // because gtkmm does this for us.
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</chapter>

<chapter xml:id="chapter-misc-widgets">
<title>Různé widgety</title>

<section xml:id="sec-labels">
<title>Popisek (Label)</title>

<para xml:lang="en">
Labels are the  main method of placing non-editable text in windows, for
instance to place a title next to an <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.
</para>

<para>Šíř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.</para>

<para xml:lang="en">
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_wrap()</methodname>.
</para>

<para xml:lang="en">
Gtk::Label supports 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 <link xlink:href="https://docs.gtk.org/Pango/pango_markup.html">Pango Markup syntax</link>. For instance,
<code>
&lt;b&gt;bold text&lt;/b&gt; and &lt;s&gt;strikethrough text&lt;/s&gt;
</code>
.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Label.html">Reference</link></para>

<section xml:id="label-example">
<title>Příklad</title>
<para>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>.</para>

<figure xml:id="figure-label">
  <title>Popisek (Label)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/label.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/label">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Child widgets:
  Gtk::Box m_HBox;
  Gtk::Box m_VBox, m_VBox2;
  Gtk::Frame m_Frame_Normal, m_Frame_Multi, m_Frame_Left, m_Frame_Right,
    m_Frame_LineWrapped, m_Frame_FilledWrapped, m_Frame_Underlined;
  Gtk::Label m_Label_Normal, m_Label_Multi, m_Label_Left, m_Label_Right,
    m_Label_LineWrapped, m_Label_FilledWrapped, m_Label_Underlined;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
:
  m_HBox(Gtk::Orientation::HORIZONTAL, 5),
  m_VBox(Gtk::Orientation::VERTICAL, 5),
  m_VBox2(Gtk::Orientation::VERTICAL, 5),
  m_Frame_Normal("Normal Label"),
  m_Frame_Multi("Multi-line Label"),
  m_Frame_Left("Left Justified Label"),
  m_Frame_Right("Right Justified Label"),
  m_Frame_LineWrapped("Line wrapped label"),
  m_Frame_FilledWrapped("Filled, wrapped label"),
  m_Frame_Underlined("Underlined label"),
  m_Label_Normal("_This is a Normal label", true),
  m_Label_Multi("This is a Multi-line label.\nSecond line\nThird line"),
  m_Label_Left("This is a Left-Justified\nMulti-line label.\nThird line"),
  m_Label_Right("This is a Right-Justified\nMulti-line label.\nThird line"),
  m_Label_Underlined("<u>This label is underlined!</u>\n"
          "<u>T</u>h<u>is one is</u> <u>u</u>n<u>derlin</u>ed "
          "in<u> q</u>u<u>ite a f</u>u<u>nky</u> fashion")
{
  set_title("Label");

  m_HBox.set_margin(5);
  set_child(m_HBox);

  m_HBox.append(m_VBox);

  m_Frame_Normal.set_child(m_Label_Normal);
  m_VBox.append(m_Frame_Normal);

  m_Frame_Multi.set_child(m_Label_Multi);
  m_VBox.append(m_Frame_Multi);

  m_Label_Left.set_justify(Gtk::Justification::LEFT);
  m_Frame_Left.set_child(m_Label_Left);
  m_VBox.append(m_Frame_Left);

  m_Label_Right.set_justify(Gtk::Justification::RIGHT);
  m_Frame_Right.set_child(m_Label_Right);
  m_VBox.append(m_Frame_Right);

  m_HBox.append(m_VBox2);

  m_Label_LineWrapped.set_text(
          "This is an example of a line-wrapped label.  It "
          /* add a big space to the next line to test spacing */
          "should not be taking up the entire             "
          "width allocated to it, but automatically "
          "wraps the words to fit.  "
          "The time has come, for all good men, to come to "
          "the aid of their party.  "
          "The sixth sheik's six sheep's sick.\n"
          "     It supports multiple paragraphs correctly, "
          "and  correctly   adds "
          "many          extra  spaces. ");
  m_Label_LineWrapped.set_wrap();
  m_Frame_LineWrapped.set_child(m_Label_LineWrapped);
  m_VBox2.append(m_Frame_LineWrapped);

  m_Label_FilledWrapped.set_text(
          "This is an example of a line-wrapped, filled label.  "
          "It should be taking "
          "up the entire              width allocated to it.  "
          "Here is a sentence to prove "
          "my point.  Here is another sentence. "
          "Here comes the sun, do de do de do.\n"
          "    This is a new paragraph.\n"
          "    This is another newer, longer, better "
          "paragraph.  It is coming to an end, "
          "unfortunately.");
  m_Label_FilledWrapped.set_justify(Gtk::Justification::FILL);
  m_Label_FilledWrapped.set_wrap();
  m_Frame_FilledWrapped.set_child(m_Label_FilledWrapped);
  m_VBox2.append(m_Frame_FilledWrapped);

  m_Label_Underlined.set_justify(Gtk::Justification::LEFT);
  m_Label_Underlined.set_use_markup(true);
  m_Frame_Underlined.set_child(m_Label_Underlined);
  m_VBox2.append(m_Frame_Underlined);
}

ExampleWindow::~ExampleWindow()
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-text-entry">
<title>Vstupní pole (Entry)</title>

<section xml:id="sec-text-entry-simple">
<title>Jednoduché použití</title>

<para>Vstupní 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>.</para>

<para>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>.</para>

<para>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.</para>

<para xml:lang="en">
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> (since <application>gtkmm</application> 4.8) and <literal>changed</literal>, for this purpose.
<literal>activate</literal> is emitted when the user presses the <keycap>Enter</keycap> 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>leave</literal>
signal in a <classname>Gtk::EventControllerFocus</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.
</para>

<para xml:lang="en">
If you pass <literal>true</literal> to the <methodname>set_activates_default()</methodname>
method, pressing <keycap>Enter</keycap> 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::Window::set_default_widget()</methodname>.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Entry.html">Reference</link></para>

<section xml:id="entry-example">
<title>Příklad s jednoduchým vstupním polem</title>
<para>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.</para>

<figure xml:id="figure-entry-simple">
  <title>Vstupní pole (Entry)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/entry.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/entry/simple">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_checkbox_editable_toggled();
  void on_checkbox_visibility_toggled();
  void on_button_close();

  //Child widgets:
  Gtk::Box m_HBox;
  Gtk::Box m_VBox;
  Gtk::Entry m_Entry;
  Gtk::Button m_Button_Close;
  Gtk::CheckButton m_CheckButton_Editable, m_CheckButton_Visible;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Close("Close"),
  m_CheckButton_Editable("Editable"),
  m_CheckButton_Visible("Visible")
{
  set_size_request(200, 100);
  set_title("Gtk::Entry");

  set_child(m_VBox);

  m_Entry.set_max_length(50);
  m_Entry.set_text("hello");
  m_Entry.set_text(m_Entry.get_text() + " world");
  m_Entry.select_region(0, m_Entry.get_text_length());
  m_Entry.set_expand(true);
  m_VBox.append(m_Entry);

  m_VBox.append(m_HBox);

  m_HBox.append(m_CheckButton_Editable);
  m_CheckButton_Editable.set_expand(true);
  m_CheckButton_Editable.signal_toggled().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_checkbox_editable_toggled) );
  m_CheckButton_Editable.set_active(true);

  m_HBox.append(m_CheckButton_Visible);
  m_CheckButton_Visible.set_expand(true);
  m_CheckButton_Visible.signal_toggled().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_checkbox_visibility_toggled) );
  m_CheckButton_Visible.set_active(true);

  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox.append(m_Button_Close);
  m_Button_Close.set_expand();
  set_default_widget(m_Button_Close);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_checkbox_editable_toggled()
{
  m_Entry.set_editable(m_CheckButton_Editable.get_active());
}

void ExampleWindow::on_checkbox_visibility_toggled()
{
  m_Entry.set_visibility(m_CheckButton_Visible.get_active());
}

void ExampleWindow::on_button_close()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-text-entry-completion">
<title>Doplňování vstupu</title>

<note><para xml:lang="en"><classname>Gtk::EntryCompletion</classname> is deprecated since <application>gtkmm</application> 4.10.
There is no replacement in <application>gtkmm</application>.
</para></note>

<para xml:lang="en">An <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.
</para>

<para xml:lang="en">To enable this functionality, you must create an
<classname>EntryCompletion</classname> object, and provide it to the
<classname>Entry</classname> widget via the
<methodname>set_completion()</methodname> method.</para>

<para>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ů.</para>

<para>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.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1EntryCompletion.html">Reference</link></para>

<section xml:id="entry-completion-example">
<title>Příklad doplňování vstupu</title>
<para>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.</para>

<figure xml:id="figure-entry-completion">
  <title>Doplňování vstupu</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/entry_completion.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/entry/completion">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_close();

  //See the comment in the implementation:
  //bool on_completion_match(const Glib::ustring& key, const Gtk::TreeModel::const_iterator& iter);

  //Tree model columns, for the EntryCompletion's filter model:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:
    ModelColumns()
    { add(m_col_id); add(m_col_name); }

    Gtk::TreeModelColumn<unsigned int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
  };

  ModelColumns m_Columns;

  //Child widgets:
  Gtk::Box m_HBox;
  Gtk::Box m_VBox;
  Gtk::Entry m_Entry;
  Gtk::Label m_Label;
  Gtk::Button m_Button_Close;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Label("Press a or b to see a list of possible completions."),
  m_Button_Close("Close")
{
  //set_size_request(200, 100);
  set_title("Gtk::EntryCompletion");

  set_child(m_VBox);
  m_VBox.append(m_Entry);

  m_VBox.append(m_Label);
  m_Label.set_expand(true);

  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox.append(m_Button_Close);
  set_default_widget(m_Button_Close);

  //Add an EntryCompletion:
  auto completion =
      Gtk::EntryCompletion::create();
  m_Entry.set_completion(completion);

  //Create and fill the completion's filter model
  auto refCompletionModel =
      Gtk::ListStore::create(m_Columns);
  completion->set_model(refCompletionModel);

  // For more complex comparisons, use a filter match callback, like this.
  // See the comment below for more details:
  //completion->set_match_func( sigc::mem_fun(*this,
              //&ExampleWindow::on_completion_match) );

  //Fill the TreeView's model
  auto row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "Alan Zebedee";

  row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "Adrian Boo";

  row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "Bob McRoberts";

  row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 4;
  row[m_Columns.m_col_name] = "Bob McBob";

  //Tell the completion what model column to use to
  //- look for a match (when we use the default matching, instead of
  //  set_match_func().
  //- display text in the entry when a match is found.
  completion->set_text_column(m_Columns.m_col_name);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_close()
{
  set_visible(false);
}

/* You can do more complex matching with a handler like this.
 * For instance, you could check for substrings inside the string instead of the start,
 * or you could look for the key in extra model columns as well as the model column that will be displayed.
 * The code here is not actually more complex - it's a reimplementation of the default behaviour.
 *
bool ExampleWindow::on_completion_match(const Glib::ustring& key, const
        Gtk::TreeModel::const_iterator& iter)
{
  if(iter)
  {
    const auto row = *iter;

    const auto key_length = key.size();
    auto filter_string = row[m_Columns.m_col_name];

    auto filter_string_start = filter_string.substr(0, key_length);
    //The key is lower-case, even if the user input is not.
    filter_string_start = filter_string_start.lowercase();

    if(key == filter_string_start)
      return true; //A match was found.
  }

  return false; //No match.
}
*/
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-text-entry-icons">
<title>Ikony ve vstupním poli</title>

<para xml:lang="en">An <classname>Entry</classname> widget can show an icon at the start or
end of the text area. The icon can be specified by methods such as
<methodname>set_icon_from_paintable()</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.</para>

<section xml:id="entry-icon-example">
<title>Příklad vstupního pole s ikonami</title>
<para>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.</para>

<figure xml:id="figure-entry-icon">
  <title>Vstupní pole s ikonou</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/entry_icon.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/entry/icon">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_icon_pressed(Gtk::Entry::IconPosition icon_pos);
  void on_button_close();

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Entry m_Entry;
  Gtk::Button m_Button_Close;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Close("Close")
{
  set_title("Gtk::Entry");

  set_child(m_VBox);

  m_Entry.set_max_length(50);
  m_Entry.set_text("Hello world");
  m_VBox.append(m_Entry);

  m_Entry.set_icon_from_icon_name("edit-find");
  m_Entry.signal_icon_press().connect( sigc::mem_fun(*this, &ExampleWindow::on_icon_pressed) );


  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox.append(m_Button_Close);
  set_default_widget(m_Button_Close);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_icon_pressed(Gtk::Entry::IconPosition /* icon_pos */)
{
  std::cout << "Icon pressed." << std::endl;
}

void ExampleWindow::on_button_close()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-text-entry-progress">
<title>Vstupní pole s ukazatelem průběhu</title>

<para>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>.</para>

<section xml:id="entry-progress-example">
<title>Příklad ukazatele průběhu ve vstupním poli</title>
<para>Tento příklad ukazuje widget <classname>Gtk::Entry</classname> s ukazatelem průběhu.</para>

<figure xml:id="figure-entry-progress">
  <title>Vstupní pole s ukazatelem průběhu</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/entry_progress.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/entry/progress">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  bool on_timeout();
  void on_button_close();

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Entry m_Entry;
  Gtk::Button m_Button_Close;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Close("Close")
{
  set_title("Gtk::Entry");

  set_child(m_VBox);

  m_Entry.set_max_length(50);
  m_Entry.set_text("Hello world");
  m_VBox.append(m_Entry);

  //Change the progress fraction every 0.1 second:
  Glib::signal_timeout().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_timeout),
    100
  );

  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox.append(m_Button_Close);
  set_default_widget(m_Button_Close);
}

ExampleWindow::~ExampleWindow()
{
}

bool ExampleWindow::on_timeout()
{
  static double fraction = 0;
  m_Entry.set_progress_fraction(fraction);

  fraction += 0.01;
  if(fraction > 1)
    fraction = 0;

  return true;
}

void ExampleWindow::on_button_close()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

</section>

<section xml:id="sec-spinbutton">
<title>Číselník (SpinButton)</title>

<para><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.</para>

<para>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.</para>

<para xml:lang="en">
<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:
<itemizedlist>
<listitem>

<para xml:lang="en">
 <literal>value</literal>: value for the Spin Button
</para>
</listitem>
<listitem>

<para xml:lang="en">
 <literal>lower</literal>: lower range value
</para>
</listitem>
<listitem>

<para xml:lang="en">
 <literal>upper</literal>: upper range value
</para>
</listitem>
<listitem>
<para xml:lang="en">
 <literal>step_increment</literal>: value to increment/decrement when pressing
mouse button 1
</para>
</listitem>
<listitem>

<para xml:lang="en">
 <literal>page_increment</literal>: value to increment/decrement when pressing
mouse button 2
</para>
</listitem>
<listitem>

<para xml:lang="en">
 <literal>page_size</literal>: unused
</para>
</listitem>

</itemizedlist>
</para>

<para>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>.</para>

<para><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>.</para>


<section xml:id="spinbutton-methods">
<title>Metody</title>

<para>Počet desetinných míst můžete měnit pomocí metody <methodname>set_digits()</methodname>.</para>

<para>Hodnotu číselníku můžete nastavit pomocí metody <methodname>set_value()</methodname> a naopak ji získat pomocí <methodname>get_value()</methodname>.</para>

<para>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.</para>

<para>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>.</para>

<para>Aby číselník <classname>SpinButton</classname> cyklicky přecházel mezi horní a dolní hranicí, použijte metodu <methodname>set_wrap()</methodname>.</para>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1SpinButton.html">Reference</link></para>

</section>

<section xml:id="spinbutton-example">
<title>Příklad</title>

<para>Zde je ukázka widgetu <classname>SpinButton</classname> v akci:</para>

<figure xml:id="figure-spinbutton">
  <title>Číselník (SpinButton)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/spinbutton.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/spinbutton">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_checkbutton_snap();
  void on_checkbutton_numeric();
  void on_spinbutton_digits_changed();
  void on_button_close();

  enum enumValueFormats
  {
    VALUE_FORMAT_INT,
    VALUE_FORMAT_FLOAT
  };
  void on_button_getvalue(enumValueFormats display);

  //Child widgets:
  Gtk::Frame m_Frame_NotAccelerated, m_Frame_Accelerated;
  Gtk::Box m_HBox_NotAccelerated, m_HBox_Accelerated,
    m_HBox_Buttons;
  Gtk::Box m_VBox_Main, m_VBox, m_VBox_Day, m_VBox_Month, m_VBox_Year,
    m_VBox_Accelerated, m_VBox_Value, m_VBox_Digits;
  Gtk::Label m_Label_Day, m_Label_Month, m_Label_Year,
    m_Label_Value, m_Label_Digits,
    m_Label_ShowValue;
  Glib::RefPtr<Gtk::Adjustment> m_adjustment_day, m_adjustment_month, m_adjustment_year,
    m_adjustment_value, m_adjustment_digits;
  Gtk::SpinButton m_SpinButton_Day, m_SpinButton_Month, m_SpinButton_Year,
    m_SpinButton_Value, m_SpinButton_Digits;
  Gtk::CheckButton m_CheckButton_Snap, m_CheckButton_Numeric;
  Gtk::Button m_Button_Int, m_Button_Float, m_Button_Close;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>
#include <cstdio>

ExampleWindow::ExampleWindow()
:
  m_Frame_NotAccelerated("Not accelerated"),
  m_Frame_Accelerated("Accelerated"),
  m_VBox_Main(Gtk::Orientation::VERTICAL, 5),
  m_VBox(Gtk::Orientation::VERTICAL),
  m_VBox_Day(Gtk::Orientation::VERTICAL),
  m_VBox_Month(Gtk::Orientation::VERTICAL),
  m_VBox_Year(Gtk::Orientation::VERTICAL),
  m_VBox_Accelerated(Gtk::Orientation::VERTICAL),
  m_VBox_Value(Gtk::Orientation::VERTICAL),
  m_VBox_Digits(Gtk::Orientation::VERTICAL),
  m_Label_Day("Day: ", Gtk::Align::START),
  m_Label_Month("Month: ", Gtk::Align::START),
  m_Label_Year("Year: ", Gtk::Align::START),
  m_Label_Value("Value: ", Gtk::Align::START),
  m_Label_Digits("Digits: ", Gtk::Align::START),
  m_adjustment_day( Gtk::Adjustment::create(1.0, 1.0, 31.0, 1.0, 5.0, 0.0) ),
  m_adjustment_month( Gtk::Adjustment::create(1.0, 1.0, 12.0, 1.0, 5.0, 0.0) ),
  m_adjustment_year( Gtk::Adjustment::create(2012.0, 1.0, 2200.0, 1.0, 100.0, 0.0) ),
  m_adjustment_value( Gtk::Adjustment::create(0.0, -10000.0, 10000.0, 0.5, 100.0, 0.0) ),
  m_adjustment_digits( Gtk::Adjustment::create(2.0, 1.0, 5.0, 1.0, 1.0, 0.0) ),
  m_SpinButton_Day(m_adjustment_day),
  m_SpinButton_Month(m_adjustment_month),
  m_SpinButton_Year(m_adjustment_year),
  m_SpinButton_Value(m_adjustment_value, 1.0, 2),
  m_SpinButton_Digits(m_adjustment_digits),
  m_CheckButton_Snap("Snap to 0.5-ticks"),
  m_CheckButton_Numeric("Numeric only input mode"),
  m_Button_Int("Value as Int"),
  m_Button_Float("Value as Float"),
  m_Button_Close("Close")
{
  set_title("SpinButton");

  m_VBox_Main.set_margin(10);
  set_child(m_VBox_Main);

  m_VBox_Main.append(m_Frame_NotAccelerated);

  m_VBox.set_margin(5);
  m_Frame_NotAccelerated.set_child(m_VBox);

  /* Day, month, year spinners */

  m_VBox.set_spacing(5);
  m_VBox.append(m_HBox_NotAccelerated);

  m_Label_Day.set_expand();
  m_VBox_Day.append(m_Label_Day);

  m_SpinButton_Day.set_wrap();
  m_SpinButton_Day.set_expand();
  m_VBox_Day.append(m_SpinButton_Day);

  m_HBox_NotAccelerated.set_spacing(5);
  m_HBox_NotAccelerated.append(m_VBox_Day);

  m_Label_Month.set_expand();
  m_VBox_Month.append(m_Label_Month);

  m_SpinButton_Month.set_wrap();
  m_SpinButton_Month.set_expand();
  m_VBox_Month.append(m_SpinButton_Month);

  m_HBox_NotAccelerated.append(m_VBox_Month);

  m_Label_Year.set_expand();
  m_VBox_Year.append(m_Label_Year);

  m_SpinButton_Year.set_wrap();
  m_SpinButton_Year.set_expand();
  m_SpinButton_Year.set_size_request(55, -1);
  m_VBox_Year.append(m_SpinButton_Year);

  m_HBox_NotAccelerated.append(m_VBox_Year);

  //Accelerated:
  m_VBox_Main.append(m_Frame_Accelerated);

  m_VBox_Accelerated.set_margin(5);
  m_Frame_Accelerated.set_child(m_VBox_Accelerated);

  m_VBox_Accelerated.set_spacing(5);
  m_VBox_Accelerated.append(m_HBox_Accelerated);

  m_HBox_Accelerated.append(m_VBox_Value);

  m_Label_Value.set_expand();
  m_VBox_Value.append(m_Label_Value);

  m_SpinButton_Value.set_wrap();
  m_SpinButton_Value.set_expand();
  m_SpinButton_Value.set_size_request(100, -1);
  m_VBox_Value.append(m_SpinButton_Value);

  m_HBox_Accelerated.append(m_VBox_Digits);

  m_VBox_Digits.append(m_Label_Digits);
  m_Label_Digits.set_expand();

  m_SpinButton_Digits.set_wrap();
  m_adjustment_digits->signal_value_changed().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_spinbutton_digits_changed) );

  m_VBox_Digits.append(m_SpinButton_Digits);
  m_SpinButton_Digits.set_expand();

  //CheckButtons:
  m_VBox_Accelerated.append(m_CheckButton_Snap);
  m_CheckButton_Snap.set_expand();
  m_CheckButton_Snap.set_active();
  m_CheckButton_Snap.signal_toggled().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_checkbutton_snap) );

  m_VBox_Accelerated.append(m_CheckButton_Numeric);
  m_CheckButton_Numeric.set_expand();
  m_CheckButton_Numeric.set_active();
  m_CheckButton_Numeric.signal_toggled().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_checkbutton_numeric) );

  //Buttons:
  m_VBox_Accelerated.append(m_HBox_Buttons);

  m_Button_Int.signal_clicked().connect( sigc::bind( sigc::mem_fun(*this,
                  &ExampleWindow::on_button_getvalue), VALUE_FORMAT_INT) );
  m_HBox_Buttons.set_spacing(5);
  m_HBox_Buttons.append(m_Button_Int);
  m_Button_Int.set_expand();

  m_Button_Float.signal_clicked().connect( sigc::bind( sigc::mem_fun(*this,
                  &ExampleWindow::on_button_getvalue), VALUE_FORMAT_FLOAT) );
  m_HBox_Buttons.append(m_Button_Float);
  m_Button_Float.set_expand();

  m_VBox_Accelerated.append(m_Label_ShowValue);
  m_Label_ShowValue.set_expand();
  m_Label_ShowValue.set_text("0");

  //Close button:
  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox_Main.append(m_Button_Close);
}

ExampleWindow::~ExampleWindow()
{
}


void ExampleWindow::on_button_close()
{
  set_visible(false);
}

void ExampleWindow::on_checkbutton_snap()
{
  m_SpinButton_Value.set_snap_to_ticks( m_CheckButton_Snap.get_active() );
}

void ExampleWindow::on_checkbutton_numeric()
{
  m_SpinButton_Value.set_numeric( m_CheckButton_Numeric.get_active() );
}

void ExampleWindow::on_spinbutton_digits_changed()
{
  m_SpinButton_Value.set_digits( m_SpinButton_Digits.get_value_as_int() );
}

void ExampleWindow::on_button_getvalue(enumValueFormats display)
{
  gchar buf[32];

  if (display == VALUE_FORMAT_INT)
    sprintf (buf, "%d", m_SpinButton_Value.get_value_as_int());
  else
    sprintf (buf, "%0.*f", m_SpinButton_Value.get_digits(),
            m_SpinButton_Value.get_value());

  m_Label_ShowValue.set_text(buf);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-progressbar">
<title>Ukazatel průběhu (PrograssBar)</title>

<para>Ukazatel průběhu zobrazuje stav probíhající operace. Například může <classname>ProgressBar</classname> zobrazovat, jak velká část úlohy je dokončená.</para>

<para xml:lang="en">
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 fraction.
</para>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ProgressBar.html">Reference</link></para>

<section xml:id="progressbar-activity-mode">
<title>Režim aktivity</title>

<para xml:lang="en">
Besides indicating the amount of progress that has occurred, 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).
</para>

<para>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.</para>

<para xml:lang="en">
The progress bar can also display a configurable text
string next to the bar, using the <methodname>set_text()</methodname> method.
</para>
</section>

<section xml:id="progressbar-example">
<title>Příklad</title>

<figure xml:id="figure-progressbar">
  <title>Ukazatel průběhu (PrograssBar)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/progressbar.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/progressbar">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_checkbutton_text();
  void on_checkbutton_activity();
  void on_checkbutton_inverted();

  bool on_timeout();
  void on_button_close();

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Grid m_Grid;
  Gtk::ProgressBar m_ProgressBar;
  Gtk::Separator m_Separator;
  Gtk::CheckButton m_CheckButton_Text, m_CheckButton_Activity, m_CheckButton_Inverted;
  Gtk::Button m_Button_Close;

  sigc::connection m_connection_timeout;
  bool m_bActivityMode;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL, 5),
  m_CheckButton_Text("Show text"),
  m_CheckButton_Activity("Activity mode"),
  m_CheckButton_Inverted("Right to Left"),
  m_Button_Close("Close"),
  m_bActivityMode(false)
{
  set_resizable();
  set_title("Gtk::ProgressBar");

  m_VBox.set_margin(10);
  set_child(m_VBox);

  m_VBox.append(m_ProgressBar);
  m_ProgressBar.set_margin_end(5);
  m_ProgressBar.set_halign(Gtk::Align::CENTER);
  m_ProgressBar.set_valign(Gtk::Align::CENTER);
  m_ProgressBar.set_size_request(100, -1);
  m_ProgressBar.set_text("some text");
  m_ProgressBar.set_show_text(false);

  //Add a timer callback to update the value of the progress bar:
  m_connection_timeout = Glib::signal_timeout().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_timeout), 50 );

  m_VBox.append(m_Separator);
  m_VBox.append(m_Grid);
  m_Grid.set_expand(true);
  m_Grid.set_row_homogeneous(true);

  //Add a check button to select displaying of the trough text:
  m_Grid.attach(m_CheckButton_Text, 0, 0);
  m_CheckButton_Text.set_margin(5);
  m_CheckButton_Text.signal_toggled().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_checkbutton_text) );

  //Add a check button to toggle activity mode:
  m_Grid.attach(m_CheckButton_Activity, 0, 1);
  m_CheckButton_Activity.set_margin(5);
  m_CheckButton_Activity.signal_toggled().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_checkbutton_activity) );

  //Add a check button to select growth from left to right or from right to left:
  m_Grid.attach(m_CheckButton_Inverted, 0, 2);
  m_CheckButton_Inverted.set_margin(5);
  m_CheckButton_Inverted.signal_toggled().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_checkbutton_inverted) );

  //Add a button to exit the program.
  m_VBox.append(m_Button_Close);
  m_Button_Close.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  set_default_widget(m_Button_Close);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_checkbutton_text()
{
  const bool show_text = m_CheckButton_Text.get_active();
  m_ProgressBar.set_show_text(show_text);
}

void ExampleWindow::on_checkbutton_activity()
{
  m_bActivityMode = m_CheckButton_Activity.get_active();

  if(m_bActivityMode)
    m_ProgressBar.pulse();
  else
    m_ProgressBar.set_fraction(0.0);
}

void ExampleWindow::on_checkbutton_inverted()
{
  const bool inverted = m_CheckButton_Inverted.get_active();
  m_ProgressBar.set_inverted(inverted);
}

void ExampleWindow::on_button_close()
{
  set_visible(false);
}

/* Update the value of the progress bar so that we get
 * some movement */
bool ExampleWindow::on_timeout()
{
  if(m_bActivityMode)
    m_ProgressBar.pulse();
  else
  {
    double new_val = m_ProgressBar.get_fraction() + 0.01;

    if(new_val > 1.0)
      new_val = 0.0;

    //Set the new value:
    m_ProgressBar.set_fraction(new_val);
  }

  //As this is a timeout function, return true so that it
  //continues to get called
  return true;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-infobar">
<title>Informační lišta (InfoBar)</title>

<para><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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1InfoBar.html">Reference</link></para>

<section xml:id="infobar-example">
<title>Příklad</title>

<para xml:lang="en">The <classname>InfoBar</classname> widget is deprecated since <application>gtkmm</application> 4.10.
The example shows an info bar consisting of a <classname>Box</classname> with
a <classname>Label</classname> and a <classname>Button</classname>.</para>

<figure xml:id="figure-infobar">
  <title>Informační lišta (InfoBar)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/infobar.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/infobar">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_infobar_ok();
  void on_button_quit();
  void on_button_clear();
  void on_textbuffer_changed();
  void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section,
    const Glib::Error& error);

  void set_infobar_background();

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TextView m_TextView;

  Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer;

  Gtk::Box m_InfoBar;
  Gtk::Label m_Message_Label;
  Gtk::Button m_Button_OK;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
  Gtk::Button m_Button_Clear;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

// The Gtk::InfoBar widget is deprecated since gtk/gtkmm 4.10.
// A Box with a Label and Button is often a good replacement.
// If you don't care about its background color, it's even easier
// than the InfoBar replacement in this example program.

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL, 6),
  m_InfoBar(Gtk::Orientation::HORIZONTAL, 6),
  m_Button_OK("_OK", true),
  m_ButtonBox(Gtk::Orientation::HORIZONTAL, 6),
  m_Button_Quit("_Quit", true),
  m_Button_Clear("_Clear", true)
{
  set_title("Infobar example");
  set_default_size(400, 200);

  m_VBox.set_margin(6);
  set_child(m_VBox);

  // Add the message label to the InfoBar:
  m_InfoBar.append(m_Message_Label);
  m_Message_Label.set_margin_start(5);
  m_Message_Label.set_hexpand(true);
  m_Message_Label.set_halign(Gtk::Align::START);

  // Add an ok button to the InfoBar:
  m_InfoBar.append(m_Button_OK);
  m_Button_OK.set_margin(5);

  // Add the InfoBar to the vbox:
  m_VBox.append(m_InfoBar);

  // Create the buffer and set it for the TextView:
  m_refTextBuffer = Gtk::TextBuffer::create();
  m_TextView.set_buffer(m_refTextBuffer);

  // Add the TextView, inside a ScrolledWindow:
  m_ScrolledWindow.set_child(m_TextView);

  // Show the scrollbars only when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);

  // Add button box:
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Clear);
  m_ButtonBox.append(m_Button_Quit);
  m_Button_Clear.set_hexpand(true);
  m_Button_Clear.set_halign(Gtk::Align::END);

  // Connect signals:
  m_Button_OK.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_infobar_ok) );
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );
  m_Button_Clear.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_clear) );
  m_refTextBuffer->signal_changed().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_textbuffer_changed) );

  // Keep the InfoBar hidden until a message needs to be shown:
  m_InfoBar.set_visible(false);
  set_infobar_background();

  // Make the clear button insensitive until text is typed in the buffer.  When
  // the button is sensitive and it is pressed, the InfoBar is displayed with a
  // message.
  m_Button_Clear.set_sensitive(false);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_infobar_ok()
{
  // Clear the message and hide the info bar:
  m_Message_Label.set_text("");
  m_InfoBar.set_visible(false);
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_button_clear()
{
  m_refTextBuffer->set_text("");
  m_Message_Label.set_text("Cleared the text.");
  m_InfoBar.set_visible(true);
}

void ExampleWindow::on_textbuffer_changed()
{
  m_Button_Clear.set_sensitive(m_refTextBuffer->size() > 0);
}

void ExampleWindow::set_infobar_background()
{
  // Concerning color in CSS files, see https://www.w3.org/TR/css-color-3.
  const std::string css = "#infobarbox { background-color: beige; }";

  m_InfoBar.set_name("infobarbox");
  auto css_provider = Gtk::CssProvider::create();
  Gtk::StyleProvider::add_provider_for_display(
    m_InfoBar.get_display(), css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  css_provider->load_from_data(css);
  css_provider->signal_parsing_error().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_parsing_error));
}

void ExampleWindow::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section,
  const Glib::Error& error)
{
  std::cerr << "on_parsing_error(): " << error.what() << std::endl;
  if (section)
  {
    const auto file = section->get_file();
    if (file)
    {
      std::cerr << "  URI = " << file->get_uri() << std::endl;
    }

    auto start_location = section->get_start_location();
    auto end_location = section->get_end_location();
    std::cerr << "  start_line = " << start_location.get_lines()+1
              << ", end_line = " << end_location.get_lines()+1 << std::endl;
    std::cerr << "  start_position = " << start_location.get_line_chars()
              << ", end_position = " << end_location.get_line_chars() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-tooltips">
<title>Vysvětlivky</title>

<para xml:lang="en">
Tooltips 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::Tooltip</classname> is used for more advanced tooltip usage,
such as showing an image as well as text.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Widget.html">Widget Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Tooltip.html">Tooltip Reference</link></para>

<section xml:id="tooltip-example">
<title>Příklad</title>

<figure xml:id="figure-tooltip">
  <title>Vysvětlivka (Tooltip)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/tooltip.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/tooltips">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:

  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Methods:
  void prepare_textview();
  void connect_signals();

  //Signal handlers:
  void on_markup_checkbutton_toggled();
  bool on_textview_query_tooltip(int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip);
  bool on_button_query_tooltip(int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip);

  //Child widgets:
  Gtk::Box m_vbox;

  Gtk::CheckButton m_checkbutton;
  Gtk::Label m_label;

  Gtk::ScrolledWindow m_scrolled_window;
  Gtk::TextView m_text_view;
  Glib::RefPtr<Gtk::TextBuffer> m_ref_text_buffer;
  Glib::RefPtr<Gtk::TextTag> m_ref_bold_tag;

  Gtk::Button m_button;
  Gtk::Box m_button_tooltip_widget;
};

#endif // GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <vector>

const Glib::ustring app_title = "gtkmm tooltips example";
const Glib::ustring non_markedup_tip = "A tooltip without markup.";
const Glib::ustring markedup_tip = "<i>Markup</i> in a tooltip.";

ExampleWindow::ExampleWindow()
  :
  m_vbox(Gtk::Orientation::VERTICAL, 3),
  m_checkbutton("Click to alternate markup in tooltip"),
  m_label("A label"),
  m_button("Button with a custom tooltip widget")
{
  //Set up window and the top-level container:
  set_title(app_title);

  m_vbox.set_margin(10);
  set_child(m_vbox);

  //Check button with markup in tooltip:
  m_checkbutton.set_tooltip_text(non_markedup_tip);
  m_vbox.append(m_checkbutton);

  //Label:
  m_label.set_tooltip_text("Another tooltip");
  m_vbox.append(m_label);

  //Textview:
  prepare_textview();

  //Button:
  //When only connecting to the query-tooltip signal, and not using any
  //of set_tooltip_text() or set_tooltip_markup(), we need to explicitly
  //tell GTK that the widget has a tooltip which we'll show.
  m_button.set_has_tooltip();
  m_vbox.append(m_button);

  //Button's custom tooltip widget:
  auto label = Gtk::make_managed<Gtk::Label>("A label in a custom tooltip widget");
  m_button_tooltip_widget.append(*label);

  connect_signals();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::prepare_textview()
{
  Gtk::TextIter iter;
  std::vector<Glib::RefPtr<Gtk::TextTag>> tags;

  //Set up a scrolled window:
  m_scrolled_window.set_child(m_text_view);
  m_scrolled_window.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_scrolled_window.set_expand();
  m_vbox.append(m_scrolled_window);

  //Create a text buffer with some text:
  m_ref_text_buffer = Gtk::TextBuffer::create();

  iter = m_ref_text_buffer->end();
  m_ref_text_buffer->insert(iter, "Hover over the text ");

  //Insert some text with a tag.
  //In the tooltip signal handler below, we will show a tooltip
  //when mouse pointer is above this tagged text.
  m_ref_bold_tag = m_ref_text_buffer->create_tag("bold");
  m_ref_bold_tag->set_property("weight", Pango::Weight::BOLD);

  tags.push_back(m_ref_bold_tag);

  iter = m_ref_text_buffer->end();
  m_ref_text_buffer->insert_with_tags(iter, "in bold", tags);

  iter = m_ref_text_buffer->end();
  m_ref_text_buffer->insert(iter, " to see its tooltip");

  m_text_view.set_buffer(m_ref_text_buffer);

  m_text_view.set_size_request(320, 50);

  //When only connecting to the query-tooltip signal, and not using any
  //of set_tooltip_text() or set_tooltip_markup(), we need to explicitly
  //tell GTK that the widget has a tooltip which we'll show.
  m_text_view.set_has_tooltip();
}

void ExampleWindow::connect_signals()
{
  m_checkbutton.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_markup_checkbutton_toggled));

  m_text_view.signal_query_tooltip().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_textview_query_tooltip), true);

  m_button.signal_query_tooltip().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_query_tooltip), true);
}

void ExampleWindow::on_markup_checkbutton_toggled()
{
  if (m_checkbutton.get_active())
  {
    m_checkbutton.set_tooltip_markup(markedup_tip);
  }
  else
  {
    m_checkbutton.set_tooltip_markup(non_markedup_tip);
  }
}

bool ExampleWindow::on_textview_query_tooltip(int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip)
{
  Gtk::TextIter iter;

  if (keyboard_tooltip)
  {
    int offset = m_ref_text_buffer->property_cursor_position().get_value();
    iter = m_ref_text_buffer->get_iter_at_offset(offset);
  }
  else
  {
    int mouse_x, mouse_y, trailing;
    m_text_view.window_to_buffer_coords(Gtk::TextWindowType::TEXT,
                                        x, y, mouse_x, mouse_y);
    m_text_view.get_iter_at_position(iter, trailing, mouse_x, mouse_y);
  }

  if (!iter.has_tag(m_ref_bold_tag))
    return false;

  //Show a tooltip if the cursor or mouse pointer is over the text
  //with the specific tag:
  tooltip->set_markup("<b>Information</b> attached to a text tag");
  tooltip->set_icon("dialog-information");
  return true;
}

bool ExampleWindow::on_button_query_tooltip(int, int, bool, const Glib::RefPtr<Gtk::Tooltip>& tooltip)
{
  tooltip->set_custom(m_button_tooltip_widget);
  return true;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-container-widgets">
<title>Kontejnerové widgety</title>

<para xml:lang="en">
Container widgets, like other widgets, derive from <classname>Gtk::Widget</classname>.
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.
</para>

<section xml:id="sec-single-item-containers">
<title>Jednopoložkové kontejnery</title>

<para xml:lang="en">
Most single-item container widgets have <methodname>set_child()</methodname>
and <methodname>unset_child()</methodname> methods for the child widget.
<classname>Gtk::Button</classname> and <classname>Gtk::Window</classname> are
technically single-item containers, but we have discussed them already elsewhere.
</para>

<para>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.</para>

<section xml:id="sec-frame">
<title>Rám (Frame)</title>

<para xml:lang="en">
Frames can enclose one or a group of widgets within a box, optionally with a
title. For instance, you might place a group of
<classname>ToggleButton</classname>s or <classname>CheckButton</classname>s in a
<classname>Frame</classname>.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Frame.html">Reference</link></para>

<section xml:id="frame-example">
<title>Příklad</title>

<figure xml:id="figure-frame">
  <title>Rám (Frame)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/frame.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/frame">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Child widgets:
  Gtk::Frame m_Frame;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
{
 /* Set some window properties */
  set_title("Frame Example");
  set_size_request(300, 300);

  /* Sets the margin around the frame. */
  m_Frame.set_margin(10);

  set_child(m_Frame);

  /* Set the frames label */
  m_Frame.set_label("Gtk::Frame Widget");

  /* Align the label at the right of the frame */
  m_Frame.set_label_align(Gtk::Align::END);
}

ExampleWindow::~ExampleWindow()
{
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-paned">
<title>Dvojitý panel (Paned)</title>

<para>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).</para>

<para xml:lang="en">
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>set_start_child()</methodname> and <methodname>set_end_child()</methodname>
instead of a <methodname>set_child()</methodname> method.
</para>

<para>Rozdělovací čáru můžete umístit pomocí metody <methodname>set_position()</methodname>, a nejspíše to budete potřebovat udělat.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Paned.html">Reference</link></para>

<section xml:id="paned-example">
<title>Příklad</title>

<figure xml:id="figure-paned">
  <title>Dvojitý panel (Paned)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/paned.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/paned">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include "messageslist.h"
#include "messagetext.h"
#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Child widgets:
  Gtk::Paned m_VPaned;
  MessagesList m_MessagesList;
  MessageText m_MessageText;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>messageslist.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MESSAGESLIST_H
#define GTKMM_EXAMPLE_MESSAGESLIST_H

#include <gtkmm.h>

class MessagesList: public Gtk::ScrolledWindow
{
public:
  MessagesList();
  ~MessagesList() override;

protected:
  // Signal handlers:
  void on_setup_message(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_message(const Glib::RefPtr<Gtk::ListItem>& list_item);

  Glib::RefPtr<Gtk::StringList> m_refStringList; // The List Model.
  Gtk::ListView m_ListView; // The List View.
};
#endif //GTKMM_EXAMPLE_MESSAGESLIST_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>messagetext.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MESSAGETEXT_H
#define GTKMM_EXAMPLE_MESSAGETEXT_H

#include <gtkmm.h>

class MessageText : public Gtk::ScrolledWindow
{
public:
  MessageText();
  virtual ~MessageText();

  void insert_text();

protected:
  Gtk::TextView m_TextView;
};

#endif //GTKMM_EXAMPLE_MESSAGETEXT_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VPaned(Gtk::Orientation::VERTICAL)
{
  set_title ("Paned Windows");
  set_default_size(450, 400);
  m_VPaned.set_margin(10);

  /* Add a vpaned widget to our toplevel window */
  set_child(m_VPaned);

  /* Now add the contents of the two halves of the window */
  m_VPaned.set_start_child(m_MessagesList);
  m_VPaned.set_end_child(m_MessageText);
}

ExampleWindow::~ExampleWindow()
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>messageslist.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "messageslist.h"

MessagesList::MessagesList()
{
  /* Create a new scrolled window, with scrollbars only if needed */
  set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);

  set_child(m_ListView);

  /* create list store */
  m_refStringList = Gtk::StringList::create({});
  auto selection_model = Gtk::SingleSelection::create(m_refStringList);
  m_ListView.set_model(selection_model);

  /* Add some messages to the window */
  for (int i = 1; i <= 10; ++i)
    m_refStringList->append(Glib::ustring::format("message #", i));

  // Create a ListItemFactory to use for populating list items.
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::mem_fun(*this, &MessagesList::on_setup_message));
  factory->signal_bind().connect(sigc::mem_fun(*this, &MessagesList::on_bind_message));
  m_ListView.set_factory(factory);
}

MessagesList::~MessagesList()
{
}

void MessagesList::on_setup_message(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto label = Gtk::make_managed<Gtk::Label>();
  label->set_halign(Gtk::Align::START);
  list_item->set_child(*label);
}

void MessagesList::on_bind_message(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto pos = list_item->get_position();
  if (pos == GTK_INVALID_LIST_POSITION)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(m_refStringList->get_string(pos));
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>messagetext.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "messagetext.h"

MessageText::MessageText()
{
  set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);

  set_child(m_TextView);
  insert_text();
}

MessageText::~MessageText()
{
}

void MessageText::insert_text()
{
  auto refTextBuffer = m_TextView.get_buffer();

  auto iter = refTextBuffer->get_iter_at_offset(0);
  refTextBuffer->insert(iter,
    "From: pathfinder@nasa.gov\n"
    "To: mom@nasa.gov\n"
    "Subject: Made it!\n"
    "\n"
    "We just got in this morning. The weather has been\n"
    "great - clear but cold, and there are lots of fun sights.\n"
    "Sojourner says hi. See you soon.\n"
    " -Path\n");
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-scrolledwindow">
<title>Okno s posuvníky (ScrolledWindow)</title>

<para xml:lang="en">
<classname>ScrolledWindow</classname> widgets create a scrollable
area. You can insert any type of widget into a
<classname>ScrolledWindow</classname>, 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.
</para>

<para xml:lang="en">
Scrolled 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
for instance <literal>Gtk::PolicyType::AUTOMATIC</literal> or
<literal>Gtk::PolicyType::ALWAYS</literal>.
<literal>Gtk::PolicyType::AUTOMATIC</literal> will cause the scrolled window
to display the scrollbar only if the contained widget is larger than the
visible area. <literal>Gtk::PolicyType::ALWAYS</literal> will cause the
scrollbar to be displayed always.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ScrolledWindow.html">Reference</link></para>

<section xml:id="scrolledwindow-example">
<title>Příklad</title>

<para>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í.</para>

<figure xml:id="figure-scrolledwindow">
  <title>Okno s posuvníky (ScrolledWindow)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/scrolledwindow.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/scrolledwindow">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_button_close();

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::Grid m_Grid;
  Gtk::Button m_ButtonClose;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL, 10),
  m_ButtonClose("_Close", true)
{
  set_title("Gtk::ScrolledWindow example");
  set_size_request(300, 300);

  set_child(m_VBox);
  m_VBox.set_margin(10);

  /* The policy is one of Gtk::PolicyType::AUTOMATIC, or Gtk::PolicyType::ALWAYS.
   * Gtk::PolicyType::AUTOMATIC will automatically decide whether you need
   * scrollbars, whereas Gtk::PolicyType::ALWAYS will always leave the scrollbars
   * there. The first one is the horizontal scrollbar, the second, the vertical. */
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::ALWAYS);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);

  /* set the spacing to 10 on x and 10 on y */
  m_Grid.set_row_spacing(10);
  m_Grid.set_column_spacing(10);

  /* pack the grid into the scrolled window */
  m_ScrolledWindow.set_child(m_Grid);

  /* this simply creates a grid of toggle buttons
   * to demonstrate the scrolled window. */
  for (int i = 0; i < 10; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      auto s = Glib::ustring::compose("button (%1,%2)", i, j);
      auto pButton = Gtk::make_managed<Gtk::ToggleButton>(s);
      m_Grid.attach(*pButton, i, j);
    }
  }

  /* Add a "close" button to the bottom of the dialog */
  m_VBox.append(m_ButtonClose);
  m_ButtonClose.set_halign(Gtk::Align::END);
  m_ButtonClose.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_close));

  /* Hitting the "Enter" key will cause this button to activate. */
  m_ButtonClose.grab_focus();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_close()
{
  set_visible(false);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-aspectframe">
<title>AspectFrame</title>

<para>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.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1AspectFrame.html">Reference</link></para>

<section xml:id="aspectframe-example">
<title>Příklad</title>

<para>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.</para>

<figure xml:id="figure-aspectframe">
  <title>AspectFrame</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/aspectframe.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/aspectframe">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Child widgets:
  Gtk::AspectFrame m_AspectFrame;
  Gtk::Frame m_Frame;
  Gtk::DrawingArea m_DrawingArea;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_AspectFrame(
    Gtk::Align::CENTER, /* center x */
    Gtk::Align::CENTER, /* center y */
    2.0, /* xsize/ysize = 2 */
    false /* ignore child's aspect */),
  m_Frame("2x1" /* label */)
{
  set_title("Aspect Frame");

  // Set a child widget to the aspect frame */
  // Ask for a 200x200 window, but the AspectFrame will give us a 200x100
  // window since we are forcing a 2x1 aspect ratio */
  m_DrawingArea.set_content_width(200);
  m_DrawingArea.set_content_height(200);
  m_Frame.set_child(m_DrawingArea);
  m_AspectFrame.set_child(m_Frame);
  m_AspectFrame.set_margin(10);

  // Add the aspect frame to our toplevel window:
  set_child(m_AspectFrame);
}

ExampleWindow::~ExampleWindow()
{
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>

</section>

<section xml:id="sec-other-single-item-containers">
<title xml:lang="en">Other Single-item Containers</title>

<para xml:lang="en">
There are other single-item containers. See the reference documentation for a
complete list. Here are links to some example programs that show containers,
which are not mentioned elsewhere in this tutorial.
</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/expander">Source Code, Expander</link></para>
<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/popover">Source Code, Popover</link></para>

</section>

</section>

<section xml:id="sec-multi-item-containers">
<title xml:lang="en">Multiple-item Containers </title>

<para xml:lang="en">
Multiple-item container widgets have other methods than <methodname>set_child()</methodname>
and <methodname>unset_child()</methodname>. Different containers can have different
methods for adding and removing child widgets. For instance, <classname>Gtk::Box</classname>
has <methodname>append()</methodname> and <methodname>remove()</methodname> as
well as other methods. The <methodname>remove()</methodname> method for multiple-item
containers takes an argument, specifying which widget to remove.
</para>

<section xml:id="container-packing">
<title>Balení</title>

<para>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).</para>

<para>Ř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:</para>

<itemizedlist>

<listitem>
<para>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.</para>
</listitem>

<listitem>
<para>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.</para>
</listitem>

<listitem>
<para>Změ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ů.</para>
</listitem>

</itemizedlist>

<para xml:lang="en">
<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 margins 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. </para>

<para xml:lang="en">
<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 flavors of containers: single-child containers and multiple-child
containers. Most container widgets in <application>gtkmm</application> are single-child containers,
including <classname>Gtk::Window</classname>.
</para>

<para>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>.</para>


<itemizedlist>

<listitem>
<para xml:lang="en">
<classname>Gtk::Grid</classname> arranges its child widgets in rows and
columns. Use <methodname>attach()</methodname> and
<methodname>attach_next_to()</methodname> to insert child widgets.
</para>
</listitem>

<listitem>
<para xml:lang="en">
<classname>Gtk::Box</classname> arranges its child widgets vertically or horizontally.
Use <methodname>append()</methodname> to insert child widgets.
</para>
</listitem>

</itemizedlist>

<para>Existuje ještě několik dalších kontejnerů, které také probereme.</para>

<para>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.</para>

</section>

<section xml:id="sec-helloworld2">
<title>Vylepšené „Hello World“</title>

<para>Pojďme se podívat, jak s tím, co jsme si ukázali, trochu vylepšit <literal>helloworld</literal>.</para>

<figure xml:id="figure-helloworld2">
  <title>„Hello World“ 2</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/helloworld2.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/helloworld2">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>helloworld.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H

#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/window.h>

class HelloWorld : public Gtk::Window
{
public:
  HelloWorld();
  ~HelloWorld() override;

protected:

  // Signal handlers:
  // Our new improved on_button_clicked().
  void on_button_clicked(const Glib::ustring& data);

  // Child widgets:
  Gtk::Box m_box1;
  Gtk::Button m_button1, m_button2;
};

#endif // GTKMM_EXAMPLE_HELLOWORLD_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>helloworld.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "helloworld.h"
#include <iostream>

HelloWorld::HelloWorld()
: m_button1("Button 1"),
  m_button2("Button 2")
{
  // This just sets the title of our new window.
  set_title("Hello Buttons!");

  // Sets the margin around the box.
  m_box1.set_margin(10);

  // put the box into the main window.
  set_child(m_box1);

  // Now when the button is clicked, we call the on_button_clicked() function
  // with a pointer to "button 1" as its argument.
  m_button1.signal_clicked().connect(sigc::bind(
              sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "button 1"));

  // We use Gtk::Box::append() to pack this button into the box,
  // which has been packed into the window.
  // A widget's default behaviour is not to expand if extra space is available.
  // A container widget by default expands if any of the contained widgets
  // wants to expand.
  m_box1.append(m_button1);
  m_button1.set_expand();

  // call the same signal handler with a different argument,
  // passing a pointer to "button 2" instead.
  m_button2.signal_clicked().connect(sigc::bind(
              sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "button 2"));

  m_box1.append(m_button2);
  m_button2.set_expand();

  // Gtk::Widget::set_visible(true) is seldom needed. All widgets are visible by default.
}

HelloWorld::~HelloWorld()
{
}

// Our new improved signal handler.  The data passed to this method is
// printed to stdout.
void HelloWorld::on_button_clicked(const Glib::ustring& data)
{
  std::cout << "Hello World - " << data << " was pressed" << std::endl;
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "helloworld.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<HelloWorld>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

<para xml:lang="en">
After building and running this program, try resizing the window to see the
behavior. Also, try playing with <methodname>set_expand()</methodname>,
<methodname>set_hexpand()</methodname>, <methodname>set_vexpand()</methodname>,
<methodname>set_halign()</methodname> and <methodname>set_valign()</methodname>
while reading the <link linkend="sec-boxes">Boxes</link> section.
</para>

</section>

<section xml:id="sec-boxes">
<title>Boxy</title>

<para xml:lang="en">
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. In a vertical box, widgets are packed from
top to bottom. You may use any combination of boxes inside or beside other
boxes to create the desired effect.
</para>

<section xml:id="boxes-adding-widgets">
<title>Přidání widgetů</title>
<section xml:id="per-child-packing-options">
<title>Volby balení pro potomky</title>
<para xml:lang="en">
The <methodname>append()</methodname> method places widgets inside these
containers. It 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. If it's inconvenient
to add widgets in this order, use <methodname>insert_child_after()</methodname>
or <methodname>insert_child_at_start()</methodname>. We will use
<methodname>append()</methodname> in our examples.
</para>

<para xml:lang="en">
There are several options governing how widgets are to be packed, and this can
be confusing at first. You can modify the packing by using <methodname>set_expand()</methodname>,
<methodname>set_hexpand()</methodname>, <methodname>set_vexpand()</methodname>,
<methodname>set_halign()</methodname>, <methodname>set_valign()</methodname>
and/or <methodname>set_margin()</methodname> on the child widgets. If you have
difficulties, then it is sometimes a good idea to play with the
<application>Cambalache</application> GUI designer to see what is possible.
You can then use the <classname>Gtk::Builder</classname> API to load your GUI at runtime.
</para>

<para>V základu existuje pět rozdílných stylů, které můžete vidět na tomto obrázku:</para>

<figure xml:id="figure-box-packing1">
  <title>Balení boxů 1</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/box_packing1.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en">
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>set_hexpand()</methodname>, <methodname>set_halign()</methodname>,
<methodname>set_margin_start()</methodname> and <methodname>set_margin_end()</methodname>
methods.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Box.html">Reference</link></para>

</section>

<section xml:id="per-container-packing-options">
<title>Volby balení pro kontejner</title>
<para xml:lang="en">
Here's the constructor for the <classname>Box</classname> widget,
and methods that set per-container packing options:</para>
<programlisting xml:lang="en"><code>Gtk::Box(Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, int spacing = 0);
void set_orientation(Gtk::Orientation orientation);
void set_spacing(int spacing);
void set_homogeneous(bool homogeneous = true);</code></programlisting>
<para xml:lang="en">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.
</para>

<para xml:lang="en">
What's the difference between spacing (set when the box is created)
and margins (set separately for each child widget)? Spacing is added between
objects, and margins are added on one or more sides of a widget. The following
figure should make it clearer. The shown margins are the left and right margins
of each button in the row.
</para>

<figure xml:id="figure-box-packing2">
  <title>Balení boxů 2</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/box_packing2.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

</section>
</section>

<section xml:id="boxes-command-line-options">
<title>Gtk::Application a přepínače příkazového řádku</title>

<para>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>.</para>

<itemizedlist>
<listitem><para xml:lang="en">
Handle 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::run()</methodname>.
</para></listitem>

<listitem><para xml:lang="en">
Give all command-line options to <methodname>Gtk::Application::run()</methodname>
and add the flag <literal>Gio::Application::Flags::HANDLES_COMMAND_LINE</literal>
to <methodname>Gtk::Application::create()</methodname>.
Connect a signal handler to the <literal>command_line</literal> signal, and
handle the command-line options in the signal handler.</para>

<para>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>.)</para></listitem>
</itemizedlist>
</section>

<section xml:id="box-packing-example">
<title>Příklad</title>

<para>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í.</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/box">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow(int which);
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit_clicked();

  //Child widgets:
  Gtk::Button m_button;
  Gtk::Box m_box1;
  Gtk::Box m_boxQuit;
  Gtk::Button m_buttonQuit;

  Gtk::Label m_Label1, m_Label2;

  Gtk::Separator m_separator1, m_separator2;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>packbox.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_PACKBOX_H
#define GTKMM_EXAMPLE_PACKBOX_H

#include <gtkmm.h>

class PackBox : public Gtk::Box
{
public:
  PackBox(bool homogeneous = false, int spacing = 0, bool expand = false,
    Gtk::Align align = Gtk::Align::FILL, int margin = 0);

protected:
  Gtk::Button m_buttons[4];
};

#endif //GTKMM_EXAMPLE_PACKBOX_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"
#include "packbox.h"

ExampleWindow::ExampleWindow(int which)
: m_box1(Gtk::Orientation::VERTICAL),
  m_buttonQuit("Quit")
{
  set_title("Gtk::Box example");

  m_separator1.set_margin_top(5);
  m_separator1.set_margin_bottom(5);
  m_separator2.set_margin_top(5);
  m_separator2.set_margin_bottom(5);

  switch(which)
  {
    case 1:
    {
      m_Label1.set_text("Gtk::Box(Gtk::Orientation::HORIZONTAL, 0); set_homogeneous(false);");

      // Align the label to the left side.
      m_Label1.set_halign(Gtk::Align::START);
      m_Label1.set_valign(Gtk::Align::START);

      // Pack the label into the vertical box (vbox box1).  Remember that
      // widgets added to a vbox will be packed one on top of the other in
      // order.
      m_box1.append(m_Label1);

      // Create a PackBox - homogeneous = false, spacing = 0,
      // expand = false, Gtk::Align::FILL, margin = 0
      // These are the default values.
      auto pPackBox = Gtk::make_managed<PackBox>();
      m_box1.append(*pPackBox);

      // Create a PackBox - homogeneous = false, spacing = 0,
      // expand = true, Gtk::Align::CENTER, margin = 0
      pPackBox = Gtk::make_managed<PackBox>(false, 0, true, Gtk::Align::CENTER);
      m_box1.append(*pPackBox);

      // Create a PackBox - homogeneous = false, spacing = 0,
      // expand = true, Gtk::Align::FILL, margin = 0
      pPackBox = Gtk::make_managed<PackBox>(false, 0, true);
      m_box1.append(*pPackBox);

      // pack the separator into the vbox.  Remember each of these
      // widgets are being packed into a vbox, so they'll be stacked
      // vertically.
      m_box1.append(m_separator1);

      // create another new label, and show it.
      m_Label2.set_text("Gtk::Box(Gtk::Orientation::HORIZONTAL, 0); set_homogeneous(true);");
      m_Label2.set_halign(Gtk::Align::START);
      m_Label2.set_valign(Gtk::Align::START);
      m_box1.append(m_Label2);

      // Args are: homogeneous, spacing, expand, align, margin
      pPackBox = Gtk::make_managed<PackBox>(true, 0, true, Gtk::Align::CENTER);
      m_box1.append(*pPackBox);

      // Args are: homogeneous, spacing, expand, align, margin
      pPackBox = Gtk::make_managed<PackBox>(true, 0, true);
      m_box1.append(*pPackBox);

      m_box1.append(m_separator2);

      break;
    }

    case 2:
    {
      m_Label1.set_text("Gtk::Box(Gtk::Orientation::HORIZONTAL, 10); set_homogeneous(false);");
      m_Label1.set_halign(Gtk::Align::START);
      m_Label1.set_valign(Gtk::Align::START);
      m_box1.append(m_Label1);

      auto pPackBox = Gtk::make_managed<PackBox>(false, 10, true, Gtk::Align::CENTER);
      m_box1.append(*pPackBox);

      pPackBox = Gtk::make_managed<PackBox>(false, 10, true);
      m_box1.append(*pPackBox);

      m_box1.append(m_separator1);

      m_Label2.set_text("Gtk::Box(Gtk::Orientation::HORIZONTAL, 0); set_homogeneous(false);");
      m_Label2.set_halign(Gtk::Align::START);
      m_Label2.set_valign(Gtk::Align::START);
      m_box1.append(m_Label2);

      pPackBox = Gtk::make_managed<PackBox>(false, 0, false, Gtk::Align::FILL, 10);
      m_box1.append(*pPackBox);

      pPackBox = Gtk::make_managed<PackBox>(false, 0, true, Gtk::Align::FILL, 10);
      m_box1.append(*pPackBox);

      m_box1.append(m_separator2);

      break;
    }

    case 3:
    {
      // This demonstrates the ability to use Gtk::Align::END to
      // right justify widgets.  First, we create a new box as before.
      auto pPackBox = Gtk::make_managed<PackBox>();

      // create the label that will be put at the end.
      m_Label1.set_text("end");

      // pack it using Gtk::Align::END, so it is put on the right side
      // of the PackBox.
      m_Label1.set_halign(Gtk::Align::END);
      m_Label1.set_hexpand(true);
      pPackBox->append(m_Label1);

      m_box1.append(*pPackBox);

      // This explicitly sets the separator to 700 pixels wide by 5 pixels
      // high.  This is so the hbox we created will also be 700 pixels wide,
      // and the "end" label will be separated from the other labels in the
      // hbox.  Otherwise, all the widgets in the hbox would be packed as
      // close together as possible.
      m_separator1.set_size_request(700, 5);

      // pack the separator into the vbox.
      m_box1.append(m_separator1);

      break;
    }

    default:
    {
      std::cerr << "Unexpected command-line option." << std::endl;
      break;
    }
  }

  // Connect the signal to hide the window:
  m_buttonQuit.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit_clicked) );

  // pack the button into the quitbox.
  m_boxQuit.append(m_buttonQuit);
  m_buttonQuit.set_hexpand(true);
  m_buttonQuit.set_halign(Gtk::Align::CENTER);
  m_box1.append(m_boxQuit);

  // pack the vbox (box1) which now contains all our widgets, into the
  // main window.
  set_child(m_box1);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit_clicked()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>
#include <iostream>
#include <cstdlib>

#define GTK_APPLICATION_RECEIVES_COMMAND_LINE_ARGUMENTS 0

#if GTK_APPLICATION_RECEIVES_COMMAND_LINE_ARGUMENTS
namespace
{
int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line,
                    Glib::RefPtr<Gtk::Application>& app)
{
  int argc = 0;
  char** argv = command_line->get_arguments(argc);

  for (int i = 0; i < argc; ++i)
    std::cout << "argv[" << i << "] = " << argv[i] << std::endl;

  app->activate(); // Without activate() the window won't be shown.
  return EXIT_SUCCESS;
}
} // anonymous namespace
#endif


int main(int argc, char *argv[])
{
  if (argc != 2)
  {
    std::cerr << "Usage: example <num>, where <num> is 1, 2, or 3." << std::endl;
    return EXIT_FAILURE;
  }

  int argc1 = argc;

#if GTK_APPLICATION_RECEIVES_COMMAND_LINE_ARGUMENTS
  // The Gio::Application::Flags::HANDLES_COMMAND_LINE flag and the
  // on_command_line() signal handler are not necessary. This program is simpler
  // without them, and with argc = 1 in the call to Gtk::Application::make_window_and_run().
  // They are included to show a program with Gio::Application::Flags::HANDLES_COMMAND_LINE.
  // Gio::Application::Flags::NON_UNIQUE makes it possible to run several instances of
  // this application simultaneously.
  auto app = Gtk::Application::create(
    "org.gtkmm.example", Gio::Application::Flags::HANDLES_COMMAND_LINE | Gio::Application::Flags::NON_UNIQUE);

  // Note after = false.
  // Only one signal handler is invoked. This signal handler must run before
  // the default signal handler, or else it won't run at all.
  app->signal_command_line().connect(
    [&app](const auto& command_line)
    { return on_command_line(command_line, app); }, false);
#else
  // Gio::Application::Flags::NON_UNIQUE makes it possible to run several instances of
  // this application simultaneously.
  argc1 = 1; // Don't give the command line arguments to Gtk::Application.
  auto app = Gtk::Application::create("org.gtkmm.example", Gio::Application::Flags::NON_UNIQUE);
#endif

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc1, argv, std::atoi(argv[1]));
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>packbox.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "packbox.h"
#include <map>

namespace
{
  const std::map<Gtk::Align, Glib::ustring> align_string = {
    {Gtk::Align::FILL, "Gtk::Align::FILL"},
    {Gtk::Align::START, "Gtk::Align::START"},
    {Gtk::Align::END, "Gtk::Align::END"},
    {Gtk::Align::CENTER, "Gtk::Align::CENTER"},
    {Gtk::Align::BASELINE, "Gtk::Align::BASELINE"},
  };
}

PackBox::PackBox(bool homogeneous, int spacing, bool expand, Gtk::Align align, int margin)
: Gtk::Box(Gtk::Orientation::HORIZONTAL, spacing)
{
  set_homogeneous(homogeneous);

  m_buttons[0].set_label("box.append(button);");
  m_buttons[1].set_label("expand=" + Glib::ustring(expand ? "true" : "false"));
  m_buttons[2].set_label(align_string.at(align));
  m_buttons[3].set_label("margin=" + Glib::ustring::format(margin));

  for (auto& button : m_buttons)
  {
    append(button);
    button.set_hexpand(expand);
    button.set_halign(align);
    button.set_margin_start(margin);
    button.set_margin_end(margin);
  }
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>

</section>

<section xml:id="sec-grid">
<title>Mřížka (Grid)</title>

<para>Kontejner <classname>Grid</classname> widgety dynamicky uspořádává do řádků a sloupců. Rozměry mřížky není zapotřebí zadávat v konstruktoru.</para>

<para>Synovské 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>.</para>
<para xml:lang="en">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 behavior when the Grid is resized.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Grid.html">Reference</link></para>

<section xml:id="grid-example">
<title>Příklad</title>
<para>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.</para>

<figure xml:id="figure-grid">
  <title>Mřížka (Grid)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/grid.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/grid">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

private:
  // Signal handlers:
  void on_button_quit();
  void on_button_numbered(const Glib::ustring& data);

  // Child widgets:
  Gtk::Grid m_grid;
  Gtk::Button m_button_1, m_button_2, m_button_quit;
};

#endif /* GTKMM_EXAMPLEWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_button_1("button 1"),
  m_button_2("button 2"),
  m_button_quit("Quit")
{
  set_title("Gtk::Grid");

  m_grid.set_margin(12);
  set_child(m_grid);

  m_grid.attach(m_button_1, 0, 0);
  m_grid.attach(m_button_2, 1, 0);
  m_grid.attach_next_to(m_button_quit, m_button_1, Gtk::PositionType::BOTTOM, 2, 1);

  m_button_1.signal_clicked().connect(
    sigc::bind( sigc::mem_fun(*this, &ExampleWindow::on_button_numbered), "button 1") );
  m_button_2.signal_clicked().connect(
    sigc::bind( sigc::mem_fun(*this, &ExampleWindow::on_button_numbered), "button 2") );

  m_button_quit.signal_clicked().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_button_quit) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void
ExampleWindow::on_button_numbered(const Glib::ustring& data)
{
  std::cout << data << " was pressed" << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-notebook">
<title>Sešit (Notebook)</title>

<para><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.</para>

<para>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.</para>

<para>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.</para>

<para>K programové změně vybrané stránky použijte metodu <methodname>set_current_page()</methodname>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Notebook.html">Reference</link></para>

<section xml:id="notebook-example">
<title>Příklad</title>

<figure xml:id="figure-notebook">
  <title>Sešit (Notebook)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/notebook.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/notebook/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();
  void on_notebook_switch_page(Gtk::Widget* page, guint page_num);

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Notebook m_Notebook;
  Gtk::Label m_Label1, m_Label2;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Label1("Contents of tab 1"),
  m_Label2("Contents of tab 2"),
  m_Button_Quit("Quit")
{
  set_title("Gtk::Notebook example");
  set_default_size(400, 200);

  m_VBox.set_margin(10);
  set_child(m_VBox);

  //Add the Notebook, with the button underneath:
  m_Notebook.set_margin(10);
  m_Notebook.set_expand();
  m_VBox.append(m_Notebook);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::CENTER);
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );

  //Add the Notebook pages:
  m_Notebook.append_page(m_Label1, "First");
  m_Notebook.append_page(m_Label2, "Second");

  m_Notebook.signal_switch_page().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_notebook_switch_page) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_notebook_switch_page(Gtk::Widget* /* page */, guint page_num)
{
  std::cout << "Switched to tab with index " << page_num << std::endl;

  //You can also use m_Notebook.get_current_page() to get this index.
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-assistant">
<title>Průvodce (Assistant)</title>

<note><para xml:lang="en"><classname>Gtk::Assistant</classname> is deprecated since <application>gtkmm</application> 4.10.
There is no replacement in <application>gtkmm</application>. libadwaita (a C library) has replacement parts
(like AdwCarousel). In some cases, a <classname>Gtk::Notebook</classname> might
be an acceptable replacement.
</para></note>

<para>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>.</para>

<para>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.</para>

<para>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>.</para>

<para xml:lang="en">
To set the title of a page, use the <methodname>set_page_title()</methodname> method.
</para>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Assistant.html">Reference</link></para>

<section xml:id="assistant-example">
<title>Příklad</title>

<figure xml:id="figure-assistant">
  <title>Průvodce (Assistant)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/assistant.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/assistant/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleassistant.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEASSISTANT_H
#define GTKMM_EXAMPLEASSISTANT_H

#include <gtkmm.h>

class ExampleAssistant : public Gtk::Assistant
{
public:
  ExampleAssistant();
  virtual ~ExampleAssistant();

  void get_result(bool& check_state, Glib::ustring& entry_text);

private:
  // Signal handlers:
  void on_assistant_apply();
  void on_assistant_cancel();
  void on_assistant_close();
  void on_assistant_prepare(Gtk::Widget* widget);
  void on_entry_changed();

  // Member functions:
  void print_status();

  // Child widgets:
  Gtk::Box m_box;
  Gtk::Label m_label1, m_label2;
  Gtk::CheckButton m_check;
  Gtk::Entry m_entry;
};

#endif /* GTKMM_EXAMPLEASSISTANT_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include "exampleassistant.h"
#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

private:
  // Signal handlers:
  void on_button_clicked();
  void on_assistant_apply();

  // Child widgets:
  Gtk::Grid m_grid;
  Gtk::Button m_button;
  Gtk::Label m_label1, m_label2;
  Gtk::CheckButton m_check;
  Gtk::Entry m_entry;
  ExampleAssistant m_assistant;
};

#endif /* GTKMM_EXAMPLEWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleassistant.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "exampleassistant.h"

ExampleAssistant::ExampleAssistant()
: m_box(Gtk::Orientation::HORIZONTAL, 12),
  m_label1("Type text to allow the assistant to continue:"),
  m_label2("Confirmation page"),
  m_check("Optional extra information")
{
  set_title("Gtk::Assistant example");
  set_default_size(400, 200);

  m_box.append(m_label1);
  m_box.append(m_entry);
  m_label1.set_wrap();
  m_label1.set_valign(Gtk::Align::CENTER);
  m_entry.set_valign(Gtk::Align::CENTER);

  append_page(m_box);
  append_page(m_check);
  append_page(m_label2);

  set_page_title(*get_nth_page(0), "Page 1");
  set_page_title(*get_nth_page(1), "Page 2");
  set_page_title(*get_nth_page(2), "Confirmation");

  set_page_complete(m_check, true);
  set_page_complete(m_label2, true);

  set_page_type(m_box, Gtk::AssistantPage::Type::INTRO);
  set_page_type(m_label2, Gtk::AssistantPage::Type::CONFIRM);

  signal_apply().connect(sigc::mem_fun(*this,
    &ExampleAssistant::on_assistant_apply));
  signal_cancel().connect(sigc::mem_fun(*this,
    &ExampleAssistant::on_assistant_cancel));
  signal_close().connect(sigc::mem_fun(*this,
    &ExampleAssistant::on_assistant_close));
  signal_prepare().connect(sigc::mem_fun(*this,
    &ExampleAssistant::on_assistant_prepare));

  m_entry.signal_changed().connect(sigc::mem_fun(*this,
    &ExampleAssistant::on_entry_changed));
}

ExampleAssistant::~ExampleAssistant()
{
}

void ExampleAssistant::get_result(bool& check_state, Glib::ustring& entry_text)
{
  check_state = m_check.get_active();
  entry_text = m_entry.get_text();
}

void ExampleAssistant::on_assistant_apply()
{
  std::cout << "Apply was clicked";
  print_status();
}

void ExampleAssistant::on_assistant_cancel()
{
  std::cout << "Cancel was clicked";
  print_status();
  set_visible(false);
}

void ExampleAssistant::on_assistant_close()
{
  std::cout << "Assistant was closed";
  print_status();
  set_visible(false);
}

void ExampleAssistant::on_assistant_prepare(Gtk::Widget* /* widget */)
{
  set_title(Glib::ustring::compose("Gtk::Assistant example (Page %1 of %2)",
    get_current_page() + 1, get_n_pages()));
}

void ExampleAssistant::on_entry_changed()
{
  // The page is only complete if the entry contains text.
  if(m_entry.get_text_length())
    set_page_complete(m_box, true);
  else
    set_page_complete(m_box, false);
}

void ExampleAssistant::print_status()
{
  std::cout << ", entry contents: \"" << m_entry.get_text()
    << "\", checkbutton status: " << m_check.get_active() << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include "exampleassistant.h"

ExampleWindow::ExampleWindow()
: m_button("Show the assistant"),
  m_label1("State of assistant checkbutton:", Gtk::Align::START, Gtk::Align::CENTER),
  m_label2("Contents of assistant entry:", Gtk::Align::START, Gtk::Align::CENTER)
{
  set_title("Gtk::Assistant example");

  m_grid.set_row_homogeneous(true);
  m_grid.set_column_spacing(5);
  m_grid.set_margin(12);

  m_grid.attach(m_button, 0, 0, 2, 1);
  m_button.set_hexpand(true);
  m_button.set_valign(Gtk::Align::CENTER);

  m_grid.attach(m_label1, 0, 1, 1, 1);

  m_grid.attach(m_label2, 0, 2, 1, 1);

  m_grid.attach(m_check, 1, 1, 1, 1);
  m_check.set_halign(Gtk::Align::START);

  m_grid.attach(m_entry, 1, 2, 1, 1);
  m_entry.set_hexpand(true);

  set_child(m_grid);

  m_button.signal_clicked().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_button_clicked));
  m_assistant.signal_apply().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_assistant_apply));

  m_check.set_sensitive(false);
  m_entry.set_sensitive(false);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_assistant_apply()
{
  bool check_state;
  Glib::ustring entry_text;

  m_assistant.get_result(check_state, entry_text);
  m_check.set_active(check_state);
  m_entry.set_text(entry_text);
}

void ExampleWindow::on_button_clicked()
{
  m_assistant.set_visible(true);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-other-multi-item-containers">
<title xml:lang="en">Other Multi-item Containers</title>

<para xml:lang="en">
There are other multi-item containers. See the reference documentation for a
complete list. Here are links to some example programs that show containers,
which are not mentioned elsewhere in this tutorial.
</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/actionbar">Source Code, ActionBar</link></para>
<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listbox_flowbox/flowbox">Source Code, FlowBox</link></para>

</section>
</section>
</chapter>

<chapter xml:id="chapter-listmodel">
<title xml:lang="en">ListView, GridView, ColumnView</title>

<para xml:lang="en">
Lists are intended to be used whenever developers want to display many objects
in roughly the same way. They are perfectly fine to be used for very short lists
of only 2 or 3 items, but generally scale fine to thousands of items.
</para>

<para xml:lang="en">
Lists are meant to be used with changing data, both with the items themselves
changing as well as the list adding and removing items. Of course, they work just
as well with static data.
</para>

<para xml:lang="en">
The <link xlink:href="https://docs.gtk.org/gtk4/section-list-widget.html">List Widget Overview</link>
chapter in the GTK documentation contains more information about list widgets.
</para>

<para xml:lang="en">
Some examples are shown in this chapter. There are more examples in the
<link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/">listmodelviews directory</link>
in <application>gtkmm-documentation</application>'s examples.</para>

<section xml:id="sec-listmodel-datamodel">
<title xml:lang="en">The Data Model</title>

<para xml:lang="en">
The data model is a class that implements the <classname>Gio::ListModel</classname>
interface. Examples of such classes are <classname>Gio::ListStore</classname>
(not to be confused with the deprecated <classname>Gtk::ListStore</classname>),
<classname>Gtk:StringList</classname>, <classname>Gtk:DirectoryList</classname>
and <classname>Pango::FontMap</classname>.
</para>

<para xml:lang="en">
The elements in a model are called <emphasis>items</emphasis>.
All items are instances of a subclass of <classname>Glib::Object</classname>.
For instance, you might have a <classname>ColumnView</classname> with one integer
and one text column, like so:
</para>
<programlisting xml:lang="en"><code><![CDATA[class ModelColumns : public Glib::Object
{
public:
  int m_col_id;
  Glib::ustring m_col_name;

  static Glib::RefPtr<ModelColumns> create(
    int col_id, const Glib::ustring& col_name)
  {
    return Glib::make_refptr_for_instance<ModelColumns>(
      new ModelColumns(col_id, col_name));
  }

protected:
  ModelColumns(int col_id, const Glib::ustring& col_name)
  : m_col_id(col_id), m_col_name(col_name)
  {}
};

Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
]]></code></programlisting>

<para xml:lang="en">
Every item in a model has a position which is the unsigned integer that describes
where in the model the item is located. The first item in a model is at position 0.
The position of an item can of course change as other items are added to or removed
from the model.
</para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1ListStore.html">Gio::ListStore Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1StringList.html">StringList Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1DirectoryList.html">DirectoryList Reference</link></para>
</section>

<section xml:id="sec-listmodel-selectionmodel">
<title xml:lang="en">The Selection Model</title>

<para xml:lang="en">
The selection model is a class that implements the <classname>Gtk::SelectionModel</classname>
interface. You can choose between <classname>NoSelection</classname>,
<classname>SingleSelection</classname> and <classname>MultiSelection</classname>.
</para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1NoSelection.html">NoSelection Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1SingleSelection.html">SingleSelection Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1MultiSelection.html">MultiSelection Reference</link></para>
</section>

<section xml:id="sec-listmodel-factory">
<title xml:lang="en">The Factory</title>

<para xml:lang="en">
Data from the data model is added to the view by a factory, which is a subclass of
<classname>ListItemFactory</classname>. There is only one such subclass in <application>gtkmm</application>,
<classname>SignalListItemFactory</classname>. Data from the model is added to the
view with signal handlers connected to a <classname>SignalListItemFactory</classname>.
</para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1SignalListItemFactory.html">SignalListItemFactory Reference</link></para>
</section>

<section xml:id="sec-listmodel-view">
<title>Zobrazení (View)</title>

<para xml:lang="en">
The View is the widget that displays the model 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.
</para>

<para xml:lang="en">
An important requirement for views (especially views of long lists) is that they need
to know which items are not visible so they can be recycled. Views achieve that by
implementing the <classname>Scrollable</classname> interface and expecting
to be placed directly into a <classname>ScrolledWindow</classname>.
</para>

<para xml:lang="en">
There are different view widgets to choose from.
</para>

<section xml:id="sec-listmodel-listview">
<title xml:lang="en">ListView</title>

<para xml:lang="en">
The <classname>ListView</classname> shows a 1-dimensional list with one column.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ListView.html">Reference</link></para>

<section xml:id="listmodel-listview-example">
<title>Příklad</title>

<figure xml:id="figure-listmodel-listview">
  <title xml:lang="en">ListView</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/listmodel_listview.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/list_listview">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_button_quit();
  void on_setup_label(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item);

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::Label m_Heading;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::ListView m_ListView;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;

  Glib::RefPtr<Gtk::StringList> m_StringList;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Heading("<b>Name</b>", Gtk::Align::START),
  m_Button_Quit("Quit")
{
  set_title("Gtk::ListView (Gtk::StringList) example");
  set_default_size(300, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the ListView, inside a ScrolledWindow, with the heading above
  // and the button underneath.
  m_Heading.set_use_markup();
  m_VBox.append(m_Heading);
  m_ScrolledWindow.set_child(m_ListView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_quit));

  // Create the list model:
  m_StringList = Gtk::StringList::create({"Billy Bob", "Joey Jojo", "Rob McRoberts"});

  // Set list model and selection model.
  auto selection_model = Gtk::SingleSelection::create(m_StringList);
  selection_model->set_autoselect(false);
  selection_model->set_can_unselect(true);
  m_ListView.set_model(selection_model);
  m_ListView.add_css_class("data-table"); // high density table

  // Add the factory for the ListView's single column.
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_label));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_name));
  m_ListView.set_factory(factory);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_setup_label(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  list_item->set_child(*Gtk::make_managed<Gtk::Label>("", Gtk::Align::START));
}

void ExampleWindow::on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto pos = list_item->get_position();
  if (pos == GTK_INVALID_LIST_POSITION)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(m_StringList->get_string(pos));
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-listmodel-gridview">
<title xml:lang="en">GridView</title>

<para xml:lang="en">
The <classname>GridView</classname> shows a 2-dimensional grid.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1GridView.html">Reference</link></para>

<section xml:id="listmodel-gridview-example">
<title>Příklad</title>

<figure xml:id="figure-listmodel-gridview">
  <title xml:lang="en">GridView</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/listmodel_gridview.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/gridview">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include <gdkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  class ModelColumns;
  // Signal handlers:
  void on_button_quit();
  void on_item_activated(unsigned int position);
  void on_selection_changed();
  void on_setup_listitem(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_listitem(const Glib::RefPtr<Gtk::ListItem>& list_item);
  int on_model_sort(const Glib::RefPtr<const ModelColumns>& a, const Glib::RefPtr<const ModelColumns>& b);

  void add_entry(const std::string& filename, const Glib::ustring& description);

  // A Gio::ListStore stores filename, description and texture.
  class ModelColumns : public Glib::Object
  {
  public:
    std::string m_filename;
    Glib::ustring  m_description;
    Glib::RefPtr<Gdk::Texture> m_texture;

    static Glib::RefPtr<ModelColumns> create(const std::string& filename,
      const Glib::ustring& description, const Glib::RefPtr<Gdk::Texture>& texture)
    {
      return Glib::make_refptr_for_instance<ModelColumns>(
        new ModelColumns(filename, description, texture));
    }

  protected:
    ModelColumns(const std::string& filename, const Glib::ustring& description,
      const Glib::RefPtr<Gdk::Texture>& texture)
    : m_filename(filename), m_description(description), m_texture(texture)
    { }
  }; // ModelColumns

  Glib::RefPtr<Gio::ListStore<ModelColumns>> m_data_model;
  Glib::RefPtr<Gtk::SingleSelection> m_selection_model;
  Glib::RefPtr<Gtk::SignalListItemFactory> m_factory;

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::GridView m_GridView;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <array>
#include <iostream>

namespace
{
  struct GridEntry
  {
    std::string m_filename;
    Glib::ustring m_description;
  };

  std::array<GridEntry, 8> entries =
  {
    GridEntry{"mozilla-firefox.png", "<b>Mozilla Firefox</b> Logo"},
    GridEntry{"xmms.xpm",            "<b>XMMS</b> Logo"},
    GridEntry{"gnome-dice-1.svg",    "<b>Gnome Dice 1</b> Logo"},
    GridEntry{"gnome-dice-2.svg",    "<b>Gnome Dice 2</b> Logo"},
    GridEntry{"gnome-dice-3.svg",    "<b>Gnome Dice 3</b> Logo"},
    GridEntry{"gnome-dice-4.svg",    "<b>Gnome Dice 4</b> Logo"},
    GridEntry{"gnome-dice-5.svg",    "<b>Gnome Dice 5</b> Logo"},
    GridEntry{"gnome-dice-6.svg",    "<b>Gnome Dice 6</b> Logo"}
  };

} // anonymous namespace

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit")
{
  set_title("Gtk::GridView (Gio::ListStore) example");
  set_default_size(400, 400);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the GridView inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_GridView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(6);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_quit));

  // Create the data model:
  m_data_model = Gio::ListStore<ModelColumns>::create();
  m_selection_model = Gtk::SingleSelection::create(m_data_model);
  m_selection_model->set_autoselect(false);

  m_factory = Gtk::SignalListItemFactory::create();
  m_factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_listitem));
  m_factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_listitem));

  // Fill the Gio::ListStore's data model and sort it.
  for (const auto& entry : entries)
    add_entry(entry.m_filename, entry.m_description);
  m_data_model->sort(sigc::mem_fun(*this, &ExampleWindow::on_model_sort));

  m_GridView.set_model(m_selection_model);
  m_GridView.set_factory(m_factory);

  m_GridView.signal_activate().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_item_activated));
  m_selection_model->property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_selection_changed));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_setup_listitem(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  // Each ListItem contains a vertical Box with an Image and a Label.
  auto vBox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
  auto picture = Gtk::make_managed<Gtk::Picture>();
  picture->set_can_shrink(false);
  picture->set_halign(Gtk::Align::CENTER);
  picture->set_valign(Gtk::Align::END);
  vBox->append(*picture);
  vBox->append(*Gtk::make_managed<Gtk::Label>());
  list_item->set_child(*vBox);
}

void ExampleWindow::on_bind_listitem(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto vBox = dynamic_cast<Gtk::Box*>(list_item->get_child());
  if (!vBox)
    return;
  auto picture = dynamic_cast<Gtk::Picture*>(vBox->get_first_child());
  if (!picture)
    return;
  auto label = dynamic_cast<Gtk::Label*>(picture->get_next_sibling());
  if (!label)
    return;
  picture->set_paintable(col->m_texture);
  label->set_markup(col->m_description);
}

void ExampleWindow::on_item_activated(unsigned int position)
{
  auto col = m_data_model->get_item(position);
  if (!col)
    return;

  const std::string filename = col->m_filename;
  const Glib::ustring description = col->m_description;

  std::cout  << "Item activated: filename=" << filename
    << ", description=" << description << std::endl;
}

void ExampleWindow::on_selection_changed()
{
  auto position = m_selection_model->get_selected();
  auto col = m_data_model->get_item(position);
  if (!col)
    return;

  const std::string filename = col->m_filename;
  const Glib::ustring description = col->m_description;

  std::cout  << "Selection Changed to: filename=" << filename
    << ", description=" << description << std::endl;
}

int ExampleWindow::on_model_sort(const Glib::RefPtr<const ModelColumns>& a,
  const Glib::RefPtr<const ModelColumns>& b)
{
  return (a->m_description < b->m_description) ? -1 : ((a->m_description > b->m_description) ? 1 : 0);
}

void ExampleWindow::add_entry(const std::string& filename,
        const Glib::ustring& description )
{
  try
  {
     auto pixbuf = Gdk::Pixbuf::create_from_file(filename);
     auto texture = Gdk::Texture::create_for_pixbuf(pixbuf);
     m_data_model->append(ModelColumns::create(filename, description, texture));
  }
  catch (const Gdk::PixbufError& ex)
  {
    std::cerr << "Gdk::PixbufError: " << ex.what() << std::endl;
  }
  catch (const Glib::FileError& ex)
  {
    std::cerr << "Glib::FileError: " << ex.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-listmodel-columnview">
<title xml:lang="en">ColumnView</title>

<para xml:lang="en">
The <classname>ColumnView</classname> shows a 1-dimensional list with one or more columns.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ColumnView.html">Reference</link></para>

<section xml:id="listmodel-columnview-example">
<title>Příklad</title>

<figure xml:id="figure-listmodel-columnview">
  <title xml:lang="en">ColumnView</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/listmodel_columnview.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/list_columnview">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_button_quit();
  void on_setup_label(const Glib::RefPtr<Gtk::ListItem>& list_item, Gtk::Align halign);
  void on_setup_progressbar(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_number(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_percentage(const Glib::RefPtr<Gtk::ListItem>& list_item);

  // A Gio::ListStore item.
  class ModelColumns : public Glib::Object
  {
  public:
    unsigned int m_col_id;
    Glib::ustring m_col_name;
    short m_col_number;
    int m_col_percentage;

    static Glib::RefPtr<ModelColumns> create(unsigned int col_id,
      const Glib::ustring& col_name, short col_number, int col_percentage)
    {
      return Glib::make_refptr_for_instance<ModelColumns>(
        new ModelColumns(col_id, col_name, col_number, col_percentage));
    }

  protected:
    ModelColumns(unsigned int col_id, const Glib::ustring& col_name,
      short col_number, int col_percentage)
    : m_col_id(col_id), m_col_name(col_name), m_col_number(col_number),
      m_col_percentage(col_percentage)
    {}
  }; // ModelColumns

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::ColumnView m_ColumnView;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;

  Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit")
{
  set_title("Gtk::ColumnView (Gio::ListStore) example");
  set_default_size(500, 250);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the ColumnView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_ColumnView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_quit));

  // Create the List model:
  m_ListStore = Gio::ListStore<ModelColumns>::create();
  m_ListStore->append(ModelColumns::create(1, "Billy Bob", 10, 15));
  m_ListStore->append(ModelColumns::create(2, "Joey Jojo", 20, 40));
  m_ListStore->append(ModelColumns::create(3, "Rob McRoberts", 30, 70));

  // Set list model and selection model.
  auto selection_model = Gtk::SingleSelection::create(m_ListStore);
  selection_model->set_autoselect(false);
  selection_model->set_can_unselect(true);
  m_ColumnView.set_model(selection_model);
  m_ColumnView.add_css_class("data-table"); // high density table

  // Make the columns reorderable.
  // This is not necessary, but it's nice to show the feature.
  m_ColumnView.set_reorderable(true);

  // Add the ColumnView's columns:

  // Id column
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::END));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_id));
  auto column = Gtk::ColumnViewColumn::create("ID", factory);
  m_ColumnView.append_column(column);

  // Name column
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::START));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_name));
  column = Gtk::ColumnViewColumn::create("Name", factory);
  m_ColumnView.append_column(column);

  // Number column
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::END));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_number));
  column = Gtk::ColumnViewColumn::create("Formatted number", factory);
  m_ColumnView.append_column(column);

  // Percentage column
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_progressbar));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_percentage));
  column = Gtk::ColumnViewColumn::create("Some percentage", factory);
  m_ColumnView.append_column(column);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_setup_label(
  const Glib::RefPtr<Gtk::ListItem>& list_item, Gtk::Align halign)
{
  list_item->set_child(*Gtk::make_managed<Gtk::Label>("", halign));
}

void ExampleWindow::on_setup_progressbar(
  const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto progressbar = Gtk::make_managed<Gtk::ProgressBar>();
  progressbar->set_show_text(true);
  list_item->set_child(*progressbar);
}

void ExampleWindow::on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(Glib::ustring::format(col->m_col_id));
}

void ExampleWindow::on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(col->m_col_name);
}

void ExampleWindow::on_bind_number(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  // 10 digits, using leading zeroes.
  label->set_text(Glib::ustring::sprintf("%010d", col->m_col_number));
}

void ExampleWindow::on_bind_percentage(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto progressbar = dynamic_cast<Gtk::ProgressBar*>(list_item->get_child());
  if (!progressbar)
    return;
  progressbar->set_fraction(col->m_col_percentage * 0.01);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</section>

<section xml:id="sec-listmodel-sorting">
<title>Řazení</title>

<para xml:lang="en">
The list can be sorted by wrapping it in a <classname>SortListModel</classname>.
There are two ways to do this.
</para>
<itemizedlist>
  <listitem><para xml:lang="en">In a <classname>ColumnView</classname>, get the
  <classname>ColumnViewSorter</classname> from the <classname>ColumnView</classname>
  and set it to the <classname>SortListModel</classname>. Set a <classname>Sorter</classname>
  to each <classname>ColumnViewColumn</classname>. Then the user of your app can
  sort the items by clicking on a column heading.</para></listitem>
  <listitem><para xml:lang="en">In any view, set a <classname>Sorter</classname> such as a
  <classname>StringSorter</classname> or a <classname>NumericSorter</classname>
  to the <classname>SortListModel</classname>.</para></listitem>
</itemizedlist>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1SortListModel.html">SortListModel Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1StringSorter.html">StringSorter Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1NumericSorter.html">NumericSorter Reference</link></para>

<section xml:id="listmodel-sorting-example">
<title>Příklad</title>

<figure xml:id="figure-listmodel-sorting">
  <title xml:lang="en">SortListModel</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/listmodel_sort.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/sort">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_button_nosort();
  void on_button_sortheadings();
  void on_button_sortlength();
  void on_button_quit();
  void on_setup_label(const Glib::RefPtr<Gtk::ListItem>& list_item, Gtk::Align halign);
  void on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item);

  // A Gio::ListStore item.
  class ModelColumns : public Glib::Object
  {
  public:
    unsigned int m_col_id;
    Glib::ustring m_col_name;

    static Glib::RefPtr<ModelColumns> create(int col_id, const Glib::ustring& col_name)
    {
      return Glib::make_refptr_for_instance<ModelColumns>(
        new ModelColumns(col_id, col_name));
    }

  protected:
    ModelColumns(int col_id, const Glib::ustring& col_name)
    : m_col_id(col_id), m_col_name(col_name)
    {}
  }; // ModelColumns

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::ColumnView m_ColumnView;
  Gtk::Box m_ButtonBox;
  Gtk::ToggleButton m_Button_NoSort;
  Gtk::ToggleButton m_Button_SortHeadings;
  Gtk::ToggleButton m_Button_SortLength;
  Gtk::Button m_Button_Quit;

  Glib::RefPtr<Gtk::SingleSelection> m_SelectionModel; 
  Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
  Glib::RefPtr<Gtk::SortListModel> m_SortListModel;
  Glib::RefPtr<Gtk::ColumnViewColumn> m_IdColumn;
  Glib::RefPtr<Gtk::ColumnViewColumn> m_NameColumn;
  Glib::RefPtr<Gtk::NumericSorter<Glib::ustring::size_type>> m_LengthSorter;
  Glib::RefPtr<Gtk::NumericSorter<unsigned int>> m_IdSorter;
  Glib::RefPtr<Gtk::StringSorter> m_NameSorter;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_NoSort("Don't Sort"),
  m_Button_SortHeadings("Sort Headings"),
  m_Button_SortLength("Sort Length"),
  m_Button_Quit("Quit")
{
  set_title("Gtk::ColumnView (Gtk::SortListModel) example");
  set_default_size(400, 350);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the ColumnView, inside a ScrolledWindow, with the buttons underneath:
  m_ScrolledWindow.set_child(m_ColumnView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.set_margin(5);
  m_ButtonBox.set_spacing(10);
  m_ButtonBox.append(m_Button_NoSort);
  m_ButtonBox.append(m_Button_SortHeadings);
  m_ButtonBox.append(m_Button_SortLength);
  m_ButtonBox.append(m_Button_Quit);
  m_Button_NoSort.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_nosort));
  m_Button_SortHeadings.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_sortheadings));
  m_Button_SortLength.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_sortlength));
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_quit));

  // Gtk::CheckButton and Gtk::ToggleButton have set_group() methods.
  // They act as radio buttons, if they are included in a group.
  m_Button_SortHeadings.set_group(m_Button_NoSort);
  m_Button_SortLength.set_group(m_Button_NoSort);

  // Create the List model.
  m_ListStore = Gio::ListStore<ModelColumns>::create();
  m_ListStore->append(ModelColumns::create(1, "Billy Bob"));
  m_ListStore->append(ModelColumns::create(11, "Billy Bob Junior"));
  m_ListStore->append(ModelColumns::create(12, "Sue Bob"));
  m_ListStore->append(ModelColumns::create(2, "Joey Jojo"));
  m_ListStore->append(ModelColumns::create(3, "Rob McRoberts"));
  m_ListStore->append(ModelColumns::create(31, "Xavier McRoberts"));

  // Create the sort model.
  auto size_expression = Gtk::ClosureExpression<Glib::ustring::size_type>::create(
    [](const Glib::RefPtr<Glib::ObjectBase>& item)->Glib::ustring::size_type
    {
      const auto col = std::dynamic_pointer_cast<ModelColumns>(item);
      return col ? col->m_col_name.size() : 0;
    });
  m_LengthSorter = Gtk::NumericSorter<Glib::ustring::size_type>::create(size_expression);
  m_LengthSorter->set_sort_order(Gtk::SortType::ASCENDING);
  m_SortListModel = Gtk::SortListModel::create(m_ListStore, m_LengthSorter);

  // Set list model and selection model.
  m_SelectionModel = Gtk::SingleSelection::create(m_ListStore);
  m_SelectionModel->set_autoselect(false);
  m_SelectionModel->set_can_unselect(true);
  m_ColumnView.set_model(m_SelectionModel);
  m_ColumnView.add_css_class("data-table"); // high density table

  // Make the columns reorderable.
  // This is not necessary, but it's nice to show the feature.
  m_ColumnView.set_reorderable(true);

  // Add the ColumnView's columns:

  // Id column
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::END));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_id));
  m_IdColumn = Gtk::ColumnViewColumn::create("ID", factory);
  m_ColumnView.append_column(m_IdColumn);
  auto uint_expression = Gtk::ClosureExpression<unsigned int>::create(
    [](const Glib::RefPtr<Glib::ObjectBase>& item)->unsigned int
    {
      const auto col = std::dynamic_pointer_cast<ModelColumns>(item);
      return col ? col->m_col_id : 0;
    });
  m_IdSorter = Gtk::NumericSorter<unsigned int>::create(uint_expression);

  // Name column
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::START));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_name));
  m_NameColumn = Gtk::ColumnViewColumn::create("Name", factory);
  m_ColumnView.append_column(m_NameColumn);
  auto ustring_expression = Gtk::ClosureExpression<Glib::ustring>::create(
    [](const Glib::RefPtr<Glib::ObjectBase>& item)->Glib::ustring
    {
      const auto col = std::dynamic_pointer_cast<ModelColumns>(item);
      return col ? col->m_col_name : "";
    });
  m_NameSorter = Gtk::StringSorter::create(ustring_expression);

  // Show the list model without sorting.
  m_Button_NoSort.set_active(true);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_nosort()
{
  if (m_Button_NoSort.get_active())
  {
    m_SelectionModel->set_model(m_ListStore);
    m_IdColumn->set_sorter({});
    m_NameColumn->set_sorter({});
  }
}

void ExampleWindow::on_button_sortheadings()
{
  if (m_Button_SortHeadings.get_active())
  {
    m_SortListModel->set_sorter(m_ColumnView.get_sorter());
    m_SelectionModel->set_model(m_SortListModel);
    m_IdColumn->set_sorter(m_IdSorter);
    m_NameColumn->set_sorter(m_NameSorter);
  }
}

void ExampleWindow::on_button_sortlength()
{
  if (m_Button_SortLength.get_active())
  {
    m_SortListModel->set_sorter(m_LengthSorter);
    m_SelectionModel->set_model(m_SortListModel);
    m_IdColumn->set_sorter({});
    m_NameColumn->set_sorter({});
  }
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_setup_label(
  const Glib::RefPtr<Gtk::ListItem>& list_item, Gtk::Align halign)
{
  list_item->set_child(*Gtk::make_managed<Gtk::Label>("", halign));
}

void ExampleWindow::on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(Glib::ustring::format(col->m_col_id));
}

void ExampleWindow::on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(col->m_col_name);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-listmodel-filtering">
<title xml:lang="en">Filtering</title>

<para xml:lang="en">
The list can be filtered by wrapping it in a <classname>FilterListModel</classname>.
Set a <classname>Filter</classname> such as a <classname>StringFilter</classname>
or a <classname>BoolFilter</classname> to the <classname>FilterListModel</classname>.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1FilterListModel.html">FilterListModel Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1StringFilter.html">StringFilter Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1BoolFilter.html">BoolFilter Reference</link></para>

<section xml:id="listmodel-filtering-example">
<title>Příklad</title>

<figure xml:id="figure-listmodel-filtering">
  <title xml:lang="en">FilterListModel</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/listmodel_filter.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/filter">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_button_showall();
  void on_button_showj();
  void on_button_showm();
  void on_button_quit();
  void on_setup_label(const Glib::RefPtr<Gtk::ListItem>& list_item, Gtk::Align halign);
  void on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item);

  // A Gio::ListStore item.
  class ModelColumns : public Glib::Object
  {
  public:
    unsigned int m_col_id;
    Glib::ustring m_col_name;

    static Glib::RefPtr<ModelColumns> create(int col_id, const Glib::ustring& col_name)
    {
      return Glib::make_refptr_for_instance<ModelColumns>(
        new ModelColumns(col_id, col_name));
    }

  protected:
    ModelColumns(int col_id, const Glib::ustring& col_name)
    : m_col_id(col_id), m_col_name(col_name)
    {}
  }; // ModelColumns

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::ColumnView m_ColumnView;
  Gtk::Box m_ButtonBox;
  Gtk::ToggleButton m_Button_ShowAll;
  Gtk::ToggleButton m_Button_ShowJ;
  Gtk::ToggleButton m_Button_ShowM;
  Gtk::Button m_Button_Quit;

  Glib::RefPtr<Gtk::SingleSelection> m_SelectionModel; 
  Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
  Glib::RefPtr<Gtk::FilterListModel> m_FilterListModel;
  Glib::RefPtr<Gtk::StringFilter> m_StringFilter;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_ShowAll("Show All"),
  m_Button_ShowJ("Show J"),
  m_Button_ShowM("Show M"),
  m_Button_Quit("Quit")
{
  set_title("Gtk::ColumnView (Gtk::FilterListModel) example");
  set_default_size(400, 350);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the ColumnView, inside a ScrolledWindow, with the buttons underneath:
  m_ScrolledWindow.set_child(m_ColumnView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.set_margin(5);
  m_ButtonBox.set_spacing(10);
  m_ButtonBox.append(m_Button_ShowAll);
  m_ButtonBox.append(m_Button_ShowJ);
  m_ButtonBox.append(m_Button_ShowM);
  m_ButtonBox.append(m_Button_Quit);
  m_Button_ShowAll.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_showall));
  m_Button_ShowJ.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_showj));
  m_Button_ShowM.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_showm));
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_quit));

  // Gtk::CheckButton and Gtk::ToggleButton have set_group() methods.
  // They act as radio buttons, if they are included in a group.
  m_Button_ShowJ.set_group(m_Button_ShowAll);
  m_Button_ShowM.set_group(m_Button_ShowAll);

  // Create the List model.
  m_ListStore = Gio::ListStore<ModelColumns>::create();
  m_ListStore->append(ModelColumns::create(1, "Billy Bob"));
  m_ListStore->append(ModelColumns::create(11, "Billy Bob Junior"));
  m_ListStore->append(ModelColumns::create(12, "Sue Bob"));
  m_ListStore->append(ModelColumns::create(2, "Joey Jojo"));
  m_ListStore->append(ModelColumns::create(3, "Rob McRoberts"));
  m_ListStore->append(ModelColumns::create(31, "Xavier McRoberts"));

  // Create the filter model.
  auto expression = Gtk::ClosureExpression<Glib::ustring>::create(
    [](const Glib::RefPtr<Glib::ObjectBase>& item)->Glib::ustring
    {
      const auto col = std::dynamic_pointer_cast<ModelColumns>(item);
      return col ? col->m_col_name : "";
    });
  m_StringFilter = Gtk::StringFilter::create(expression);
  m_StringFilter->set_ignore_case(false);
  m_StringFilter->set_match_mode(Gtk::StringFilter::MatchMode::SUBSTRING);
  m_FilterListModel = Gtk::FilterListModel::create(m_ListStore, m_StringFilter);

  // Set list model and selection model.
  m_SelectionModel = Gtk::SingleSelection::create(m_ListStore);
  m_SelectionModel->set_autoselect(false);
  m_SelectionModel->set_can_unselect(true);
  m_ColumnView.set_model(m_SelectionModel);
  m_ColumnView.add_css_class("data-table"); // high density table

  // Make the columns reorderable.
  // This is not necessary, but it's nice to show the feature.
  m_ColumnView.set_reorderable(true);

  // Add the ColumnView's columns:

  // Id column
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::END));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_id));
  auto column = Gtk::ColumnViewColumn::create("ID", factory);
  m_ColumnView.append_column(column);

  // Name column
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(sigc::bind(sigc::mem_fun(*this,
    &ExampleWindow::on_setup_label), Gtk::Align::START));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_name));
  column = Gtk::ColumnViewColumn::create("Name", factory);
  m_ColumnView.append_column(column);

  // Show the list model without filtering.
  m_Button_ShowAll.set_active(true);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_showall()
{
  if (m_Button_ShowAll.get_active())
    m_SelectionModel->set_model(m_ListStore);
}

void ExampleWindow::on_button_showj()
{
  if (m_Button_ShowJ.get_active())
  {
   m_StringFilter->set_search("J");
    m_SelectionModel->set_model(m_FilterListModel);
  }
}

void ExampleWindow::on_button_showm()
{
  if (m_Button_ShowM.get_active())
  {
   m_StringFilter->set_search("M");
    m_SelectionModel->set_model(m_FilterListModel);
  }
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_setup_label(
  const Glib::RefPtr<Gtk::ListItem>& list_item, Gtk::Align halign)
{
  list_item->set_child(*Gtk::make_managed<Gtk::Label>("", halign));
}

void ExampleWindow::on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(Glib::ustring::format(col->m_col_id));
}

void ExampleWindow::on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(col->m_col_name);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

<section xml:id="sec-listmodel-trees">
<title xml:lang="en">Displaying Trees</title>

<para xml:lang="en">
While the deprecated <classname>TreeView</classname> provided built-in support for trees,
the list widgets, and in particular <classname>Gio::ListModel</classname>, do not.
However, <application>gtkmm</application> provides functionality to make trees look and behave like lists for
the people who still want to display lists. This is achieved by using the
<classname>TreeListModel</classname> to flatten a tree into a list.
The <classname>TreeExpander</classname> widget can then be used inside a listitem
to allow users to expand and collapse rows.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeListModel.html">TreeListModel Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeExpander.html">TreeExpander Reference</link></para>

<section xml:id="listmodel-tree-example">
<title>Příklad</title>

<figure xml:id="figure-listmodel-tree">
  <title xml:lang="en">TreeListModel</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/listmodel_tree.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/tree_columnview">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_button_quit();
  void on_setup_id(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_setup_name(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item);

  Glib::RefPtr<Gio::ListModel> create_model(
    const Glib::RefPtr<Glib::ObjectBase>& item = {});

  // A Gio::ListStore item.
  class ModelColumns : public Glib::Object
  {
  public:
    int m_col_id;
    Glib::ustring m_col_name;

    static Glib::RefPtr<ModelColumns> create(int col_id, const Glib::ustring& col_name)
    {
      return Glib::make_refptr_for_instance<ModelColumns>(
        new ModelColumns(col_id, col_name));
    }

  protected:
    ModelColumns(int col_id, const Glib::ustring& col_name)
    : m_col_id(col_id), m_col_name(col_name)
    {}
  }; // ModelColumns

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::ColumnView m_ColumnView;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;

  Glib::RefPtr<Gtk::TreeListModel> m_TreeListModel;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit")
{
  set_title("Gtk::ColumnView (Gtk::TreeListModel) example");
  set_default_size(300, 350);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the ColumnView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_ColumnView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_quit));

  // Create the root model:
  auto root = create_model();

  // Set list model and selection model.
  // passthrough must be false when Gtk::TreeExpander is used in the view.
  m_TreeListModel = Gtk::TreeListModel::create(root,
    sigc::mem_fun(*this, &ExampleWindow::create_model),
    /* passthrough */ false, /* autoexpand */ false);
  auto selection_model = Gtk::MultiSelection::create(m_TreeListModel);
  m_ColumnView.set_model(selection_model);
  m_ColumnView.add_css_class("data-table"); // high density table

  // Make the columns reorderable.
  // This is not necessary, but it's nice to show the feature.
  m_ColumnView.set_reorderable(true);

  // Add the ColumnView's columns:

  // Id column
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_id));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_id));
  auto column = Gtk::ColumnViewColumn::create("ID", factory);
  m_ColumnView.append_column(column);

  // Name column
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_name));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_name));
  column = Gtk::ColumnViewColumn::create("Name", factory);
  m_ColumnView.append_column(column);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

Glib::RefPtr<Gio::ListModel> ExampleWindow::create_model(
  const Glib::RefPtr<Glib::ObjectBase>& item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(item);
  auto result = Gio::ListStore<ModelColumns>::create();
  if (!col)
  {
    // Top names
    result->append(ModelColumns::create(1, "Billy Bob"));
    result->append(ModelColumns::create(2, "Joey Jojo"));
    result->append(ModelColumns::create(3, "Rob McRoberts"));
  }
  else
  {
    switch (col->m_col_id)
    {
    case 1:
      result->append(ModelColumns::create(11, "Billy Bob Junior"));
      result->append(ModelColumns::create(12, "Sue Bob"));
      break;
    case 3:
      result->append(ModelColumns::create(31, "Xavier McRoberts"));
      break;
    }
  }

  // If result is empty, it's a leaf in the tree, i.e. an item without children.
  // Returning an empty RefPtr (not a RefPtr with an empty Gio::ListModel)
  // signals that the item is not expandable.
  return (result->get_n_items() > 0) ? result : Glib::RefPtr<Gio::ListModel>();
}

void ExampleWindow::on_setup_id(
  const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  // Each ListItem contains a TreeExpander, which contains a Label.
  // The Label shows the ModelColumns::m_col_id. That's done in on_bind_id(). 
  auto expander = Gtk::make_managed<Gtk::TreeExpander>();
  auto label = Gtk::make_managed<Gtk::Label>();
  label->set_halign(Gtk::Align::END);
  expander->set_child(*label);
  list_item->set_child(*expander);
}

void ExampleWindow::on_setup_name(
  const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  list_item->set_child(*Gtk::make_managed<Gtk::Label>("", Gtk::Align::START));
}

void ExampleWindow::on_bind_id(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  // When TreeListModel::property_passthrough() is false, ListItem::get_item()
  // is a TreeListRow. TreeExpander needs the TreeListRow.
  // The ModelColumns item is returned by TreeListRow::get_item().
  auto row = std::dynamic_pointer_cast<Gtk::TreeListRow>(list_item->get_item());
  if (!row)
    return;
  auto col = std::dynamic_pointer_cast<ModelColumns>(row->get_item());
  if (!col)
    return;
  auto expander = dynamic_cast<Gtk::TreeExpander*>(list_item->get_child());
  if (!expander)
    return;
  expander->set_list_row(row);
  auto label = dynamic_cast<Gtk::Label*>(expander->get_child());
  if (!label)
    return;
  label->set_text(Glib::ustring::format(col->m_col_id));
}

void ExampleWindow::on_bind_name(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto row = std::dynamic_pointer_cast<Gtk::TreeListRow>(list_item->get_item());
  if (!row)
    return;
  auto col = std::dynamic_pointer_cast<ModelColumns>(row->get_item());
  if (!col)
    return;
  auto label = dynamic_cast<Gtk::Label*>(list_item->get_child());
  if (!label)
    return;
  label->set_text(col->m_col_name);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

</chapter>

<chapter xml:id="chapter-treeview">
<title>Widget TreeView</title>

<note><para xml:lang="en"><classname>Gtk::TreeView</classname> is deprecated since <application>gtkmm</application> 4.10.
In new code, use <classname>Gtk::ListView</classname> for lists and
<classname>Gtk::ColumnView</classname> for tabular lists.
</para></note>

<para>Widget <classname>Gtk::TreeView</classname> může obsahovat seznam nebo strom s daty ve sloupcích.</para>

<section xml:id="sec-treeview-model">
<title>Model</title>

<para>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.</para>
<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeModel.html">Reference</link></para>

<section xml:id="treeview-model-liststore">
<title>ListStore (pro řádky)</title>

<para><classname>ListStore</classname> obsahuje jen řádková data, řádky nemají žádné potomky.</para>

<figure xml:id="figure-treeview-liststore-model">
  <title>TreeView – ListStore</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_list.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ListStore.html">Reference</link></para>

</section>

<section xml:id="treeview-model-treestore">
<title>TreeStore (pro hierarchii)</title>

<para><classname>TreeStore</classname> obsahuje řádková data a každý z řádků může mít potomky v podobě dalších řádků.</para>

<figure xml:id="figure-treeview-treestore-model">
  <title>TreeView – TreeStore</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_tree.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeStore.html">Reference</link></para>

</section>

<section xml:id="treeview-model-columns">
<title>Sloupce modelu</title>

<para xml:lang="en">
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>TreeModelColumn</classname>s 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.
</para>

<programlisting xml:lang="en"><code>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;</code></programlisting>

<para>Když vytváříte Model, určíte <classname>ColumnRecord</classname> takto:</para>
<programlisting xml:lang="en"><code>Glib::RefPtr&lt;Gtk::ListStore&gt; refListStore =
    Gtk::ListStore::create(m_Columns);</code></programlisting>
<para xml:lang="en">
As a <classname>TreeModelColumnRecord</classname> describes structure, not data,
it can be shared among multiple models, and this is preferable for efficiency.
However, the instance (such as <varname>m_Columns</varname> here) should usually
not be static, because it often needs to be instantiated after
<application>glibmm</application> has been initialized. The best solution is
to make it a lazily instantiated singleton, so that it will be constructed
on-demand, whenever the first model accesses it.
</para>
</section>

<section xml:id="treeview-adding-rows">
<title>Přidávání řádků</title>

<para>Řádky do modelu přidejte pomocí metod <methodname>append()</methodname>, <methodname>prepend()</methodname> nebo <methodname>insert()</methodname>.</para>
<programlisting xml:lang="en"><code>auto iter = m_refListStore-&gt;append();</code></programlisting>
<para>Pro získání řádku <classname>Row</classname> můžete použít dereferenci iterátoru:</para>
<programlisting xml:lang="en"><code>auto row = *iter;</code></programlisting>
<section xml:id="treeview-adding-child-rows">
<title>Přidávání synovský řádků</title>
<para>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:</para>
<programlisting xml:lang="en"><code>auto iter_child =
    m_refTreeStore-&gt;append(row.children());</code></programlisting>
</section>

</section>

<section xml:id="treeview-setting-values">
<title>Nastavení hodnot</title>

<para xml:lang="en">
You can use the <methodname>operator[]</methodname> overload to set the data for a
particular column in the row, specifying the
<classname>TreeModelColumn</classname> used to create the model.
</para>
<programlisting xml:lang="en"><code>row[m_Columns.m_col_text] = "sometext";</code></programlisting>
</section>

<section xml:id="treeview-getting-values">
<title>Získání hodnot</title>

<para xml:lang="en">
You can use the <methodname>operator[]</methodname> overload to get the data in a
particular column in a row, specifying the
<classname>TreeModelColumn</classname> used to create the model.
</para>
<programlisting xml:lang="en"><code>auto strText = row[m_Columns.m_col_text];
auto number = row[m_Columns.m_col_number];</code></programlisting>
<para>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:</para>
<programlisting xml:lang="en"><code>//compiler error - no conversion from ustring to int.
int number = row[m_Columns.m_col_text];</code></programlisting>
</section>

<section xml:id="treeview-hidden-columns">
<title>„Skryté“ sloupce</title>

<para>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.</para>
</section>

</section>

<section xml:id="sec-treeview">
<title>Zobrazení (View)</title>

<para><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.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeView.html">Reference</link></para>

<section xml:id="sec-treeview-using-a-model">
<title>Použití modelu</title>

<para><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:</para>
<programlisting xml:lang="en"><code>m_TreeView.set_model(m_refListStore);</code></programlisting>
</section>

<section xml:id="treeview-adding-view-columns">
<title>Přidání sloupců do zobrazení</title>

<para>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ů.</para>
<programlisting xml:lang="en"><code>m_TreeView.append_column("Messages", m_Columns.m_col_text);</code></programlisting>
<para xml:lang="en">
When using this simple <methodname>append_column()</methodname> overload, 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.
</para>
</section>

<section xml:id="treeview-multiple-model-columns-per-view-column">
<title>Více než jeden sloupec modelu ve sloupci zobrazení</title>

<para>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>.</para>

<para xml:lang="en">
Then use <methodname>append_column()</methodname> to add the view Column to the
View. Notice that <methodname>Gtk::TreeView::append_column()</methodname> is overloaded
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.
</para>
<para xml:lang="en">
Here is some example code, which has a pixbuf icon and a text name in the same column:
</para>
<programlisting xml:lang="en"><code>auto pColumn = Gtk::make_managed&lt;Gtk::TreeView::Column&gt;("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);</code></programlisting>
</section>

<section xml:id="treeview-cellrenderer-details">
<title>Určení údajů pro CellRenderer</title>

<para xml:lang="en">
The default <classname>CellRenderer</classname>s and their default behavior
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.
</para>
<programlisting xml:lang="en"><code>auto cols_count = m_TreeView.append_column_editable("Alex", m_columns.alex);
auto pColumn = m_TreeView.get_column(cols_count-1);
if(pColumn)
{
  auto 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);</code></programlisting>

<para>Můžete také napojit signál <classname>CellRenderer</classname>, abyste odhalili uživatelské činnosti. Například:</para>
<programlisting xml:lang="en"><code>auto pRenderer = Gtk::make_managed&lt;Gtk::CellRendererToggle&gt;();
pRenderer-&gt;signal_toggled().connect(
    sigc::bind( sigc::mem_fun(*this,
        &amp;Example_TreeView_TreeStore::on_cell_toggled), m_columns.dave)
);</code></programlisting>
</section>

<section xml:id="treeview-editable-cells">
<title>Editovatelné buňky</title>

<section xml:id="treeview-editable-cells-automatic">
<title>Editovatelné buňky s automatickým ukládáním.</title>

<para xml:lang="en">
Cells 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.
</para>
</section>

<section xml:id="treeview-editable-cells-custom">
<title>Implementace vlastní logiky pro editovatelné buňky.</title>

<para>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.</para>
<para xml:lang="en">
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.
</para>
<para>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.</para>
<para>Například, pro <classname>CellRendererText</classname> byste mohli nastavit vlastnost buňky <emphasis>editable</emphasis> na <literal>true</literal> takto:</para>
<programlisting xml:lang="en"><code>cell-&gt;property_editable() = true;</code></programlisting>
<para>U <classname>CellRendererToggle</classname> byste místo toho mohli nastavit vlastnost <emphasis>activatable</emphasis>.</para>
<para xml:lang="en">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_cells()</methodname> on that view Column.
</para>
<para>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.</para>
</section>
</section>
</section>

<section xml:id="sec-iterating-over-model-rows">
<title>Iterace přes řádky modelu</title>

<para><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:</para>
<programlisting xml:lang="en"><code>auto children = refModel-&gt;children();
for (auto iter = children.begin(), end = children.end(); iter != end; ++iter)
{
  auto row = *iter;
  //Do something with the row - see above for set/get.
}</code></programlisting>
<para xml:lang="en">
If you always want to iterate across the entire range, much more succinct syntax
is possible using C++'s range-based <literal>for</literal> loop:
</para>
<programlisting xml:lang="en"><code>for (auto row: refModel-&gt;children())
{
  //Do something with the row - see above for set/get.
}</code></programlisting>

<section xml:id="treeview-row-children">
<title>Potomci řádku</title>

<para xml:lang="en">
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:
</para>
<programlisting xml:lang="en"><code>Gtk::TreeModel::Children children = row.children();</code></programlisting>
</section>

</section>

<section xml:id="sec-treeview-selection">
<title>Výběr</title>

<para>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:</para>
<programlisting xml:lang="en"><code>auto refTreeSelection = m_TreeView.get_selection();</code></programlisting>

<section xml:id="treeview-selection-mode">
<title>Jednoduchý nebo vícenásobný výběr</title>

<para xml:lang="en">
By default, only single rows can be selected, but you can allow
multiple selection by setting the mode, like so:
</para>
<programlisting xml:lang="en"><code>refTreeSelection-&gt;set_mode(Gtk::SelectionMode::MULTIPLE);</code></programlisting>
</section>

<section xml:id="treeview-selected-rows">
<title>Vybrané řádky</title>

<para>Pro označení jednoho řádku stačí zavolat <methodname>get_selected()</methodname>, takto:</para>
<programlisting xml:lang="en"><code>auto iter = refTreeSelection-&gt;get_selected();
if(iter) //If anything is selected
{
  auto row = *iter;
  //Do something with the row.
}</code></programlisting>

<para xml:lang="en">
For multiple-selection, you need to call <methodname>get_selected_rows()</methodname>
or define a callback, and give it to
<methodname>selected_foreach()</methodname>,
<methodname>selected_foreach_path()</methodname>, or
<methodname>selected_foreach_iter()</methodname>, like so:
</para>
<programlisting xml:lang="en"><code>refTreeSelection-&gt;selected_foreach_iter(
    sigc::mem_fun(*this, &amp;TheClass::selected_row_callback) );

void TheClass::selected_row_callback(
    const Gtk::TreeModel::const_iterator&amp; iter)
{
  auto row = *iter;
  //Do something with the row.
}</code></programlisting>

</section>

<section xml:id="treeview-selection-changed-signal">
<title>Signál "changed"</title>

<para>Když chcete reagovat na uživatelovo kliknutí na řádek nebo rozsah řádků, připojte nějak takto signál:</para>
<programlisting xml:lang="en"><code>refTreeSelection-&gt;signal_changed().connect(
    sigc::mem_fun(*this, &amp;Example_IconTheme::on_selection_changed)
);</code></programlisting>
</section>

<section xml:id="treeview-selection-preventing">
<title>Jak zabárnit výběru řádku</title>

<para>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.</para>
<para>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:</para>
<programlisting xml:lang="en"><code>m_refTreeSelection-&gt;set_select_function( sigc::mem_fun(*this,
    &amp;DemoWindow::select_function) );</code></programlisting>
<para>a pak</para>
<programlisting xml:lang="en"><code>bool DemoWindow::select_function(
    const Glib::RefPtr&lt;Gtk::TreeModel&gt;&amp; model,
    const Gtk::TreeModel::Path&amp; path, bool)
{
  const auto iter = model-&gt;get_iter(path);
  return iter-&gt;children().empty(); // only allow leaf nodes to be selected
}</code></programlisting>
</section>

<section xml:id="treeview-selection-changing">
<title>Změna výběru</title>

<para>Pro změnu výběru určete <classname>Gtk::TreeModel::iterator</classname> nebo <classname>Gtk::TreeModel::Row</classname>, takto:</para>
<programlisting xml:lang="en"><code>auto row = m_refModel-&gt;children()[5]; //The sixth row.
if(row)
  refTreeSelection-&gt;select(row.get_iter());</code></programlisting>
<para>nebo</para>
<programlisting xml:lang="en"><code>auto iter = m_refModel-&gt;children().begin()
if(iter)
  refTreeSelection-&gt;select(iter);</code></programlisting>
</section>
</section>

<section xml:id="sec-treeview-sort">
<title>Řazení</title>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeSortable.html">TreeSortable Reference</link></para>

<section xml:id="treeview-sort-headers">
<title>Řazení klikáním na sloupce</title>

<para>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:</para>
<programlisting xml:lang="en"><code>auto pColumn = treeview.get_column(0);
if(pColumn)
  pColumn-&gt;set_sort_column(m_columns.m_col_id);</code></programlisting>
</section>

<section xml:id="treeview-sort-independent-views">
<title>Nezávisle řazená zobrazení téhož modelu</title>

<para xml:lang="en">
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::TreeViewColumn::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:
</para>
<programlisting xml:lang="en"><code>auto sorted_model = Gtk::TreeModelSort::create(model);
sorted_model-&gt;set_sort_column(columns.m_col_name, Gtk::SortType::ASCENDING);
treeview.set_model(sorted_model);</code></programlisting>

<para>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:</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_button_delete()
{
  auto refTreeSelection = m_treeview.get_selection();
  if(refTreeSelection)
  {
    auto sorted_iter = m_refTreeSelection-&gt;get_selected();
    if(sorted_iter)
    {
      auto iter = m_refModelSort-&gt;convert_iter_to_child_iter(sorted_iter);
      m_refModel-&gt;erase(iter);
    }
  }
}</code></programlisting>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TreeModelSort.html">TreeModelSort Reference</link></para>
</section>

</section>

<section xml:id="sec-treeview-draganddrop">
<title>Táhni a upusť</title>

<para xml:lang="en">
<classname>Gtk::TreeView</classname> already implements simple drag-and-drop
when used with the <classname>Gtk::ListStore</classname> or
<classname>Gtk::TreeStore</classname> models (since gtk 4.8). If necessary, it also allows you
to implement more complex behavior when items are dragged and dropped, using
the normal <link linkend="chapter-draganddrop">Drag and Drop</link> API.
</para>

<section xml:id="treeview-reorderable-rows">
<title>Seřaditelné řádky</title>

<para>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>.</para>
<para xml:lang="en">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_vfunc()</literal> and
<literal>Gtk::TreeDragDest::row_drop_possible_vfunc()</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>.</para>
<para>Ukázané to je v příkladu drag_and_drop.</para>
</section>

</section>

<section xml:id="sec-treeview-contextmenu">
<title>Vyskakovací kontextová nabídka</title>

<para xml:lang="en">
Lots 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. It's much the same as a normal context menu, as described
in the <link linkend="sec-menus-popup">menus chapter</link>. You use a
<classname>Gtk::GestureClick</classname> to detect the mouse click.
</para>
<para xml:lang="en">This is demonstrated in the Popup Context Menu example. In that example
a derived <classname>TreeView</classname> is used, but that's not necessary.
</para>

</section>

<section xml:id="sec-treeview-examples">
<title>Příklady</title>

<para xml:lang="en">Some <classname>TreeView</classname> examples are shown here. There are
more examples in the <link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/">treeview directory</link>
in <application>gtkmm-documentation</application>'s examples.</para>

<para xml:lang="en">If neither <classname>ListStore</classname> nor <classname>TreeStore</classname>
is suitable for your application, look at the
<link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/custom_treemodel">custom TreeModel</link>
example. It shows how you can make your own implementation of the <classname>TreeModel</classname>
interface.</para>

<section xml:id="liststore-example">
<title>ListStore</title>
<para>Tento příklad obsahuje widget <classname>Gtk::TreeView</classname> s modelem <classname>Gtk::ListStore</classname>.</para>

<figure xml:id="figure-treeview-liststore">
  <title>TreeView – ListStore</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_list.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/list/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();

  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); add(m_col_number); add(m_col_percentage);}

    Gtk::TreeModelColumn<unsigned int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
    Gtk::TreeModelColumn<short> m_col_number;
    Gtk::TreeModelColumn<int> m_col_percentage;
  };

  ModelColumns m_Columns;

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TreeView m_TreeView;
  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit")
{
  set_title("Gtk::TreeView (ListStore) example");
  set_default_size(400, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_TreeView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );

  //Create the Tree model:
  m_refTreeModel = Gtk::ListStore::create(m_Columns);
  m_TreeView.set_model(m_refTreeModel);

  //Fill the TreeView's model
  auto row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "Billy Bob";
  row[m_Columns.m_col_number] = 10;
  row[m_Columns.m_col_percentage] = 15;

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "Joey Jojo";
  row[m_Columns.m_col_number] = 20;
  row[m_Columns.m_col_percentage] = 40;

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "Rob McRoberts";
  row[m_Columns.m_col_number] = 30;
  row[m_Columns.m_col_percentage] = 70;

  //Add the TreeView's view columns:
  //This number will be shown with the default numeric formatting.
  m_TreeView.append_column("ID", m_Columns.m_col_id);
  m_TreeView.append_column("Name", m_Columns.m_col_name);

  m_TreeView.append_column_numeric("Formatted number", m_Columns.m_col_number,
          "%010d" /* 10 digits, using leading zeroes. */);

  //Display a progress bar instead of a decimal number:
  auto cell = Gtk::make_managed<Gtk::CellRendererProgress>();
  int cols_count = m_TreeView.append_column("Some percentage", *cell);
  auto pColumn = m_TreeView.get_column(cols_count - 1);
  if(pColumn)
  {
    pColumn->add_attribute(cell->property_value(), m_Columns.m_col_percentage);
  }

  //Make all the columns reorderable:
  //This is not necessary, but it's nice to show the feature.
  //You can use TreeView::set_column_drag_function() to more
  //finely control column drag and drop.
  for(guint i = 0; i < 2; i++)
  {
    auto column = m_TreeView.get_column(i);
    column->set_reorderable();
  }
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="treestore-example">
<title>TreeStore</title>

<para>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ů.</para>

<figure xml:id="figure-treeview-treestore">
  <title>TreeView – TreeStore</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_tree.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/tree/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();
  void on_treeview_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);

  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); }

    Gtk::TreeModelColumn<int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
  };

  ModelColumns m_Columns;

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TreeView m_TreeView;
  Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit")
{
  set_title("Gtk::TreeView (TreeStore) example");
  set_default_size(400, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_TreeView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );

  //Create the Tree model:
  m_refTreeModel = Gtk::TreeStore::create(m_Columns);
  m_TreeView.set_model(m_refTreeModel);

  //All the items to be reordered with drag-and-drop:
  m_TreeView.set_reorderable();

  //Fill the TreeView's model
  auto row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "Billy Bob";

  auto childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 11;
  childrow[m_Columns.m_col_name] = "Billy Bob Junior";

  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 12;
  childrow[m_Columns.m_col_name] = "Sue Bob";

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "Joey Jojo";


  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "Rob McRoberts";

  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 31;
  childrow[m_Columns.m_col_name] = "Xavier McRoberts";

  //Add the TreeView's view columns:
  m_TreeView.append_column("ID", m_Columns.m_col_id);
  m_TreeView.append_column("Name", m_Columns.m_col_name);

  //Connect signal:
  m_TreeView.signal_row_activated().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_treeview_row_activated) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_treeview_row_activated(const Gtk::TreeModel::Path& path,
        Gtk::TreeViewColumn* /* column */)
{
  const auto iter = m_refTreeModel->get_iter(path);
  if(iter)
  {
    const auto row = *iter;
    std::cout << "Row activated: ID=" << row[m_Columns.m_col_id] << ", Name="
        << row[m_Columns.m_col_name] << std::endl;
  }
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-editable-cells-example">
<title>Editovatelné buňky</title>

<para>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>.</para>

<figure xml:id="figure-treeview-editablecells">
  <title>TreeView – editovatelné buňky</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_editablecells.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/editable_cells/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();

  void treeviewcolumn_validated_on_cell_data(Gtk::CellRenderer* renderer, const Gtk::TreeModel::const_iterator& iter);
  void cellrenderer_validated_on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
  void cellrenderer_validated_on_edited(const Glib::ustring& path_string, const Glib::ustring& new_text);
  void on_message_response(int response_id, Gtk::MessageDialog* dialog);

  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); add(m_col_foo); add(m_col_number); add(m_col_number_validated); }

    Gtk::TreeModelColumn<unsigned int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
    Gtk::TreeModelColumn<bool> m_col_foo;
    Gtk::TreeModelColumn<int> m_col_number;
    Gtk::TreeModelColumn<int> m_col_number_validated;
  };

  ModelColumns m_Columns;

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TreeView m_TreeView;
  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;

  //For the validated column:
  //You could also use a CellRendererSpin or a CellRendererProgress:
  Gtk::CellRendererText m_cellrenderer_validated;
  Gtk::TreeView::Column m_treeviewcolumn_validated;
  bool m_validate_retry;
  Glib::ustring m_invalid_text_for_retry;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "examplewindow.h"

using std::sprintf;
using std::strtol;

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit"),
  m_validate_retry(false)
{
  set_title("Gtk::TreeView Editable Cells example");
  set_default_size(400, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_TreeView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );

  //Create the Tree model:
  m_refTreeModel = Gtk::ListStore::create(m_Columns);
  m_TreeView.set_model(m_refTreeModel);

  //Fill the TreeView's model
  auto row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "Billy Bob";
  row[m_Columns.m_col_foo] = true;
  row[m_Columns.m_col_number] = 10;

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "Joey Jojo";
  row[m_Columns.m_col_foo] = true;
  row[m_Columns.m_col_number] = 20;

  row = *(m_refTreeModel->append());

  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "Rob McRoberts";
  row[m_Columns.m_col_foo] = false;
  row[m_Columns.m_col_number] = 30;

  //Add the TreeView's view columns:
  //We use the *_editable convenience methods for most of these,
  //because the default functionality is enough:
  m_TreeView.append_column_editable("ID", m_Columns.m_col_id);
  m_TreeView.append_column_editable("Name", m_Columns.m_col_name);
  m_TreeView.append_column_editable("foo", m_Columns.m_col_foo);
  m_TreeView.append_column_numeric_editable("Number", m_Columns.m_col_number,
          "%010d");

  //For this column, we create the CellRenderer ourselves, and connect our own
  //signal handlers, so that we can validate the data that the user enters, and
  //control how it is displayed.
  m_treeviewcolumn_validated.set_title("validated (<10)");
  m_treeviewcolumn_validated.pack_start(m_cellrenderer_validated);
  m_TreeView.append_column(m_treeviewcolumn_validated);

  //Tell the view column how to render the model values:
  m_treeviewcolumn_validated.set_cell_data_func(m_cellrenderer_validated,
          sigc::mem_fun(*this,
              &ExampleWindow::treeviewcolumn_validated_on_cell_data) );

  //Make the CellRenderer editable, and handle its editing signals:
  m_cellrenderer_validated.property_editable() = true;

  m_cellrenderer_validated.signal_editing_started().connect(
          sigc::mem_fun(*this,
        &ExampleWindow::cellrenderer_validated_on_editing_started) );

  m_cellrenderer_validated.signal_edited().connect( sigc::mem_fun(*this,
              &ExampleWindow::cellrenderer_validated_on_edited) );

  //If this was a CellRendererSpin then you would have to set the adjustment:
  //m_cellrenderer_validated.property_adjustment() = m_spin_adjustment;
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::treeviewcolumn_validated_on_cell_data(
        Gtk::CellRenderer* /* renderer */,
        const Gtk::TreeModel::const_iterator& iter)
{
  //Get the value from the model and show it appropriately in the view:
  if(iter)
  {
    const auto row = *iter;
    int model_value = row[m_Columns.m_col_number_validated];

    //This is just an example.
    //In this case, it would be easier to use append_column_editable() or
    //append_column_numeric_editable()
    char buffer[32];
    sprintf(buffer, "%d", model_value);

    auto view_text = buffer;
    m_cellrenderer_validated.property_text() = view_text;
  }
}

void ExampleWindow::cellrenderer_validated_on_editing_started(
        Gtk::CellEditable* cell_editable, const Glib::ustring& /* path */)
{
  //Start editing with previously-entered (but invalid) text,
  //if we are allowing the user to correct some invalid data.
  if(m_validate_retry)
  {
    //This is the CellEditable inside the CellRenderer.
    auto celleditable_validated = cell_editable;

    //It's usually an Entry, at least for a CellRendererText:
    auto pEntry = dynamic_cast<Gtk::Entry*>(celleditable_validated);
    if(pEntry)
    {
      pEntry->set_text(m_invalid_text_for_retry);
      m_validate_retry = false;
      m_invalid_text_for_retry.clear();
    }
  }
}

void ExampleWindow::cellrenderer_validated_on_edited(
        const Glib::ustring& path_string,
        const Glib::ustring& new_text)
{
  Gtk::TreePath path(path_string);

  //Convert the inputed text to an integer, as needed by our model column:
  char* pchEnd = nullptr;
  int new_value = strtol(new_text.c_str(), &pchEnd, 10);

  if(new_value >= 10)
  {
    //Prevent entry of numbers higher than 10.

    //Tell the user:
    auto dialog = new Gtk::MessageDialog(*this,
            "The number must be less than 10. Please try again.",
            false, Gtk::MessageType::ERROR, Gtk::ButtonsType::OK, true /* modal */);
    dialog->signal_response().connect(sigc::bind(
      sigc::mem_fun(*this, &ExampleWindow::on_message_response), dialog));

    dialog->set_visible(true);

    //Start editing again, with the bad text, so that the user can correct it.
    //A real application should probably allow the user to revert to the
    //previous text.

    //Set the text to be used in the start_editing signal handler:
    m_invalid_text_for_retry = new_text;
    m_validate_retry = true;

    //Start editing again, when the message dialog has been closed:
    m_TreeView.set_cursor(path, m_treeviewcolumn_validated,
            m_cellrenderer_validated, true /* start_editing */);
  }
  else
  {
    //Get the row from the path:
    auto iter = m_refTreeModel->get_iter(path);
    if(iter)
    {
      auto row = *iter;

      //Put the new value in the model:
      row[m_Columns.m_col_number_validated] = new_value;
    }
  }
}

void ExampleWindow::on_message_response(int /* response_id */, Gtk::MessageDialog* dialog)
{
  delete dialog;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="treeview-dnd-example">
<title>Táhni a upusť</title>

<para>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>.</para>

<figure xml:id="figure-treeview-draganddrop">
  <title>TreeView – táhni a upusť</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_draganddrop.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/drag_and_drop/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "treemodel_dnd.h"


class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();


  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TreeView m_TreeView;
  Glib::RefPtr<TreeModel_Dnd> m_refTreeModel;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>treemodel_dnd.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_TREEMODEL_DND_H
#define GTKMM_EXAMPLE_TREEMODEL_DND_H

#include <gtkmm.h>

class TreeModel_Dnd : public Gtk::TreeStore
{
protected:
  TreeModel_Dnd();

public:

  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); add(m_col_draggable); add(m_col_receivesdrags); }

    Gtk::TreeModelColumn<int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
    Gtk::TreeModelColumn<bool> m_col_draggable;
    Gtk::TreeModelColumn<bool> m_col_receivesdrags;
  };

  ModelColumns m_Columns;

  static Glib::RefPtr<TreeModel_Dnd> create();

protected:
  //Overridden virtual functions:
  bool row_draggable_vfunc(const Gtk::TreeModel::Path& path) const override;
  bool row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Glib::ValueBase& value) const override;
};

#endif //GTKMM_EXAMPLE_TREEMODEL_DND_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("_Quit", true)
{
  set_title("Gtk::TreeView (Drag and Drop) example");
  set_default_size(400, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_TreeView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );

  //Create the Tree model:
  //Use our derived model, which overrides some Gtk::TreeDragDest and
  //Gtk::TreeDragSource virtual functions:
  //The columns are declared in the overridden TreeModel.
  m_refTreeModel = TreeModel_Dnd::create();
  m_TreeView.set_model(m_refTreeModel);

  //Enable Drag-and-Drop of TreeView rows:
  //See also the derived TreeModel's *_vfunc overrides.
  m_TreeView.enable_model_drag_source();
  m_TreeView.enable_model_drag_dest();

  //Fill the TreeView's model
  auto row = *(m_refTreeModel->append());
  row[m_refTreeModel->m_Columns.m_col_id] = 1;
  row[m_refTreeModel->m_Columns.m_col_name] = "Billy Bob";
  row[m_refTreeModel->m_Columns.m_col_draggable] = true;
  row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;

  auto childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_refTreeModel->m_Columns.m_col_id] = 11;
  childrow[m_refTreeModel->m_Columns.m_col_name] = "Billy Bob Junior";
  childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
  childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;

  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_refTreeModel->m_Columns.m_col_id] = 12;
  childrow[m_refTreeModel->m_Columns.m_col_name] = "Sue Bob";
  childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
  childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;

  row = *(m_refTreeModel->append());
  row[m_refTreeModel->m_Columns.m_col_id] = 2;
  row[m_refTreeModel->m_Columns.m_col_name] = "Joey Jojo";
  row[m_refTreeModel->m_Columns.m_col_draggable] = true;
  row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;

  row = *(m_refTreeModel->append());
  row[m_refTreeModel->m_Columns.m_col_id] = 3;
  row[m_refTreeModel->m_Columns.m_col_name] = "Rob McRoberts";
  row[m_refTreeModel->m_Columns.m_col_draggable] = true;
  row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;

  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_refTreeModel->m_Columns.m_col_id] = 31;
  childrow[m_refTreeModel->m_Columns.m_col_name] = "Xavier McRoberts";
  childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
  childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;

  //Add the TreeView's view columns:
  m_TreeView.append_column("ID", m_refTreeModel->m_Columns.m_col_id);
  m_TreeView.append_column("Name", m_refTreeModel->m_Columns.m_col_name);
  m_TreeView.append_column_editable("Draggable",
          m_refTreeModel->m_Columns.m_col_draggable);
  m_TreeView.append_column_editable("Receives Drags",
          m_refTreeModel->m_Columns.m_col_receivesdrags);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>treemodel_dnd.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "treemodel_dnd.h"
#include <iostream>

TreeModel_Dnd::TreeModel_Dnd()
{
  //We can't just call Gtk::TreeModel(m_Columns) in the initializer list
  //because m_Columns does not exist when the base class constructor runs.
  //And we can't have a static m_Columns instance, because that would be
  //instantiated before the gtkmm type system.
  //So, we use this method, which should only be used just after creation:
  set_column_types(m_Columns);
}

Glib::RefPtr<TreeModel_Dnd> TreeModel_Dnd::create()
{
  return Glib::make_refptr_for_instance<TreeModel_Dnd>( new TreeModel_Dnd() );
}

bool
TreeModel_Dnd::row_draggable_vfunc(const Gtk::TreeModel::Path& path) const
{
  // Make the value of the "draggable" column determine whether this row can
  // be dragged:

  const const_iterator iter = get_iter(path);
  if(iter)
  {
    ConstRow row = *iter;
    bool is_draggable = row[m_Columns.m_col_draggable];
    return is_draggable;
  }

  return Gtk::TreeStore::row_draggable_vfunc(path);
}

bool
TreeModel_Dnd::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest,
        const Glib::ValueBase& value) const
{
  //Make the value of the "receives drags" column determine whether a row can be
  //dragged into it:

  //dest is the path that the row would have after it has been dropped:
  //But in this case we are more interested in the parent row:
  auto dest_parent = dest;
  bool dest_is_not_top_level = dest_parent.up();
  if(!dest_is_not_top_level || dest_parent.empty())
  {
    //The user wants to move something to the top-level.
    //Let's always allow that.
  }
  else
  {
    //Get an iterator for the row at this path:
    const const_iterator iter_dest_parent = get_iter(dest_parent);
    if(iter_dest_parent)
    {
      ConstRow row = *iter_dest_parent;
      bool receives_drags = row[m_Columns.m_col_receivesdrags];
      return receives_drags;
    }
  }

  // You could also examine the row being dragged (via value)
  // if you must look at both rows to see whether a drop should be allowed.
  // You could use
  //   Glib::RefPtr<const Gtk::TreeModel> model_dragged_row;
  //   Gtk::TreeModel::Path path_dragged_row;
  //   Gtk::TreeModel::Path::get_row_drag_data(value,
  //     model_dragged_row, path_dragged_row);

  return Gtk::TreeStore::row_drop_possible_vfunc(dest, value);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="treeview-popup-menu-example">
<title>Vyskakovací kontextová nabídka</title>

<para xml:lang="en">
This example is much like the <classname>ListStore</classname> example, but
derives a custom <classname>TreeView</classname> to encapsulate the tree model
code and popup menu code in our derived class. See the
<link linkend="sec-treeview-contextmenu">TreeView Popup Context Menu</link> section.
</para>

<figure xml:id="figure-treeview-popup">
  <title>TreeView – vyskakovací kontextová nabídka</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/treeview_popup.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/treeview/popup/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "treeview_withpopup.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();



  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  TreeView_WithPopup m_TreeView;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>treeview_withpopup.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_TREEVIEW_WITHPOPUP_H
#define GTKMM_EXAMPLE_TREEVIEW_WITHPOPUP_H

#include <gtkmm.h>

class TreeView_WithPopup : public Gtk::TreeView
{
public:
  TreeView_WithPopup();
  virtual ~TreeView_WithPopup();

protected:
  // Signal handler for showing popup menu:
  void on_popup_button_pressed(int n_press, double x, double y);

  //Signal handler for popup menu items:
  void on_menu_file_popup_generic();


  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); }

    Gtk::TreeModelColumn<unsigned int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
  };

  ModelColumns m_Columns;

  //The Tree model:
  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;

  Gtk::PopoverMenu m_MenuPopup;
};

#endif //GTKMM_EXAMPLE_TREEVIEW_WITHPOPUP_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <iostream>
#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("Quit")
{
  set_title("Gtk::TreeView (ListStore) example");
  set_default_size(400, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_TreeView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>treeview_withpopup.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "treeview_withpopup.h"
#include <iostream>

TreeView_WithPopup::TreeView_WithPopup()
{
  //Create the Tree model:
  m_refTreeModel = Gtk::ListStore::create(m_Columns);
  set_model(m_refTreeModel);

  //Fill the TreeView's model
  auto row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "right-click on this";

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "or this";

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "or this, for a popup context menu";

  //Add the TreeView's view columns:
  append_column("ID", m_Columns.m_col_id);
  append_column("Name", m_Columns.m_col_name);

  // Catch button press events:
  auto refGesture = Gtk::GestureClick::create();
  refGesture->set_button(GDK_BUTTON_SECONDARY);
  refGesture->signal_pressed().connect(
    sigc::mem_fun(*this, &TreeView_WithPopup::on_popup_button_pressed));
  add_controller(refGesture);

  // Fill popup menu:
  auto gmenu = Gio::Menu::create();
  gmenu->append("_Edit", "popup.edit");
  gmenu->append("_Process", "popup.process");
  gmenu->append("_Remove", "popup.remove");

  m_MenuPopup.set_parent(*this);
  m_MenuPopup.set_menu_model(gmenu);
  m_MenuPopup.set_has_arrow(false);

  // Create actions:
  auto refActionGroup = Gio::SimpleActionGroup::create();

  refActionGroup->add_action("edit",
    sigc::mem_fun(*this, &TreeView_WithPopup::on_menu_file_popup_generic));
  refActionGroup->add_action("process",
    sigc::mem_fun(*this, &TreeView_WithPopup::on_menu_file_popup_generic));
  refActionGroup->add_action("remove",
    sigc::mem_fun(*this, &TreeView_WithPopup::on_menu_file_popup_generic));

  insert_action_group("popup", refActionGroup);
}

TreeView_WithPopup::~TreeView_WithPopup()
{
}

void TreeView_WithPopup::on_popup_button_pressed(int /* n_press */, double x, double y)
{
  const Gdk::Rectangle rect(x, y, 1, 1);
  m_MenuPopup.set_pointing_to(rect);
  m_MenuPopup.popup();
}

void TreeView_WithPopup::on_menu_file_popup_generic()
{
  std::cout << "A popup menu item was selected." << std::endl;

  auto refSelection = get_selection();
  if(refSelection)
  {
    auto iter = refSelection->get_selected();
    if(iter)
    {
      int id = (*iter)[m_Columns.m_col_id];
      std::cout << "  Selected ID=" << id << std::endl;
    }
  }
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-dropdown">
<title xml:lang="en">The DropDown Widget</title>

<para xml:lang="en">The <classname>DropDown</classname> widget is an alternative to the deprecated
<classname>ComboBox</classname>. It uses list models instead of tree models,
and the content is displayed using widgets instead of cell renderers.
</para>

<para xml:lang="en">The <classname>DropDown</classname> widget offers a list of choices in a
dropdown menu. If appropriate, it can show extra information about each item,
such as text, a picture, or a check button. The <classname>DropDown</classname> widget
can optionally have an <classname>Entry</classname> in the dropdown menu, allowing
the user to search in a long list.
</para>

<para xml:lang="en">The list is provided via a <classname>Gio::ListModel</classname>, and data
from this model is added to the <classname>DropDown</classname>'s view with
signal handlers connected to a <classname>SignalListItemFactory</classname>.
This provides flexibility, but the <classname>StringList</classname> class provides
a simpler text-based specialization in case that flexibility is not required.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1DropDown.html">Reference</link></para>

<section xml:id="sec-dropdown-model">
<title>Model</title>

<para xml:lang="en">The model for a <classname>DropDown</classname> can be defined and filled
exactly as for a <classname>ListView</classname> or a <classname>ColumnView</classname>.
It must be a subclass of <classname>Glib::Object</classname>.
For instance, you might have a <classname>DropDown</classname> with one integer
and one text column, like so:
</para>
<programlisting xml:lang="en"><code><![CDATA[class ModelColumns : public Glib::Object
{
public:
  int m_col_id;
  Glib::ustring m_col_name;

  static Glib::RefPtr<ModelColumns> create(
    int col_id, const Glib::ustring& col_name)
  {
    return Glib::make_refptr_for_instance<ModelColumns>(
      new ModelColumns(col_id, col_name));
  }

protected:
  ModelColumns(int col_id, const Glib::ustring& col_name)
  : m_col_id(col_id), m_col_name(col_name)
  {}
};

Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
]]></code></programlisting>

<para xml:lang="en">After appending rows to this model, you should provide the model to the
<classname>DropDown</classname> with the <methodname>set_model()</methodname> method.
Unless you use the <classname>StringList</classname> model, you also need to set
a <classname>ListItemFactory</classname> with <methodname>set_factory()</methodname>.
If you want the items in the dropdown menu to look different from the item
in the <classname>DropDown</classname> widget, you also need to set a separate
<classname>ListItemFactory</classname> with <methodname>set_list_factory()</methodname>.
</para>
</section>

<section xml:id="sec-dropdown-get">
<title xml:lang="en">The selected item</title>

<para xml:lang="en">To discover what item, if any, the user has selected from the <classname>DropDown</classname>,
call <methodname>DropDown::get_selected()</methodname>. This returns an
<type>unsigned int</type> that you can use to get the selected data from the model.
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
<classname>DropDown</classname>. For instance:
</para>
<programlisting xml:lang="en"><code><![CDATA[unsigned int sel = m_DropDown.get_selected();
if (sel != GTK_INVALID_LIST_POSITION)
{
  // Get the data for the selected row, using our knowledge of the list model:
  auto id = m_ListStore->get_item(sel).m_col_id;
  set_some_id_chosen(id); // Your own function.
}
else
  set_nothing_chosen(); // Your own function.
]]></code></programlisting>
</section>

<section xml:id="sec-dropdown-changes">
<title>Reagování na změny</title>

<para xml:lang="en">You might need to react to every change of selection in the <classname>DropDown</classname>,
for instance to update other widgets. To do so, you should connect to
<methodname>property_selected().signal_changed()</methodname>. For instance:
</para>
<programlisting xml:lang="en"><code><![CDATA[m_DropDown.property_selected().signal_changed().connect(
  sigc::mem_fun(*this, &ExampleWindow::on_dropdown_changed));
]]></code></programlisting>
</section>

<section xml:id="sec-dropdown-simple">
<title xml:lang="en">Simple String Example</title>

<figure xml:id="figure-dropdown-string">
  <title xml:lang="en">Simple DropDown</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dropdown_string.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dropdown/string">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/dropdown.h>
#include <gtkmm/stringlist.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handler:
  void on_dropdown_changed();

  // Child widget:
  Gtk::DropDown m_DropDown;

  Glib::RefPtr<Gtk::StringList> m_StringList;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("DropDown example");

  set_child(m_DropDown);

  // Fill the dropdown:
  const std::vector<Glib::ustring> strings{
    "1 minute", "2 minutes", "5 minutes", "20 minutes"
  };
  m_StringList = Gtk::StringList::create(strings);
  m_DropDown.set_model(m_StringList);
  m_DropDown.set_selected(0);

  // Connect signal handler:
  m_DropDown.property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dropdown_changed));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_dropdown_changed()
{
  const auto selected = m_DropDown.get_selected();
  std::cout << "DropDown changed: Row=" << selected
    << ", String=" << m_StringList->get_string(selected) << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>

<section xml:id="sec-dropdown-search">
<title xml:lang="en">Examples with a Search Entry</title>

<para xml:lang="en">The dropdown menu may contain an <classname>Entry</classname> that allows
to search for items in the list. Call <methodname>set_enable_search()</methodname>
and <methodname>set_expression()</methodname>. For instance:
</para>
<programlisting xml:lang="en"><code><![CDATA[m_DropDown.set_enable_search(true);
auto expression = Gtk::ClosureExpression<Glib::ustring>::create(
  sigc::mem_fun(*this, &ExampleWindow::get_col_name));
m_DropDown.set_expression(expression);

//-------
Glib::ustring ExampleWindow::get_col_name(const Glib::RefPtr<Glib::ObjectBase>& item)
{
  const auto col = std::dynamic_pointer_cast<ModelColumns>(item);
  return col ? col->m_col_name : "";
}
]]></code></programlisting>

<section xml:id="sec-dropdown-search-string">
<title xml:lang="en">String Example</title>

<figure xml:id="figure-dropdown-search-string">
  <title xml:lang="en">Search String</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dropdown_search_string.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dropdown/search_string">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/dropdown.h>
#include <gtkmm/stringlist.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handler:
  void on_dropdown_changed();

  // Child widget:
  Gtk::DropDown m_DropDown;
  
  Glib::RefPtr<Gtk::StringList> m_StringList;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/expression.h>
#include <gtkmm/stringobject.h>
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("Searchable DropDown example");

  set_child(m_DropDown);

  // Fill the dropdown:
  const std::vector<Glib::ustring> many_times{
    "1 minute", "2 minutes", "5 minutes", "10 minutes", "15 minutes", "20 minutes",
    "25 minutes", "30 minutes", "35 minutes", "40 minutes", "45 minutes", "50 minutes",
    "55 minutes", "1 hour", "2 hours", "3 hours", "5 hours", "6 hours", "7 hours",
    "8 hours", "9 hours", "10 hours", "11 hours", "12 hours"
  };
  m_StringList = Gtk::StringList::create(many_times);
  m_DropDown.set_model(m_StringList);
  m_DropDown.set_selected(0);

  // Show a search entry.
  m_DropDown.set_enable_search(true);
  auto expression = Gtk::ClosureExpression<Glib::ustring>::create(
    [](const Glib::RefPtr<Glib::ObjectBase>& item)->Glib::ustring
    {
      // An item in a StringList is a StringObject.
      const auto string_object = std::dynamic_pointer_cast<Gtk::StringObject>(item);
      return string_object ? string_object->get_string() : "";
    });
  m_DropDown.set_expression(expression);

  // Connect signal handler:
  m_DropDown.property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dropdown_changed));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_dropdown_changed()
{
  const auto selected = m_DropDown.get_selected();
  std::cout << "DropDown changed: Row=" << selected
    << ", String=" << m_StringList->get_string(selected) << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>

<section xml:id="sec-dropdown-search-font">
<title xml:lang="en">Font Example</title>

<para xml:lang="en">This example uses a <classname>Pango::FontMap</classname> as its model.
This is possible because <classname>Pango::FontMap</classname> implements
the <classname>Gio::ListModel</classname> interface. Of course you can use a
<classname>FontDialogButton</classname> instead.
</para>

<figure xml:id="figure-dropdown-search-font">
  <title xml:lang="en">Search Font</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dropdown_search_font.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dropdown/search_font">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handler:
  void on_dropdown_changed();

  Glib::ustring get_family_name(const Glib::RefPtr<Glib::ObjectBase>& item);

  // Child widget:
  Gtk::DropDown m_DropDown;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <pangomm/cairofontmap.h>
#include <iostream>
//#include <typeinfo>

ExampleWindow::ExampleWindow()
{
  set_title("Searchable DropDown example");

  // Add the DropDown to the window.
  set_child(m_DropDown);

  // Show a search entry.
  m_DropDown.set_enable_search(true);
  auto expression = Gtk::ClosureExpression<Glib::ustring>::create(
    sigc::mem_fun(*this, &ExampleWindow::get_family_name));
  m_DropDown.set_expression(expression);

  // Pango::FontMap is a Gio::ListModel.
  auto model = Pango::CairoFontMap::get_default();
  m_DropDown.set_model(model);
  m_DropDown.set_selected(0);

  // Connect signal handler.
  m_DropDown.property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dropdown_changed));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_dropdown_changed()
{
  const auto selected = m_DropDown.get_selected();
  const auto item = m_DropDown.get_selected_item();
  std::cout << "DropDown changed: Row=" << selected
    << ", Font=" << get_family_name(item) << std::endl;

  // Pango::FontMap is often a list of items of type Pango::FontFamily.
  // From the description of Pango::CairoFontMap: "The actual type of the font map
  // will depend on the particular font technology Cairo was compiled to use."
  // If get_family_name() does not return a family name, you can add
  // #include <typeinfo> and query the type of the items with:
  //   std::cout << typeid(*item.get()).name() << std::endl;
}

Glib::ustring ExampleWindow::get_family_name(const Glib::RefPtr<Glib::ObjectBase>& item)
{
  auto family = std::dynamic_pointer_cast<Pango::FontFamily>(item);
  return family ? family->get_name() : "";
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-dropdown-complex">
<title xml:lang="en">Complex Example</title>

<para xml:lang="en">This is a more complex example with two <classname>SignalListItemFactory</classname>
objects and their signal handlers. This example would be simpler without the
checkmark in the dropdown menu.
</para>

<figure xml:id="figure-dropdown-complex">
  <title xml:lang="en">Search Font</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dropdown_complex.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dropdown/complex">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_setup_selected_item(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_selected_item(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_setup_list_item(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_bind_list_item(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_unbind_list_item(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_selected_item_changed(const Glib::RefPtr<Gtk::ListItem>& list_item);
  void on_dropdown_changed();

  void create_model();
  void liststore_add_item(const Glib::ustring& title, const Glib::ustring& icon,
    const Glib::ustring& description);

  // A Gio::ListStore item.
  class ModelColumns : public Glib::Object
  {
  public:
    Glib::ustring m_title;
    Glib::ustring m_icon;
    Glib::ustring m_description;

    static Glib::RefPtr<ModelColumns> create(const Glib::ustring& title,
      const Glib::ustring& icon, const Glib::ustring& description)
    {
      return Glib::make_refptr_for_instance<ModelColumns>(
        new ModelColumns(title, icon, description));
    }

  protected:
    ModelColumns(const Glib::ustring& title, const Glib::ustring& icon,
      const Glib::ustring& description)
    : m_title(title), m_icon(icon), m_description(description)
    {}
  }; // ModelColumns

  // Child widget:
  Gtk::DropDown m_DropDown;

  Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("DropDown example");

  // Add the DropDown to the window.
  set_child(m_DropDown);

  // Factory for presenting the selected item.
  auto factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_selected_item));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_selected_item));
  m_DropDown.set_factory(factory);

  // Factory for presenting the items in the dropdown list.
  factory = Gtk::SignalListItemFactory::create();
  factory->signal_setup().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_setup_list_item));
  factory->signal_bind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_bind_list_item));
  factory->signal_unbind().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_unbind_list_item));
  m_DropDown.set_list_factory(factory);

  // Create the model and fill it.
  create_model();
  m_DropDown.set_model(m_ListStore);
  m_DropDown.set_selected(0);

  // Connect signal handler:
  m_DropDown.property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dropdown_changed));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_dropdown_changed()
{
  const auto selected = m_DropDown.get_selected();
  std::cout << "DropDown changed: Row=" << selected
    << ", Title=" << m_ListStore->get_item(selected)->m_title << std::endl;
}

void ExampleWindow::create_model()
{
  m_ListStore = Gio::ListStore<ModelColumns>::create();

  liststore_add_item("Digital Output", "audio-card-symbolic", "Built-in Audio");
  liststore_add_item("Headphones", "audio-headphones-symbolic", "Built-in Audio");
  liststore_add_item("Digital Output", "audio-card-symbolic", "Thinkpad Tunderbolt 3 Dock USB Audio");
  liststore_add_item("Analog Output", "audio-card-symbolic", "Thinkpad Tunderbolt 3 Dock USB Audio");
}

void ExampleWindow::liststore_add_item(const Glib::ustring& title,
  const Glib::ustring& icon, const Glib::ustring& description)
{
  m_ListStore->append(ModelColumns::create(title, icon, description));
}

void ExampleWindow::on_setup_selected_item(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
  box->append(*Gtk::make_managed<Gtk::Image>());
  box->append(*Gtk::make_managed<Gtk::Label>());
  list_item->set_child(*box);
}

void ExampleWindow::on_bind_selected_item(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto box = dynamic_cast<Gtk::Box*>(list_item->get_child());
  if (!box)
    return;
  auto image = dynamic_cast<Gtk::Image*>(box->get_first_child());
  if (!image)
    return;
  image->set_from_icon_name(col->m_icon);
  auto label = dynamic_cast<Gtk::Label*>(image->get_next_sibling());
  if (!label)
    return;
  label->set_text(col->m_title);
}

void ExampleWindow::on_setup_list_item(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto hbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
  auto vbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 2);

  hbox->append(*Gtk::make_managed<Gtk::Image>());
  hbox->append(*vbox);
  auto title = Gtk::make_managed<Gtk::Label>();
  title->set_xalign(0.0);
  vbox->append(*title);
  auto description = Gtk::make_managed<Gtk::Label>();
  description->set_xalign(0.0);
  description->add_css_class("dim-label");
  vbox->append(*description);
  auto checkmark = Gtk::make_managed<Gtk::Image>();
  checkmark->set_from_icon_name("object-select-symbolic");
  checkmark->set_visible(false);
  hbox->append(*checkmark);

  list_item->set_child(*hbox);
}

void ExampleWindow::on_bind_list_item(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto col = std::dynamic_pointer_cast<ModelColumns>(list_item->get_item());
  if (!col)
    return;
  auto hbox = dynamic_cast<Gtk::Box*>(list_item->get_child());
  if (!hbox)
    return;
  auto image = dynamic_cast<Gtk::Image*>(hbox->get_first_child());
  if (!image)
    return;
  image->set_from_icon_name(col->m_icon);
  auto vbox = dynamic_cast<Gtk::Box*>(image->get_next_sibling());
  if (!vbox)
    return;
  auto title = dynamic_cast<Gtk::Label*>(vbox->get_first_child());
  if (!title)
    return;
  title->set_text(col->m_title);
  auto description = dynamic_cast<Gtk::Label*>(title->get_next_sibling());
  if (!description)
    return;
  description->set_text(col->m_description);

  auto connection = m_DropDown.property_selected_item().signal_changed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::on_selected_item_changed),
    list_item));
  list_item->set_data("connection", new sigc::connection(connection),
    Glib::destroy_notify_delete<sigc::connection>);
  on_selected_item_changed(list_item);
}

void ExampleWindow::on_unbind_list_item(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  if (auto connection = static_cast<sigc::connection*>(list_item->get_data("connection")))
  {
    connection->disconnect();
    list_item->set_data("connection", nullptr);
  }
}

void ExampleWindow::on_selected_item_changed(const Glib::RefPtr<Gtk::ListItem>& list_item)
{
  auto hbox = dynamic_cast<Gtk::Box*>(list_item->get_child());
  if (!hbox)
    return;
  auto checkmark = dynamic_cast<Gtk::Image*>(hbox->get_last_child());
  if (!checkmark)
    return;
  checkmark->set_visible(m_DropDown.get_selected_item() == list_item->get_item());
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</chapter>

<chapter xml:id="chapter-combobox">
<title>Rozbalovací seznamy (ComboBox)</title>

<note><para xml:lang="en"><classname>Gtk::ComboBox</classname> and <classname>Gtk::ComboBoxText</classname>
are deprecated since <application>gtkmm</application> 4.10. Use <classname>Gtk::DropDown</classname> in new code.
</para></note>

<para xml:lang="en">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 check button, 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.
</para>

<para>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.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ComboBox.html">Reference</link></para>

<section xml:id="sec-combobox-model">
<title>Model</title>

<para>Model 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:</para>
<programlisting xml:lang="en"><code>class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
  ModelColumns()
  { 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;</code></programlisting>

<para>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>.</para>
</section>

<section xml:id="sec-combobox-get">
<title>Vybraná položka</title>

<para>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:</para>
<programlisting xml:lang="en"><code>Gtk::TreeModel::iterator iter = m_Combo.get_active();
if(iter)
{
  auto row = *iter;

  //Get the data for the selected row, using our knowledge
  //of the tree model:
  auto id = row[m_Columns.m_col_id];
  set_something_id_chosen(id); //Your own function.
}
else
  set_nothing_chosen(); //Your own function.</code></programlisting>
</section>

<section xml:id="sec-combobox-changes">
<title>Reagování na změny</title>

<para>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:</para>
<programlisting xml:lang="en"><code>m_combo.signal_changed().connect( sigc::mem_fun(*this,
      &amp;ExampleWindow::on_combo_changed) );</code></programlisting>
</section>

<section xml:id="combobox-example-full">
<title>Úplný příklad</title>

<figure xml:id="figure-combobox-complex">
  <title>ComboBox</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/combobox_complex.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/combobox/complex">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/liststore.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  void on_cell_data_extra(const Gtk::TreeModel::const_iterator& iter);

  //Signal handlers:
  void on_combo_changed();


  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); add(m_col_extra);}

    Gtk::TreeModelColumn<int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
    Gtk::TreeModelColumn<Glib::ustring> m_col_extra;
  };

  ModelColumns m_Columns;

  //Child widgets:
  Gtk::ComboBox m_Combo;
  Gtk::CellRendererText m_cell;
  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("ComboBox example");

  //Create the Tree model:
  //m_refTreeModel = Gtk::TreeStore::create(m_Columns);
  m_refTreeModel = Gtk::ListStore::create(m_Columns);
  m_Combo.set_model(m_refTreeModel);

  //Fill the ComboBox's Tree Model:
  auto iter = m_refTreeModel->append();
  auto row = *iter;
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "Billy Bob";
  row[m_Columns.m_col_extra] = "something";
  m_Combo.set_active(iter);
  /*
  auto childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 11;
  childrow[m_Columns.m_col_name] = "Billy Bob Junior";

  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 12;
  childrow[m_Columns.m_col_name] = "Sue Bob";
  */

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "Joey Jojo";
  row[m_Columns.m_col_extra] = "yadda";


  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "Rob McRoberts";
  row[m_Columns.m_col_extra] = "";

  /*
  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 31;
  childrow[m_Columns.m_col_name] = "Xavier McRoberts";
  */

  //Add the model columns to the Combo (which is a kind of view),
  //rendering them in the default way:
  m_Combo.pack_start(m_Columns.m_col_id);
  m_Combo.pack_start(m_Columns.m_col_name);

  //An example of adding a cell renderer manually,
  //instead of using pack_start(model_column, Gtk::PackOptions::EXPAND_WIDGET)
  //so we have more control:
  m_Combo.set_cell_data_func(m_cell,
    sigc::mem_fun(*this, &ExampleWindow::on_cell_data_extra));
  m_Combo.pack_start(m_cell);

  //Add the ComboBox to the window.
  set_child(m_Combo);

  //Connect signal handler:
  m_Combo.signal_changed().connect( sigc::mem_fun(*this, &ExampleWindow::on_combo_changed) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_cell_data_extra(const Gtk::TreeModel::const_iterator& iter)
{
  auto row = *iter;
  const Glib::ustring extra = row[m_Columns.m_col_extra];

  //Some arbitrary logic just to show that this is where you can do such things:

  //Transform the value, deciding how to represent it as text:
  if(extra.empty())
    m_cell.property_text() = "(none)";
  else
    m_cell.property_text() = "-" + extra + "-";

  //Change other cell renderer properties too:
  m_cell.property_foreground() = (extra == "yadda" ? "red" : "green");
}

void ExampleWindow::on_combo_changed()
{
  const auto iter = m_Combo.get_active();
  if(iter)
  {
    const auto row = *iter;
    if(row)
    {
      //Get the data for the selected row, using our knowledge of the tree
      //model:
      int id = row[m_Columns.m_col_id];
      Glib::ustring name = row[m_Columns.m_col_name];

      std::cout << " ID=" << id << ", name=" << name << std::endl;
    }
  }
  else
    std::cout << "invalid iter" << std::endl;
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="combobox-example-simple">
<title>Jednoduchý textový příklad</title>

<figure xml:id="figure-combobox-text">
  <title>Kombinované vstupní pole (ComboBoxText)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/combobox_text.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/combobox/text">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/comboboxtext.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_combo_changed();

  //Child widgets:
  Gtk::ComboBoxText m_Combo;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("ComboBoxText example");

  //Fill the combo:
  m_Combo.append("something");
  m_Combo.append("something else");
  m_Combo.append("something or other");
  m_Combo.set_active(1);

  set_child(m_Combo);

  //Connect signal handler:
  m_Combo.signal_changed().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_combo_changed) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_combo_changed()
{
  Glib::ustring text = m_Combo.get_active_text();
  if(!(text.empty()))
    std::cout << "Combo changed: " << text << std::endl;
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-comboboxentry">
<title>ComboBox se vstupním polem</title>

<para><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.</para>

<section xml:id="sec-comboboxentry-text-column">
<title>Textový sloupec</title>

<para xml:lang="en">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:
</para>
<programlisting xml:lang="en"><code>m_combo.set_entry_text_column(m_columns.m_col_name);</code></programlisting>
<para>Když vyberete položku z robalovací nabídky, umístí se hodnota z tohoto sloupce do <classname>Entry</classname>.</para>
</section>

<section xml:id="sec-comboboxentry-model">
<title>Vstupní pole</title>

<para>Protož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>.</para>
</section>

<section xml:id="sec-comboboxentry-changes">
<title>Reagování na změny</title>

<para xml:lang="en">
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 <keycap>Enter</keycap> key.
Pressing the <keycap>Enter</keycap> 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>
signal (available since <application>gtkmm</application> 4.8), and add a <classname>Gtk::EventControllerFocus</classname>
and connect to its <literal>leave</literal> signal, like so
</para>
<programlisting xml:lang="en"><code><![CDATA[auto entry = m_Combo.get_entry();
if (entry)
{
  // Alternatively you can connect to m_Combo.signal_changed().
  entry->signal_changed().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_entry_changed));
  entry->signal_activate().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_entry_activate));
  // The Entry shall receive focus-leave events.
  auto controller = Gtk::EventControllerFocus::create();
  m_ConnectionFocusLeave = controller->signal_leave().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_entry_focus_leave));
  entry->add_controller(controller);
}]]></code></programlisting>
<para xml:lang="en">
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 the <classname>EventControllerFocus</classname>
must be added to the <classname>Entry</classname>.
</para>
</section>

<section xml:id="comboboxentry-example-full">
<title>Úplný příklad</title>

<figure xml:id="figure-comboboxentry-complex">
  <title>Rozbalovací seznam (ComboBox) se vstupním polem (Entry)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/comboboxentry_complex.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/combobox/entry_complex">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/combobox.h>
#include <gtkmm/liststore.h>
#include <gtkmm/version.h>

#define HAS_SIGNAL_ACTIVATE GTKMM_CHECK_VERSION(4,7,1)

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_entry_changed();
#if HAS_SIGNAL_ACTIVATE
  void on_entry_activate();
#endif
  void on_entry_focus_leave();

  //Signal connection:
  sigc::connection m_ConnectionFocusLeave;

  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); }

    Gtk::TreeModelColumn<Glib::ustring> m_col_id; //The data to choose - this must be text.
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
  };

  ModelColumns m_Columns;

  //Child widgets:
  Gtk::ComboBox m_Combo;
  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/eventcontrollerfocus.h>
#include <iostream>

ExampleWindow::ExampleWindow()
: m_Combo(true /* has_entry */)
{
  set_title("ComboBox example");

  //Create the Tree model:
  //m_refTreeModel = Gtk::TreeStore::create(m_Columns);
  m_refTreeModel = Gtk::ListStore::create(m_Columns);
  m_Combo.set_model(m_refTreeModel);

  //Fill the ComboBox's Tree Model:
  auto row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = "1";
  row[m_Columns.m_col_name] = "Billy Bob";
  /*
  auto childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 11;
  childrow[m_Columns.m_col_name] = "Billy Bob Junior";

  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 12;
  childrow[m_Columns.m_col_name] = "Sue Bob";
  */

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = "2";
  row[m_Columns.m_col_name] = "Joey Jojo";

  row = *(m_refTreeModel->append());
  row[m_Columns.m_col_id] = "3";
  row[m_Columns.m_col_name] = "Rob McRoberts";

  /*
  childrow = *(m_refTreeModel->append(row.children()));
  childrow[m_Columns.m_col_id] = 31;
  childrow[m_Columns.m_col_name] = "Xavier McRoberts";
  */

  //Add the model columns to the Combo (which is a kind of view),
  //rendering them in the default way:
  //This is automatically rendered when we use set_entry_text_column().
  //m_Combo.pack_start(m_Columns.m_col_id, Gtk::PackOptions::EXPAND_WIDGET);
  m_Combo.pack_start(m_Columns.m_col_name);

  m_Combo.set_entry_text_column(m_Columns.m_col_id);
  m_Combo.set_active(1);

  //Add the ComboBox to the window.
  set_child(m_Combo);

  //Connect signal handlers:
  auto entry = m_Combo.get_entry();
  if (entry)
  {
    // Alternatively you can connect to m_Combo.signal_changed().
    entry->signal_changed().connect(sigc::mem_fun(*this,
      &ExampleWindow::on_entry_changed));
#if HAS_SIGNAL_ACTIVATE
    entry->signal_activate().connect(sigc::mem_fun(*this,
      &ExampleWindow::on_entry_activate));
#endif
    // The Entry shall receive focus-leave events.
    auto controller = Gtk::EventControllerFocus::create();
    m_ConnectionFocusLeave = controller->signal_leave().connect(
      sigc::mem_fun(*this, &ExampleWindow::on_entry_focus_leave));
    entry->add_controller(controller);
  }
  else
    std::cout << "No Entry ???" << std::endl;
}

ExampleWindow::~ExampleWindow()
{
  // The focus-leave signal may be emitted while m_Combo is being destructed.
  // The signal handler can generate critical messages, if it's called when
  // m_Combo has been partly destructed.
  m_ConnectionFocusLeave.disconnect();
}

void ExampleWindow::on_entry_changed()
{
  auto entry = m_Combo.get_entry();
  if (entry)
  {
    std::cout << "on_entry_changed(): Row=" << m_Combo.get_active_row_number()
      << ", ID=" << entry->get_text() << std::endl;
  }
}

#if HAS_SIGNAL_ACTIVATE
void ExampleWindow::on_entry_activate()
{
  auto entry = m_Combo.get_entry();
  if (entry)
  {
    std::cout << "on_entry_activate(): Row=" << m_Combo.get_active_row_number()
      << ", ID=" << entry->get_text() << std::endl;
  }
}
#endif

void ExampleWindow::on_entry_focus_leave()
{
  auto entry = m_Combo.get_entry();
  if (entry)
  {
    std::cout << "on_entry_focus_leave(): Row=" << m_Combo.get_active_row_number()
      << ", ID=" << entry->get_text() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="comboboxentry-example-simple">
<title>Jednoduchý textový příklad</title>

<figure xml:id="figure-comboboxentry-text">
  <title>Textový rozbalovací seznam (ComboBoxText) se vstupním polem (Entry)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/comboboxentry_text.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/combobox/entry_text">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/version.h>

#define HAS_SIGNAL_ACTIVATE GTKMM_CHECK_VERSION(4,7,1)

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_combo_changed();
#if HAS_SIGNAL_ACTIVATE
  void on_entry_activate();
#endif
  void on_entry_focus_leave();

  //Signal connection:
  sigc::connection m_ConnectionFocusLeave;

  //Child widgets:
  Gtk::ComboBoxText m_Combo;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/eventcontrollerfocus.h>
#include <iostream>

ExampleWindow::ExampleWindow()
: m_Combo(true /* has_entry */)
{
  set_title("ComboBoxText example");

  //Fill the combo:
  m_Combo.append("something");
  m_Combo.append("something else");
  m_Combo.append("something or other");
  m_Combo.set_active(0);

  set_child(m_Combo);

  //Connect signal handlers:
  auto entry = m_Combo.get_entry();
  // Alternatively you can connect to entry->signal_changed().
  m_Combo.signal_changed().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_combo_changed) );

  if (entry)
  {
#if HAS_SIGNAL_ACTIVATE
    entry->signal_activate().connect(sigc::mem_fun(*this,
      &ExampleWindow::on_entry_activate));
#endif
    // The Entry shall receive focus-leave events.
    auto controller = Gtk::EventControllerFocus::create();
    m_ConnectionFocusLeave = controller->signal_leave().connect(
      sigc::mem_fun(*this, &ExampleWindow::on_entry_focus_leave));
    entry->add_controller(controller);
  }
  else
    std::cout << "No Entry ???" << std::endl;

  m_Combo.property_has_frame() = false;
}

ExampleWindow::~ExampleWindow()
{
  // The focus-leave signal may be emitted while m_Combo is being destructed.
  // The signal handler can generate critical messages, if it's called when
  // m_Combo has been partly destructed.
  m_ConnectionFocusLeave.disconnect();
}

void ExampleWindow::on_combo_changed()
{
  std::cout << "on_combo_changed(): Row=" << m_Combo.get_active_row_number()
    << ", Text=" << m_Combo.get_active_text() << std::endl;
}

#if HAS_SIGNAL_ACTIVATE
void ExampleWindow::on_entry_activate()
{
  std::cout << "on_entry_activate(): Row=" << m_Combo.get_active_row_number()
    << ", Text=" << m_Combo.get_active_text() << std::endl;
}
#endif

void ExampleWindow::on_entry_focus_leave()
{
  std::cout << "on_entry_focus_leave(): Row=" << m_Combo.get_active_row_number()
    << ", Text=" << m_Combo.get_active_text() << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>

</chapter>

<chapter xml:id="chapter-textview">
<title>Zobrazení textu (TextView)</title>

<para>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>.</para>

<section xml:id="sec-textview-buffer">
<title>Vyrovnávací paměť</title>

<para><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>.</para>
<para><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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextBuffer.html">Reference</link></para>

<section xml:id="textview-iterators">
<title>Iterátory</title>

<para xml:lang="en">
A <classname>Gtk::TextBuffer::iterator</classname> and a <classname>Gtk::TextBuffer::const_iterator</classname>
represent a position between two characters in the text buffer. Whenever the buffer
is modified in a way that affects the number of characters in the buffer, all outstanding
iterators become invalid. Because of this, iterators can't be used to preserve positions
across buffer modifications. To preserve a position, use <classname>Gtk::TextBuffer::Mark</classname>.
</para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextIter.html">Reference</link></para>
</section>

<section xml:id="textview-formatting">
<title>Formátovací značky a formátování</title>

<section xml:id="textview-formatting-tags">
<title>Formátovací značky (Tag)</title>

<para>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í:</para>
<programlisting xml:lang="en"><code>auto refTagMatch = Gtk::TextBuffer::Tag::create();
refTagMatch-&gt;property_background() = "orange";</code></programlisting>
<para>Při použití metody <methodname>create()</methodname> můžete určit pro objekt <classname>Tag</classname> název, ale není to nutné.</para>

<para>Třída <classname>Tag</classname> má mnoho dalších vlastností.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextTag.html">Reference</link></para>

</section>

<section xml:id="textview-formatting-tagtable">
<title>Tabulka formátovacích značek (TagTable)</title>

<para>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:</para>
<programlisting xml:lang="en"><code>auto refTagTable = Gtk::TextBuffer::TagTable::create();
refTagTable-&gt;add(refTagMatch);
//Hopefully a future version of gtkmm will have a set_tag_table() method,
//for use after creation of the buffer.
auto refBuffer = Gtk::TextBuffer::create(refTagTable);</code></programlisting>

<para>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.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextTagTable.html">Reference</link></para>

</section>

<section xml:id="textview-formatting-applying-tags">
<title>Použití formátovacích značek</title>

<para>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:</para>
<programlisting xml:lang="en"><code>refBuffer-&gt;apply_tag(refTagMatch, iterRangeStart, iterRangeStop);</code></programlisting>
<para xml:lang="en">
Or you could specify the tag when first inserting the text:
</para>
<programlisting xml:lang="en"><code>refBuffer-&gt;insert_with_tag(iter, "Some text", refTagMatch);</code></programlisting>

<para>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>.</para>

</section>
</section>

<section xml:id="textview-marks">
<title>Poziční značky (Mark)</title>

<para>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:</para>
<programlisting xml:lang="en"><code>auto refMark = refBuffer-&gt;create_mark(iter);</code></programlisting>

<para>Později můžete použít metodu <methodname>get_iter()</methodname> k vytvoření iterátoru pro novou pozici v objektu <classname>Mark</classname>.</para>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextMark.html">Reference</link></para>

</section>

<section xml:id="textview-view">
<title>Zobrazení (View)</title>

<para>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>.</para>

<para>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ů.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextView.html">Reference</link></para>

<section xml:id="textview-default-formatting">
<title>Výchozí formátování</title>

<para><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.</para>
</section>

<section xml:id="textview-scrolling">
<title>Posouvání</title>

<para xml:lang="en">
<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()</methodname> to
show the found text.
</para>
</section>

</section>


</section>

<section xml:id="sec-widgets-and-childanchors">
<title>Widgety a kotvy potomků (ChildAnchors)</title>

<para xml:lang="en">
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>iterator</classname>s. For
instance, to create a child anchor at a particular position, use
<methodname>Gtk::TextBuffer::create_child_anchor()</methodname>:
</para>
<programlisting xml:lang="en"><code>auto refAnchor = refBuffer-&gt;create_child_anchor(iter);</code></programlisting>

<para>Pro přidání widgetu na tuto pozici použijte <methodname>Gtk::TextView::add_child_at_anchor()</methodname>:</para>
<programlisting xml:lang="en"><code>m_TextView.add_child_at_anchor(m_Button, refAnchor);</code></programlisting>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1TextChildAnchor.html">Reference</link></para>

</section>

<section xml:id="sec-textview-examples">
<title>Příklady</title>

<section xml:id="textview-example-simple">
<title>Jednoduchý příklad</title>

<figure xml:id="figure-textview">
  <title>Zobrazení textu (TextView)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/textview.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/textview/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  void fill_buffers();

  //Signal handlers:
  void on_button_quit();
  void on_button_buffer1();
  void on_button_buffer2();

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TextView m_TextView;

  Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer1, m_refTextBuffer2;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit, m_Button_Buffer1, m_Button_Buffer2;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Quit("_Quit", true),
  m_Button_Buffer1("Use buffer 1"),
  m_Button_Buffer2("Use buffer 2")
{
  set_title("Gtk::TextView example");
  set_default_size(400, 200);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.set_child(m_TextView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);

  //append buttons:
  m_VBox.append(m_ButtonBox);

  m_Button_Buffer1.set_hexpand(true);
  m_Button_Buffer1.set_halign(Gtk::Align::END);
  m_ButtonBox.append(m_Button_Buffer1);
  m_ButtonBox.append(m_Button_Buffer2);
  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(5);
  m_ButtonBox.set_spacing(5);

  //Connect signals:
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );
  m_Button_Buffer1.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_buffer1) );
  m_Button_Buffer2.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_buffer2) );

  fill_buffers();
  on_button_buffer1();
}

void ExampleWindow::fill_buffers()
{
  m_refTextBuffer1 = Gtk::TextBuffer::create();
  m_refTextBuffer1->set_text("This is the text from TextBuffer #1.");

  m_refTextBuffer2 = Gtk::TextBuffer::create();
  m_refTextBuffer2->set_text(
          "This is some alternative text, from TextBuffer #2.");

}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_button_buffer1()
{
  m_TextView.set_buffer(m_refTextBuffer1);
}

void ExampleWindow::on_button_buffer2()
{
  m_TextView.set_buffer(m_refTextBuffer2);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-menus-and-toolbars">
<title>Nabídky a nástrojové lišty</title>

<para xml:lang="en">
There are specific APIs for menus and toolbars, but you should usually deal
with them together, creating <classname>Gio::SimpleAction</classname>s that
you can refer to in both 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. <classname>Gtk::Builder</classname> can create menus and toolbars.
</para>
<para xml:lang="en">
This involves the use of the <classname>Gio::SimpleActionGroup</classname>,
<classname>Gio::SimpleAction</classname> and <classname>Gtk::Builder</classname>
classes, all of which should be instantiated via their <methodname>create()</methodname>
methods, which return <classname>RefPtr</classname>s.
</para>

<section xml:id="sec-actions">
<title>Akce</title>

<para xml:lang="en">
First create the <classname>Gio::SimpleAction</classname>s and add them to a
<classname>Gio::SimpleActionGroup</classname>, with
<methodname>Gio::ActionMap::add_action()</methodname>.
(<classname>Gio::ActionMap</classname> is a base class of
<classname>Gio::SimpleActionGroup</classname>.) Then add the action group to
your window with <methodname>Gtk::Widget::insert_action_group()</methodname>.
</para>
<para xml:lang="en">
The arguments to <methodname>add_action()</methodname> specify the action's
name, which is used in the menu items and toolbar buttons. You can also specify
a signal handler when calling <methodname>add_action()</methodname>. This signal
handler will be called when the action is activated via either a menu item or
a toolbar button.
</para>

<para>Například:</para>
<programlisting xml:lang="en"><code>m_refActionGroup = Gio::SimpleActionGroup::create();

m_refActionGroup-&gt;add_action("new", sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_new));
m_refActionGroup-&gt;add_action("open", sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_open));
m_refActionGroup-&gt;add_action("quit", sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_quit));

insert_action_group("example", m_refActionGroup);
</code></programlisting>

<para xml:lang="en">
If you use an <classname>Gtk::ApplicationWindow</classname>, you don't have to
create your own action group. <classname>Gio::ActionGroup</classname> and
<classname>Gio::ActionMap</classname> are base classes of
<classname>Gtk::ApplicationWindow</classname>.
</para>

</section>


<section xml:id="sec-menubar-and-toolbar">
<title xml:lang="en">Menubar and Toolbar</title>

<para xml:lang="en">
Next you should create a <classname>Gtk::Builder</classname>. At this point is
also a good idea to tell the application to respond to keyboard shortcuts,
by using <methodname>Gtk::Application::set_accel_for_action()</methodname>.
</para>

<para>Například</para>
<programlisting xml:lang="en"><code>m_refBuilder = Gtk::Builder::create();

app-&gt;set_accel_for_action("example.new", "&lt;Primary&gt;n");
app-&gt;set_accel_for_action("example.quit", "&lt;Primary&gt;q");
app-&gt;set_accel_for_action("example.copy", "&lt;Primary&gt;c");
app-&gt;set_accel_for_action("example.paste", "&lt;Primary&gt;v");
</code></programlisting>

<!-- Not true in gtkmm4 (July 2022). Will it become true in the future?
<para>
If your main window is derived from <classname>ApplicationWindow</classname> and
you instantiate your menubar with <methodname>Gtk::Application::set_menubar()</methodname>,
then you don't have to call <methodname>set_accel_for_action()</methodname>.
See <link linkend="menu-example-main">Application Menu and Main Menu example</link>
for an example.
</para>
-->

<para xml:lang="en">
Then, you can define the actual visible layout of the menus and toolbars, and
add the UI layout to the <classname>Builder</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:
</para>
<programlisting xml:lang="en"><code>Glib::ustring ui_info =
  "&lt;interface&gt;"
  "  &lt;menu id='menubar'&gt;"
  "    &lt;submenu&gt;"
  "      &lt;attribute name='label' translatable='yes'&gt;_File&lt;/attribute&gt;"
  "      &lt;section&gt;"
  "        &lt;item&gt;"
  "          &lt;attribute name='label' translatable='yes'&gt;_New&lt;/attribute&gt;"
  "          &lt;attribute name='action'&gt;example.new&lt;/attribute&gt;"
  "        &lt;/item&gt;"
  "      &lt;/section&gt;"
  "      &lt;section&gt;"
  "        &lt;item&gt;"
  "          &lt;attribute name='label' translatable='yes'&gt;_Quit&lt;/attribute&gt;"
  "          &lt;attribute name='action'&gt;example.quit&lt;/attribute&gt;"
  "        &lt;/item&gt;"
  "      &lt;/section&gt;"
  "    &lt;/submenu&gt;"
  "    &lt;submenu&gt;"
  "      &lt;attribute name='label' translatable='yes'&gt;_Edit&lt;/attribute&gt;"
  "      &lt;item&gt;"
  "        &lt;attribute name='label' translatable='yes'&gt;_Copy&lt;/attribute&gt;"
  "        &lt;attribute name='action'&gt;example.copy&lt;/attribute&gt;"
  "      &lt;/item&gt;"
  "      &lt;item&gt;"
  "        &lt;attribute name='label' translatable='yes'&gt;_Paste&lt;/attribute&gt;"
  "        &lt;attribute name='action'&gt;example.paste&lt;/attribute&gt;"
  "      &lt;/item&gt;"
  "    &lt;/submenu&gt;"
  "  &lt;/menu&gt;"
  "&lt;/interface&gt;";

m_refBuilder-&gt;add_from_string(ui_info);
m_refBuilder-&gt;add_from_resource("/toolbar/toolbar.ui");
</code></programlisting>

<para xml:lang="en">This is where we specify the names of the menu items as they will be seen
by users in the menu. Therefore, this is where you should make strings
translatable, by adding <literal>translatable='yes'</literal>.
</para>
<para xml:lang="en">
To instantiate a <classname>Gtk::PopoverMenuBar</classname> and toolbar (a horizontal
<classname>Gtk::Box</classname>) which you can actually show, you should use
the <methodname>Builder::get_object()</methodname> and
<methodname>Builder::get_widget()</methodname> methods, and then add the widgets
to a container. For instance:
</para>
<programlisting xml:lang="en"><code>auto gmenu = m_refBuilder-&gt;get_object&lt;Gio::Menu&gt;("menubar");
auto pMenuBar = Gtk::make_managed&lt;Gtk::PopoverMenuBar&gt;(gmenu);
m_Box.append(*pMenuBar);

auto toolbar = m_refBuilder-&gt;get_widget&lt;Gtk::Box&gt;("toolbar");
m_Box.append(*toolbar);
</code></programlisting>

</section>


<section xml:id="sec-menus-popup">
<title>Vyskakovací nabídky</title>
<para xml:lang="en">
<classname>Menu</classname>s 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.
</para>

<para>Například:</para>
<programlisting xml:lang="en"><code>Glib::ustring ui_info =
  "&lt;interface&gt;"
  "  &lt;menu id='menu-examplepopup'&gt;"
  "    &lt;section&gt;"
  "      &lt;item&gt;"
  "        &lt;attribute name='label' translatable='yes'&gt;Edit&lt;/attribute&gt;"
  "        &lt;attribute name='action'&gt;examplepopup.edit&lt;/attribute&gt;"
  "      &lt;/item&gt;"
  "      &lt;item&gt;"
  "        &lt;attribute name='label' translatable='yes'&gt;Process&lt;/attribute&gt;"
  "        &lt;attribute name='action'&gt;examplepopup.process&lt;/attribute&gt;"
  "      &lt;/item&gt;"
  "      &lt;item&gt;"
  "        &lt;attribute name='label' translatable='yes'&gt;Remove&lt;/attribute&gt;"
  "        &lt;attribute name='action'&gt;examplepopup.remove&lt;/attribute&gt;"
  "      &lt;/item&gt;"
  "    &lt;/section&gt;"
  "  &lt;/menu&gt;"
  "&lt;/interface&gt;";

m_refBuilder-&gt;add_from_string(ui_info);

auto gmenu = m_refBuilder-&gt;get_object&lt;Gio::Menu&gt;("menu-examplepopup");
m_MenuPopup.set_menu_model(gmenu);
</code></programlisting>

<para xml:lang="en">
To show the popup menu, use  a <classname>Gtk::GestureClick</classname>
and connect to its <literal>pressed</literal> signal. In the signal handler,
use <classname>Gtk::PopoverMenu</classname>'s
<methodname>popup()</methodname> method. For instance:
</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_label_pressed(int /* n_press */, double x, double y)
{
  const Gdk::Rectangle rect(x, y, 1, 1);
  m_MenuPopup.set_pointing_to(rect);
  m_MenuPopup.popup();
}</code></programlisting>

</section>

<section xml:id="sec-gio-resource">
<title xml:lang="en">Gio::Resource and glib-compile-resources</title>

<para xml:lang="en">
Applications and libraries often contain binary or textual data that is
really part of the application, rather than user data. For instance
<classname>Gtk::Builder</classname> <filename class="extension">.ui</filename> files,
splashscreen images, <classname>Gio::Menu</classname> markup xml, CSS files,
icons, etc. These are often shipped as files in <filename class="directory">$datadir/appname</filename>,
or manually included as literal strings in the code.
</para>
<para xml:lang="en">
The <classname>Gio::Resource</classname> API and the <application>glib-compile-resources</application>
program provide a convenient and efficient alternative to this, which has some nice properties. You
maintain the files as normal files, so it's easy to edit them, but during the build the files
are combined into a binary bundle that is linked into the executable. This means that loading
the resource files is efficient (as they are already in memory, shared with other instances) and
simple (no need to check for things like I/O errors or locate the files in the filesystem). It
also makes it easier to create relocatable applications.
</para>
<!-- TODO: Add a link to the description of glib-compile-resources, if it will
be described at https://docs.gtk.org/gio/glib-compile-resources.html or elsewhere.
-->
<para xml:lang="en">
Resource bundles are created by the <application>glib-compile-resources</application>
program which takes an xml file that describes the bundle, and a set of files that the xml references.
These are combined into a binary resource bundle.
</para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1Resource.html">Gio::Resource Reference</link></para>
<para xml:lang="en">An example:</para>
<programlisting xml:lang="en"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;gresources&gt;
  &lt;gresource prefix="/toolbar"&gt;
    &lt;file preprocess="xml-stripblanks"&gt;toolbar.ui&lt;/file&gt;
    &lt;file&gt;rain.png&lt;/file&gt;
  &lt;/gresource&gt;
&lt;/gresources&gt;
</code></programlisting>
<para xml:lang="en">This will create a resource bundle with the files
<itemizedlist>
  <listitem><para xml:lang="en"><filename>/toolbar/toolbar.ui</filename></para></listitem>
  <listitem><para xml:lang="en"><filename>/toolbar/rain.png</filename></para></listitem>
</itemizedlist>
</para>
<para xml:lang="en">
You can then use <application>glib-compile-resources</application> to compile the xml to a binary bundle
that you can load with <methodname>Gio::Resource::create_from_file()</methodname>.
However, it's more common to use the <parameter class="command">--generate-source</parameter>
argument to create a C source file to link directly into your application. E.g.
<screen xml:lang="en">$ glib-compile-resources --target=resources.c --generate-source toolbar.gresource.xml</screen>
</para>
<para xml:lang="en">
Once a <classname>Gio::Resource</classname> has been created and registered all the data
in it can be accessed globally in the process by using API calls like
<methodname>Gio::Resource::open_stream_from_global_resources()</methodname>
to stream the data or <methodname>Gio::Resource::lookup_data_in_global_resources()</methodname>
to get a direct pointer to the data. You can also use URIs like <uri>resource:///toolbar/rain.png</uri>
with <classname>Gio::File</classname> to access the resource data.
</para>
<para xml:lang="en">
Often you don't need a <classname>Gio::Resource</classname> instance,
because resource data can be loaded with methods such as
<methodname>Gdk::Pixbuf::create_from_resource()</methodname>,
<methodname>Gtk::Builder::add_from_resource()</methodname> and
<methodname>Gtk::Image::set_from_resource()</methodname>.
</para>

</section>

<section xml:id="sec-menus-examples">
<title>Příklady</title>

<section xml:id="menu-example-main">
<title xml:lang="en">Application Menu and Main Menu example</title>
<para xml:lang="en">
This program contains an application menu, a menubar and a toolbar.
Classes are derived from <classname>Gtk::Application</classname> and
<classname>Gtk::ApplicationWindow</classname>.
</para>

<figure xml:id="figure-menus-mainmenu">
  <title xml:lang="en">App and Main Menu</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/main_menu.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/menus/main_menu/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPLICATION_H
#define GTKMM_EXAMPLEAPPLICATION_H

#include <gtkmm.h>

class ExampleApplication : public Gtk::Application
{
protected:
  ExampleApplication();

public:
  static Glib::RefPtr<ExampleApplication> create();

protected:
  //Overrides of default signal handlers:
  void on_startup() override;
  void on_activate() override;

private:
  void create_window();

  void on_menu_file_new_generic();
  void on_menu_file_quit();
  void on_menu_help_about();

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
};

#endif /* GTKMM_EXAMPLEAPPLICATION_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::ApplicationWindow
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_menu_others();

  void on_menu_choices(const Glib::ustring& parameter);
  void on_menu_choices_other(int parameter);
  void on_menu_toggle();

  //Child widgets:
  Gtk::Box m_Box;

  Glib::RefPtr<Gtk::Builder> m_refBuilder;

  //Two sets of choices:
  Glib::RefPtr<Gio::SimpleAction> m_refChoice;
  Glib::RefPtr<Gio::SimpleAction> m_refChoiceOther;

  Glib::RefPtr<Gio::SimpleAction> m_refToggle;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"
#include "examplewindow.h"
#include <iostream>

ExampleApplication::ExampleApplication()
: Gtk::Application("org.gtkmm.example.main_menu")
{
  Glib::set_application_name("Main Menu Example");
}

Glib::RefPtr<ExampleApplication> ExampleApplication::create()
{
  return Glib::make_refptr_for_instance<ExampleApplication>(new ExampleApplication());
}

void ExampleApplication::on_startup()
{
  //Call the base class's implementation:
  Gtk::Application::on_startup();

  //Create actions for menus and toolbars.
  //We can use add_action() because Gtk::Application derives from Gio::ActionMap.

  //File|New sub menu:
  add_action("newstandard",
    sigc::mem_fun(*this, &ExampleApplication::on_menu_file_new_generic));

  add_action("newfoo",
    sigc::mem_fun(*this, &ExampleApplication::on_menu_file_new_generic));

  add_action("newgoo",
    sigc::mem_fun(*this, &ExampleApplication::on_menu_file_new_generic));

  //File menu:
  add_action("quit", sigc::mem_fun(*this, &ExampleApplication::on_menu_file_quit));

  //Help menu:
  add_action("about", sigc::mem_fun(*this, &ExampleApplication::on_menu_help_about));

  // Set accelerator keys:
  set_accel_for_action("app.newstandard", "<Primary>n");
  set_accel_for_action("app.quit", "<Primary>q");
  set_accel_for_action("win.copy", "<Primary>c");
  set_accel_for_action("win.paste", "<Primary>v");

  m_refBuilder = Gtk::Builder::create();

  //Layout the actions in a menubar and a menu:
  Glib::ustring ui_info =
    "<interface>"
    "  <!-- menubar -->"
    "  <menu id='menu-example'>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_File</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>New _Standard</attribute>"
    "          <attribute name='action'>app.newstandard</attribute>"
    "          <attribute name='accel'>&lt;Primary&gt;n</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>New _Foo</attribute>"
    "          <attribute name='action'>app.newfoo</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>New _Goo</attribute>"
    "          <attribute name='action'>app.newgoo</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Quit</attribute>"
    "          <attribute name='action'>app.quit</attribute>"
    "          <attribute name='accel'>&lt;Primary&gt;q</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_Edit</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Copy</attribute>"
    "          <attribute name='action'>win.copy</attribute>"
    "          <attribute name='accel'>&lt;Primary&gt;c</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Paste</attribute>"
    "          <attribute name='action'>win.paste</attribute>"
    "          <attribute name='accel'>&lt;Primary&gt;v</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Something</attribute>"
    "          <attribute name='action'>win.something</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_Choices</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Choice _A</attribute>"
    "          <attribute name='action'>win.choice</attribute>"
    "          <attribute name='target'>a</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Choice _B</attribute>"
    "          <attribute name='action'>win.choice</attribute>"
    "          <attribute name='target'>b</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_Other Choices</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Choice 1</attribute>"
    "          <attribute name='action'>win.choiceother</attribute>"
    "          <attribute name='target' type='i'>1</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Choice 2</attribute>"
    "          <attribute name='action'>win.choiceother</attribute>"
    "          <attribute name='target' type='i'>2</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Some Toggle</attribute>"
    "          <attribute name='action'>win.sometoggle</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_Help</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_About Window</attribute>"
    "          <attribute name='action'>win.about</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_About App</attribute>"
    "          <attribute name='action'>app.about</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "  </menu>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_info);
  }
  catch (const Glib::Error& ex)
  {
    std::cerr << "Building menus failed: " << ex.what();
  }

  //Get the menubar and the app menu, and add them to the application:
  auto gmenu = m_refBuilder->get_object<Gio::Menu>("menu-example");
  if (!gmenu)
  {
    g_warning("GMenu not found");
  }
  else
  {
    set_menubar(gmenu);
  }
}

void ExampleApplication::on_activate()
{
  //std::cout << "debug1: " << G_STRFUNC << std::endl;
  // The application has been started, so let's show a window.
  // A real application might want to reuse this window in on_open(),
  // when asked to open a file, if no changes have been made yet.
  create_window();
}

void ExampleApplication::create_window()
{
  auto win = new ExampleWindow();

  //Make sure that the application runs for as long this window is still open:
  add_window(*win);

  //Delete the window when it is hidden.
  //That's enough for this simple example.
  win->signal_hide().connect([win]() { delete win; });

  win->set_show_menubar();
  win->set_visible(true);
}

void ExampleApplication::on_menu_file_new_generic()
{
  std::cout << "A File|New menu item was selected." << std::endl;
}

void ExampleApplication::on_menu_file_quit()
{
  std::cout << G_STRFUNC << std::endl;
  quit(); // Not really necessary, when Gtk::Widget::set_visible(false) is called.

  // Gio::Application::quit() will make Gio::Application::run() return,
  // but it's a crude way of ending the program. The window is not removed
  // from the application. Neither the window's nor the application's
  // destructors will be called, because there will be remaining reference
  // counts in both of them. If we want the destructors to be called, we
  // must remove the window from the application. One way of doing this
  // is to hide the window.
  std::vector<Gtk::Window*> windows = get_windows();
  if (windows.size() > 0)
    windows[0]->set_visible(false); // In this simple case, we know there is only one window.
}

void ExampleApplication::on_menu_help_about()
{
  std::cout << "Help|About App was selected." << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: Gtk::ApplicationWindow(),
  m_Box(Gtk::Orientation::VERTICAL)
{
  set_title("Main menu example");
  set_default_size(300, 100);

  // ExampleApplication displays the menubar. Other stuff, such as a toolbar,
  // is put into the box.
  set_child(m_Box);

  // Create actions for menus and toolbars.
  // We can use add_action() because Gtk::ApplicationWindow derives from Gio::ActionMap.
  // This Action Map uses a "win." prefix for the actions.
  // Therefore, for instance, "win.copy", is used in ExampleApplication::on_startup()
  // to layout the menu.

  //Edit menu:
  add_action("copy", sigc::mem_fun(*this, &ExampleWindow::on_menu_others));
  add_action("paste", sigc::mem_fun(*this, &ExampleWindow::on_menu_others));
  add_action("something", sigc::mem_fun(*this, &ExampleWindow::on_menu_others));

  //Choices menus, to demonstrate Radio items,
  //using our convenience methods for string and int radio values:
  m_refChoice = add_action_radio_string("choice",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_choices), "a");

  m_refChoiceOther = add_action_radio_integer("choiceother",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_choices_other), 1);

  m_refToggle = add_action_bool("sometoggle",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_toggle), false);

  //Help menu:
  add_action("about", sigc::mem_fun(*this, &ExampleWindow::on_menu_others));

  //Create the toolbar and add it to a container widget:

  m_refBuilder = Gtk::Builder::create();

  Glib::ustring ui_info =
    "<!-- Generated with glade 3.18.3 and then changed manually -->"
    "<interface>"
    "  <object class='GtkBox' id='toolbar'>"
    "    <property name='can_focus'>False</property>"
    "    <child>"
    "      <object class='GtkButton' id='toolbutton_new'>"
    "        <property name='can_focus'>False</property>"
    "        <property name='tooltip_text' translatable='yes'>New Standard</property>"
    "        <property name='action_name'>app.newstandard</property>"
    "        <property name='icon_name'>document-new</property>"
    "        <property name='hexpand'>False</property>"
    "        <property name='vexpand'>False</property>"
    "      </object>"
    "    </child>"
    "    <child>"
    "      <object class='GtkButton' id='toolbutton_quit'>"
    "        <property name='can_focus'>False</property>"
    "        <property name='tooltip_text' translatable='yes'>Quit</property>"
    "        <property name='action_name'>app.quit</property>"
    "        <property name='icon_name'>application-exit</property>"
    "        <property name='hexpand'>False</property>"
    "        <property name='vexpand'>False</property>"
    "      </object>"
    "    </child>"
    "  </object>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_info);
  }
  catch (const Glib::Error& ex)
  {
    std::cerr << "Building toolbar failed: " <<  ex.what();
  }

  auto toolbar = m_refBuilder->get_widget<Gtk::Box>("toolbar");
  if (!toolbar)
    g_warning("toolbar not found");
  else
    m_Box.append(*toolbar);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_menu_others()
{
  std::cout << "A menu item was selected." << std::endl;
}

void ExampleWindow::on_menu_choices(const Glib::ustring& parameter)
{
  //The radio action's state does not change automatically:
  m_refChoice->change_state(parameter);

  Glib::ustring message;
  if (parameter == "a")
    message = "Choice a was selected.";
  else
    message = "Choice b was selected.";

  std::cout << message << std::endl;
}

void ExampleWindow::on_menu_choices_other(int parameter)
{
  //The radio action's state does not change automatically:
  m_refChoiceOther->change_state(parameter);

  Glib::ustring message;
  if (parameter == 1)
    message = "Choice 1 was selected.";
  else
    message = "Choice 2 was selected.";

  std::cout << message << std::endl;
}

void ExampleWindow::on_menu_toggle()
{
  bool active = false;
  m_refToggle->get_state(active);

  //The toggle action's state does not change automatically:
  active = !active;
  m_refToggle->change_state(active);

  Glib::ustring message;
  if (active)
    message = "Toggle is active.";
  else
    message = "Toggle is not active.";

  std::cout << message << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"

int main(int argc, char* argv[])
{
  auto application = ExampleApplication::create();

  // Start the application, showing the initial window,
  // and opening extra windows for any files that it is asked to open,
  // for instance as a command-line parameter.
  // run() will return when the last window has been closed by the user.
  const int status = application->run(argc, argv);
  return status;
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="menu-example-main2">
<title>Příklad hlavní nabídky</title>
<para xml:lang="en">
This program contains a menubar and a toolbar.
A class is derived from <classname>Gtk::Window</classname>.
</para>

<figure xml:id="figure-menus-mainmenu2">
  <title>Hlavní nabídka</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/menus_and_toolbars.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/menus_and_toolbars">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow(const Glib::RefPtr<Gtk::Application>& app);
  virtual ~ExampleWindow();

private:
  //Signal handlers:
  //void on_action_file_new();
  void on_action_file_quit();
  void on_action_others();
  void on_action_toggle();

  //Child widgets:
  Gtk::Box m_Box;

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup;
  Glib::RefPtr<Gio::SimpleAction> m_refActionRain;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm.h>
#include <iostream>

ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
: m_Box(Gtk::Orientation::VERTICAL)
{
  set_title("main_menu example");
  set_default_size(200, 200);

  set_child(m_Box); //We can put a MenuBar at the top of the box and other stuff below it.

  //Define the actions:
  m_refActionGroup = Gio::SimpleActionGroup::create();

  // There are several ways of calling a function that takes a sigc::slot.
  // If the slot function is very short, it might be easy to skip the on_xxx()
  // method and put its contents directly in a lambda expression.
  m_refActionGroup->add_action("new",
    [] { std::cout << "A File|New menu item was selected.\n"; /* on_action_file_new() */});
  // With sigc::mem_fun() or (for non-member functions and static member functions)
  // sigc::ptr_fun(). The only way before C++11 introduced lambda expressions.
  m_refActionGroup->add_action("open",
    sigc::mem_fun(*this, &ExampleWindow::on_action_others) );

  // With a lambda expression. Does not disconnect automatically when ExampleWindow
  // is deleted, like sigc::mem_fun() does.
  m_refActionRain = m_refActionGroup->add_action_bool("rain",
    [this] { on_action_toggle(); }, false);

  m_refActionGroup->add_action("quit",
    sigc::mem_fun(*this, &ExampleWindow::on_action_file_quit) );

  // With a lambda expression and sigc::track_obj() or sigc::track_object().
  // Disconnects automatically like sigc::mem_fun().
#if SIGCXX_MINOR_VERSION >= 4
  m_refActionGroup->add_action("cut",
    sigc::track_object([this] { on_action_others(); }, *this));
#else
  m_refActionGroup->add_action("cut",
    sigc::track_obj([this] { on_action_others(); }, *this));
#endif
  m_refActionGroup->add_action("copy",
    sigc::mem_fun(*this, &ExampleWindow::on_action_others) );
  m_refActionGroup->add_action("paste",
    sigc::mem_fun(*this, &ExampleWindow::on_action_others) );

  insert_action_group("example", m_refActionGroup);

  //Define how the actions are presented in the menus and toolbars:
  m_refBuilder = Gtk::Builder::create();

  //Layout the actions in a menubar and toolbar:
  const Glib::ustring ui_info =
    "<interface>"
    "  <menu id='menubar'>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_File</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_New</attribute>"
    "          <attribute name='action'>example.new</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Open</attribute>"
    "          <attribute name='action'>example.open</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Rain</attribute>"
    "          <attribute name='action'>example.rain</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Quit</attribute>"
    "          <attribute name='action'>example.quit</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_Edit</attribute>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>_Cut</attribute>"
    "        <attribute name='action'>example.cut</attribute>"
    "      </item>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>_Copy</attribute>"
    "        <attribute name='action'>example.copy</attribute>"
    "      </item>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>_Paste</attribute>"
    "        <attribute name='action'>example.paste</attribute>"
    "      </item>"
    "    </submenu>"
    "  </menu>"
    "</interface>";

  // Set accelerator keys:
  app->set_accel_for_action("example.new", "<Primary>n");
  app->set_accel_for_action("example.open", "<Primary>o");
  app->set_accel_for_action("example.quit", "<Primary>q");
  app->set_accel_for_action("example.cut", "<Primary>x");
  app->set_accel_for_action("example.copy", "<Primary>c");
  app->set_accel_for_action("example.paste", "<Primary>v");

  try
  {
    m_refBuilder->add_from_string(ui_info);
    m_refBuilder->add_from_resource("/toolbar/toolbar.ui");
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "Building menus and toolbar failed: " <<  ex.what();
  }

  //Get the menubar:
  auto gmenu = m_refBuilder->get_object<Gio::Menu>("menubar");
  if (!gmenu)
    g_warning("GMenu not found");
  else
  {
    auto pMenuBar = Gtk::make_managed<Gtk::PopoverMenuBar>(gmenu);

    //Add the PopoverMenuBar to the window:
    m_Box.append(*pMenuBar);
  }

  //Get the toolbar and add it to a container widget:
  auto toolbar = m_refBuilder->get_widget<Gtk::Box>("toolbar");
  if (!toolbar)
    g_warning("toolbar not found");
  else
    m_Box.append(*toolbar);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_action_file_quit()
{
  set_visible(false); //Closes the main window to stop the app->make_window_and_run().
}

//void ExampleWindow::on_action_file_new()
//{
//   std::cout << "A File|New menu item was selected." << std::endl;
//}

void ExampleWindow::on_action_others()
{
  std::cout << "A menu item was selected." << std::endl;
}

void ExampleWindow::on_action_toggle()
{
  std::cout << "The toggle menu item was selected." << std::endl;

  bool active = false;
  m_refActionRain->get_state(active);

  //The toggle action's state does not change automatically:
  active = !active;
  m_refActionRain->change_state(active);

  Glib::ustring message;
  if(active)
    message = "Toggle is active.";
  else
    message = "Toggle is not active";

  std::cout << message << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <gtkmm.h>
#include "examplewindow.h"

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv, app);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>toolbar.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/toolbar">
    <file preprocess="xml-stripblanks">toolbar.ui</file>
    <file>rain.png</file>
  </gresource>
</gresources>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="menu-example-popup">
<title>Příklad vyskakovací nabídky</title>

<figure xml:id="figure-menus-popup">
  <title>Vyskakovací nabídka</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/menu_popup.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/menus/popup/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

#include <memory>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow(const Glib::RefPtr<Gtk::Application>& app);
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_label_pressed(int n_press, double x, double y);

  void on_menu_file_popup_generic();

  //Child widgets:
  Gtk::Box m_Box;
  Gtk::Label m_Label;
  Gtk::PopoverMenu m_MenuPopup;

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gtk::GestureClick> m_refGesture;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
: m_Box(Gtk::Orientation::VERTICAL),
  m_Label("Right-click to see the popup menu.")
{
  set_title("popup example");
  set_default_size(200, 200);

  set_child(m_Box);

  // Catch button_press events:
  m_Box.append(m_Label);
  m_Label.set_expand();
  m_refGesture = Gtk::GestureClick::create();
  m_refGesture->set_button(GDK_BUTTON_SECONDARY);
  m_refGesture->signal_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_label_pressed));
  m_Label.add_controller(m_refGesture);

  //Create actions:
  auto refActionGroup = Gio::SimpleActionGroup::create();

  //File|New sub menu:
  //These menu actions would normally already exist for a main menu, because a
  //context menu should not normally contain menu items that are only available
  //via a context menu.

  refActionGroup->add_action("edit",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_popup_generic));

  refActionGroup->add_action("process",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_popup_generic));

  refActionGroup->add_action("remove",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_popup_generic));

  insert_action_group("examplepopup", refActionGroup);

  // Set accelerator keys:
  app->set_accel_for_action("examplepopup.edit", "<Primary>e");
  app->set_accel_for_action("examplepopup.process", "<Primary>p");
  app->set_accel_for_action("examplepopup.remove", "<Primary>r");

  m_refBuilder = Gtk::Builder::create();

  //Layout the actions in a menubar and toolbar:
  Glib::ustring ui_info =
    "<interface>"
    "  <menu id='menu-examplepopup'>"
    "    <section>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>Edit</attribute>"
    "        <attribute name='action'>examplepopup.edit</attribute>"
    "      </item>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>Process</attribute>"
    "        <attribute name='action'>examplepopup.process</attribute>"
    "      </item>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>Remove</attribute>"
    "        <attribute name='action'>examplepopup.remove</attribute>"
    "      </item>"
    "    </section>"
    "  </menu>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building menus failed: " <<  ex.what();
  }

  //Get the menu:
  auto gmenu = m_refBuilder->get_object<Gio::Menu>("menu-examplepopup");
  if(!gmenu)
    g_warning("GMenu not found");

  m_MenuPopup.set_parent(m_Label);
  m_MenuPopup.set_menu_model(gmenu);
  m_MenuPopup.set_has_arrow(false);
}

ExampleWindow::~ExampleWindow()
{
  m_MenuPopup.unparent();
}

void ExampleWindow::on_menu_file_popup_generic()
{
   std::cout << "A popup menu item was selected." << std::endl;
}

void ExampleWindow::on_label_pressed(int /* n_press */, double x, double y)
{
  const Gdk::Rectangle rect(x, y, 1, 1);
  m_MenuPopup.set_pointing_to(rect);
  m_MenuPopup.popup();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv, app);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-adjustment">
<title>Přizpůsobení (Adjustment)</title>

<para><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.</para>

<para>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.</para>

<section xml:id="sec-creating-adjustment">
<title>Vytváření objektů Adjustment</title>

<para><classname>Gtk::Adjustment</classname> se vytváří jeho metodou <methodname>create()</methodname>, která vypadá takto:</para>

<programlisting xml:lang="en"><code>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);</code></programlisting>

<para>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.</para>

</section>

<section xml:id="sec-adjustments-easy">
<title>Snadné použití objektů Adjustment</title>

<para>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.</para>
<para>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>.</para>

<para>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í.</para>

<para>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:</para>
<programlisting xml:lang="en"><code>// 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);</code></programlisting>

</section>

<section xml:id="sec-adjustment-internals">
<title>Objekty Adjustment zevnitř</title>

<para>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>:</para>

<para>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.</para>

<para>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:</para>
<programlisting xml:lang="en"><code>void cb_rotate_picture(MyPicture* picture)
{
  picture-&gt;set_rotation(adj-&gt;get_value());
...</code></programlisting>
<para>a napojili byste jej na přizpůsobení widgetu <classname>Scale</classname> nějak takto:</para>
<programlisting xml:lang="en"><code>adj-&gt;signal_value_changed().connect(sigc::bind&lt;MyPicture*&gt;(sigc::mem_fun(*this,
    &amp;cb_rotate_picture), picture));</code></programlisting>

<para>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>.</para>

<para>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>.</para>

<para>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>.</para>
<programlisting xml:lang="en"><code>adjustment-&gt;signal_changed();</code></programlisting>

</section>

</chapter>

<chapter xml:id="chapter-dialogs">
<title>Dialogová okna</title>

<note><para xml:lang="en"><classname>Gtk::Dialog</classname> and the classes derived from it,
are deprecated since <application>gtkmm</application> 4.10. They can still be used in <application>gtkmm</application>4 applications,
provided GTKMM_DISABLE_DEPRECATED and GDKMM_DISABLE_DEPRECATED are not defined.
Some of the dialog classes are replaced by classes that are available since <application>gtkmm</application> 4.10.
</para>
<para xml:lang="en">The examples in this chapter use classes that are available since <application>gtkmm</application> 4.10.
Similar examples with the deprecated classes are available in the
<link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/gtkmm-4-0/examples/book/dialogs/">
gtkmm-4-0 branch</link> in the git repository.
</para></note>

<para xml:lang="en">
Dialogs 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 <literal>response</literal> signal which
is emitted when the user dismisses the dialog.
</para>

<para>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.</para>

<para>Když 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>.</para>

<para xml:lang="en">
The <literal>response</literal> signal handler receives an <literal>int</literal>. This
may be a value from the <type>Gtk::ResponseType</type> 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>.
</para>

<para xml:lang="en">
To show the dialog, call <methodname>set_visible(true)</methodname>. If the same dialog instance
will be shown several times, you must also call <methodname>set_hide_on_close()</methodname>,
or else the dialog will be destroyed when it's closed.
Connect to the <literal>response</literal> signal, if you want to know which button
was pressed. The <literal>response</literal> signal handler is also where you
should hide the dialog.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Dialog.html">Reference</link></para>

<section xml:id="sec-dialogs-alertdialog">
<title xml:lang="en">AlertDialog and MessageDialog</title>
<para xml:lang="en">
<classname>MessageDialog</classname> (deprecated since <application>gtkmm</application> 4.10) and
<classname>AlertDialog</classname> (available since <application>gtkmm</application> 4.10) are convenience
classes, used to create simple, standard message dialogs, with a message and buttons
for user response.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1AlertDialog.html">AlertDialog Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1MessageDialog.html">MessageDialog Reference</link></para>

<section xml:id="alertdialog-example">
<title>Příklad</title>

<figure xml:id="figure-dialogs-alertdialog">
  <title xml:lang="en">AlertDialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dialogs_alertdialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dialogs/alertdialog">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_button_info_clicked();
  void on_button_question_clicked();
  void on_question_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result);

  //Child widgets:
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Info;
  Gtk::Button m_Button_Question;

  Glib::RefPtr<Gtk::AlertDialog> m_pDialog;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/messagedialog.h>
#include <iostream>


ExampleWindow::ExampleWindow()
: m_ButtonBox(Gtk::Orientation::VERTICAL),
  m_Button_Info("Show Info AlertDialog"),
  m_Button_Question("Show Question AlertDialog")
{
  set_title("Gtk::AlertDialog example");

  set_child(m_ButtonBox);

  m_ButtonBox.append(m_Button_Info);
  m_Button_Info.set_expand(true);
  m_Button_Info.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_info_clicked) );

  m_ButtonBox.append(m_Button_Question);
  m_Button_Question.set_expand(true);
  m_Button_Question.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_question_clicked) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_info_clicked()
{
  if (!m_pDialog)
    m_pDialog = Gtk::AlertDialog::create();
  else
  {
    // Reset values that may have been set by on_button_question_clicked().
    m_pDialog->set_buttons({});
    m_pDialog->set_default_button(-1);
    m_pDialog->set_cancel_button(-1);
  }

  m_pDialog->set_message("This is an INFO AlertDialog.");
  m_pDialog->set_detail("And this is the secondary text that explains things.");
  m_pDialog->show(*this);
}

void ExampleWindow::on_button_question_clicked()
{
  if (!m_pDialog)
    m_pDialog = Gtk::AlertDialog::create();
  m_pDialog->set_message("This is a QUESTION AlertDialog.");
  m_pDialog->set_detail("And this is the secondary text that explains things.");
  m_pDialog->set_buttons({"Cancel", "Retry", "OK"});
  m_pDialog->set_default_button(2); // OK button or Return key
  m_pDialog->set_cancel_button(0); // Cancel button or Escape key
  m_pDialog->choose(*this,
    sigc::mem_fun(*this, &ExampleWindow::on_question_dialog_finish));
}

void ExampleWindow::on_question_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result)
{
  try
  {
    const int response_id = m_pDialog->choose_finish(result);
    switch (response_id)
    {
    case 0:
      std::cout << "Cancel clicked." << std::endl;
      break;
    case 1:
      std::cout << "Retry clicked." << std::endl;
      break;
    case 2:
      std::cout << "OK clicked." << std::endl;
      break;
    default:
      std::cout << "Unexpected response: " << response_id << std::endl;
      break;
    }
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by m_pDialog->choose_finish(result).
    std::cout << "DialogError, " << err.what() << std::endl;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-dialogs-filedialog">
<title xml:lang="en">FileDialog and FileChooserDialog</title>
<para xml:lang="en">
The <classname>FileChooserDialog</classname> (deprecated since <application>gtkmm</application> 4.10) and
<classname>FileDialog</classname> (available since <application>gtkmm</application> 4.10) are suitable
for use with "Open" or "Save" menu items.
</para>
<para xml:lang="en">
Most of the useful member methods for <classname>FileChooserDialog</classname>
are actually in the <classname>Gtk::FileChooser</classname> base class.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1FileDialog.html">FileDialog Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1FileChooserDialog.html">FileChooserDialog Reference</link></para>

<section xml:id="filedialog-example">
<title>Příklad</title>

<figure xml:id="figure-dialogs-filedialog">
  <title xml:lang="en">FileDialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dialogs_filedialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dialogs/filedialog">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_button_file_clicked();
  void on_button_folder_clicked();
  void on_file_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result,
    const Glib::RefPtr<Gtk::FileDialog>& dialog);
  void on_folder_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result,
    const Glib::RefPtr<Gtk::FileDialog>& dialog);

  //Child widgets:
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_File;
  Gtk::Button m_Button_Folder;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_ButtonBox(Gtk::Orientation::VERTICAL),
  m_Button_File("Choose File"),
  m_Button_Folder("Choose Folder")
{
  set_title("Gtk::FileDialog example");

  set_child(m_ButtonBox);

  m_ButtonBox.append(m_Button_File);
  m_Button_File.set_expand(true);
  m_Button_File.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_file_clicked) );

  m_ButtonBox.append(m_Button_Folder);
  m_Button_Folder.set_expand(true);
  m_Button_Folder.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_folder_clicked) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_file_clicked()
{
  auto dialog = Gtk::FileDialog::create();

  // Add filters, so that only certain file types can be selected:
  auto filters = Gio::ListStore<Gtk::FileFilter>::create();

  auto filter_text = Gtk::FileFilter::create();
  filter_text->set_name("Text files");
  filter_text->add_mime_type("text/plain");
  filters->append(filter_text);

  auto filter_cpp = Gtk::FileFilter::create();
  filter_cpp->set_name("C/C++ files");
  filter_cpp->add_mime_type("text/x-c");
  filter_cpp->add_mime_type("text/x-c++");
  filter_cpp->add_mime_type("text/x-c-header");
  filters->append(filter_cpp);

  auto filter_any = Gtk::FileFilter::create();
  filter_any->set_name("Any files");
  filter_any->add_pattern("*");
  filters->append(filter_any);

  dialog->set_filters(filters);

  // Show the dialog and wait for a user response:
  dialog->open(sigc::bind(sigc::mem_fun(
    *this, &ExampleWindow::on_file_dialog_finish), dialog));
}

void ExampleWindow::on_file_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result,
  const Glib::RefPtr<Gtk::FileDialog>& dialog)
{
  // Handle the response:
  try
  {
    auto file = dialog->open_finish(result);

    // Notice that this is a std::string, not a Glib::ustring.
    auto filename = file->get_path();
    std::cout << "File selected: " <<  filename << std::endl;
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by dialog->open_finish(result).
    std::cout << "No file selected. " << err.what() << std::endl;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
  }
}

void ExampleWindow::on_button_folder_clicked()
{
  auto dialog = Gtk::FileDialog::create();

  // Show the dialog and wait for a user response:
  dialog->select_folder(sigc::bind(sigc::mem_fun(
    *this, &ExampleWindow::on_folder_dialog_finish), dialog));
}

void ExampleWindow::on_folder_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result,
  const Glib::RefPtr<Gtk::FileDialog>& dialog)
{
  // Handle the response:
  try
  {
    auto folder = dialog->select_folder_finish(result);
    std::cout << "Folder selected: " << folder->get_path() << std::endl;
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by dialog->select_folder_finish(result).
    std::cout << "No folder selected. " << err.what() << std::endl;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-dialogs-colordialog">
<title xml:lang="en">ColorDialog and ColorChooserDialog</title>
<para xml:lang="en">
The <classname>ColorChooserDialog</classname> (deprecated since <application>gtkmm</application> 4.10) and
<classname>ColorDialog</classname> (available since <application>gtkmm</application> 4.10) allow the user
to choose a color. The <classname>ColorButton</classname> (deprecated since <application>gtkmm</application> 4.10)
and <classname>ColorDialogButton</classname> (available since <application>gtkmm</application> 4.10) open
a color selection dialog when it is clicked.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ColorDialog.html">ColorDialog Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ColorChooserDialog.html">ColorChooserDialog Reference</link></para>

<section xml:id="colordialog-example">
<title>Příklad</title>

<figure xml:id="figure-dialogs-colordialog">
  <title xml:lang="en">ColorDialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dialogs_colordialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dialogs/colordialog">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_color_button_color_set();
  void on_button_dialog_clicked();
  void on_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result);

  //Draw function:
  void on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::ColorDialogButton m_ColorDialogButton;
  Gtk::Button m_Button_Dialog;
  Gtk::DrawingArea m_DrawingArea; //To show the color.

  Glib::RefPtr<Gtk::ColorDialog> m_pDialog;
  Gdk::RGBA m_Color;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL, 5),
  m_Button_Dialog("Choose Color")
{
  set_title("Gtk::ColorDialog example");
  set_default_size(200, 200);

  m_pDialog = Gtk::ColorDialog::create();
  m_ColorDialogButton.set_dialog(m_pDialog);

  set_child(m_VBox);

  m_VBox.append(m_ColorDialogButton);
  m_ColorDialogButton.property_rgba().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_color_button_color_set));

  m_VBox.append(m_Button_Dialog);
  m_Button_Dialog.signal_clicked().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_button_dialog_clicked) );

  //Set start color:
  m_Color.set_red(0.0);
  m_Color.set_green(0.0);
  m_Color.set_blue(1.0);
  m_Color.set_alpha(1.0); //opaque
  m_ColorDialogButton.set_rgba(m_Color);

  m_VBox.append(m_DrawingArea);
  m_DrawingArea.set_expand(true);
  m_DrawingArea.set_draw_func(sigc::mem_fun(*this, &ExampleWindow::on_drawing_area_draw));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_color_button_color_set()
{
  //Store the chosen color:
  m_Color = m_ColorDialogButton.get_rgba();
  m_DrawingArea.queue_draw();
}

void ExampleWindow::on_button_dialog_clicked()
{
  m_pDialog->choose_rgba(*this, m_Color,
    sigc::mem_fun(*this, &ExampleWindow::on_dialog_finish));
}

void ExampleWindow::on_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result)
{
  try
  {
    // If this call changes the color, it will trigger a call to
    // on_color_button_color_set().
    m_ColorDialogButton.set_rgba(m_pDialog->choose_rgba_finish(result));

    // This is what you should do if m_ColorDialogButton and
    // on_color_button_color_set() did not exist:
    //m_Color = m_pDialog->choose_rgba_finish(result);
    //m_DrawingArea.queue_draw();
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by m_pDialog->choose_rgba_finish(result).
    std::cout << "No color selected. " << err.what() << std::endl;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
  }
}

void ExampleWindow::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int, int)
{
  Gdk::Cairo::set_source_rgba(cr, m_Color);
  cr->paint();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-dialogs-fontdialog">
<title xml:lang="en">FontDialog and FontChooserDialog</title>
<para xml:lang="en">
The <classname>FontChooserDialog</classname> (deprecated since <application>gtkmm</application> 4.10) and
<classname>FontDialog</classname> (available since <application>gtkmm</application> 4.10) allow the user
to choose a font. The <classname>FontButton</classname> (deprecated since <application>gtkmm</application> 4.10)
and <classname>FontDialogButton</classname> (available since <application>gtkmm</application> 4.10) open
a font chooser dialog when it is clicked.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1FontDialog.html">FontDialog Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1FontChooserDialog.html">FontChooserDialog Reference</link></para>

<section xml:id="fontdialog-example">
<title>Příklad</title>

<figure xml:id="figure-dialogs-fontdialog">
  <title xml:lang="en">FontDialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dialogs_fontdialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dialogs/fontdialog">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_font_button_font_set();
  void on_button_dialog_clicked();
  void on_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result);

  //Child widgets:
  Gtk::Box m_ButtonBox;
  Gtk::FontDialogButton m_FontDialogButton;
  Gtk::Button m_Button_Dialog;

  Glib::RefPtr<Gtk::FontDialog> m_pDialog;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_ButtonBox(Gtk::Orientation::VERTICAL),
  m_Button_Dialog("Choose Font")
{
  set_title("Gtk::FontDialog example");

  set_child(m_ButtonBox);

  m_pDialog = Gtk::FontDialog::create();

  m_ButtonBox.append(m_FontDialogButton);
  m_FontDialogButton.set_dialog(m_pDialog);
  m_FontDialogButton.set_font_desc(Pango::FontDescription("Sans 10"));
  m_FontDialogButton.set_expand(true);
  m_FontDialogButton.set_use_font(true);
  m_FontDialogButton.set_use_size(true);
  m_FontDialogButton.property_font_desc().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_font_button_font_set));

  m_ButtonBox.append(m_Button_Dialog);
  m_Button_Dialog.set_expand(true);
  m_Button_Dialog.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_dialog_clicked));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_font_button_font_set()
{
  auto font_name = m_FontDialogButton.get_font_desc().to_string();
  std::cout << "Font chosen: " << font_name << std::endl;
}

void ExampleWindow::on_button_dialog_clicked()
{
  // Get the previously selected font description from the FontDialogButton.
  m_pDialog->choose_font(*this,
    sigc::mem_fun(*this, &ExampleWindow::on_dialog_finish),
    m_FontDialogButton.get_font_desc());
}

void ExampleWindow::on_dialog_finish(const Glib::RefPtr<Gio::AsyncResult>& result)
{
  try
  {
    // If this call changes the font, it will trigger a call to
    // on_font_button_font_set().
    m_FontDialogButton.set_font_desc(m_pDialog->choose_font_finish(result));
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by m_pDialog->choose_font_finish(result).
    std::cout << "No font selected. " << err.what() << std::endl;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-about-dialog">
<title>Nemodální dialogové okno s informacemi o aplikaci (AboutDialog)</title>
<para><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.</para>
<para>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í.</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1AboutDialog.html">Reference</link></para>

<section xml:id="aboutdialog-example">
<title>Příklad</title>

<figure xml:id="figure-dialogs-about">
  <title>Dialogové okno s informacemi o aplikaci (AboutDialog)</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dialogs_about.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dialogs/aboutdialog">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

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

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Label m_Label;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button;
  Gtk::AboutDialog m_Dialog;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Label("The AboutDialog is non-modal. "
    "You can select parts of this text while the AboutDialog is shown."),
  m_ButtonBox(Gtk::Orientation::VERTICAL),
  m_Button("Show AboutDialog")
{
  set_title("Gtk::AboutDialog example");
  set_default_size(400, 150);

  set_child(m_VBox);

  m_VBox.append(m_Label);
  m_Label.set_expand(true);
  m_Label.set_wrap(true);
  m_Label.set_selectable(true);

  m_VBox.append(m_ButtonBox);
  m_ButtonBox.append(m_Button);
  m_Button.set_expand(true);
  m_Button.set_halign(Gtk::Align::CENTER);
  m_Button.set_valign(Gtk::Align::CENTER);
  m_Button.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_clicked) );

  m_Dialog.set_transient_for(*this);
  m_Dialog.set_hide_on_close();

  m_Dialog.set_logo(Gdk::Texture::create_from_resource("/about/gtkmm_logo.gif"));
  m_Dialog.set_program_name("Example application");
  m_Dialog.set_version("1.0.0");
  m_Dialog.set_copyright("Murray Cumming");
  m_Dialog.set_comments("This is just an example application.");
  m_Dialog.set_license("LGPL");

  m_Dialog.set_website("http://www.gtkmm.org");
  m_Dialog.set_website_label("gtkmm website");

  std::vector<Glib::ustring> list_authors;
  list_authors.push_back("Murray Cumming");
  list_authors.push_back("Somebody Else");
  list_authors.push_back("AN Other");
  m_Dialog.set_authors(list_authors);

  m_Button.grab_focus();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_clicked()
{
  m_Dialog.set_visible(true);

  //Bring it to the front, in case it was already shown:
  m_Dialog.present();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>aboutdialog.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/about">
    <file>gtkmm_logo.gif</file>
  </gresource>
</gresources>
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-dialogs-windowdialog">
<title xml:lang="en">Custom Dialog</title>
<para xml:lang="en">
When none of the predefined dialog classes suit your needs, you can make your own
dialog by deriving a class from <classname>Window</classname> and fill it with
the widgets you need.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Window.html">Window Reference</link></para>

<section xml:id="windowdialog-example">
<title>Příklad</title>

<figure xml:id="figure-dialogs-windowdialog">
  <title xml:lang="en">Window Dialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/dialogs_windowdialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/dialogs/windowdialog">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "namedialog.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_button_clicked();
  void on_dialog_response(const Glib::ustring& response);
  void on_dialog_hidden();

  //Child widgets:
  Gtk::Button m_Button;

  NameDialog m_Dialog;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>namedialog.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_NAME_DIALOG_H_
#define GTKMM_NAME_DIALOG_H_

#include <gtkmm.h>

class NameDialog : public Gtk::Window
{
public:
  NameDialog();
  ~NameDialog() override;

  void buttons_clicked_connect(const sigc::slot<void(const Glib::ustring&)>& slot);
  Glib::ustring get_entry1() const;
  Glib::ustring get_entry2() const;

protected:
  //Member widgets:
  Gtk::Grid m_Grid;
  Gtk::Image m_Image;
  Gtk::Label m_Label1;
  Gtk::Label m_Label2;
  Gtk::Entry m_Entry1;
  Gtk::Entry m_Entry2;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_OK;
  Gtk::Button m_Button_Cancel;
};

#endif /* GTKMM_NAME_DIALOG_H_ */
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_Button("Show Dialog"),
  m_Dialog()
{
  set_title("Custom Dialog example");

  set_child(m_Button);
  m_Button.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));

  m_Dialog.set_default_size(250, 100);
  m_Dialog.set_transient_for(*this);
  m_Dialog.set_modal();
  m_Dialog.set_hide_on_close();
  m_Dialog.buttons_clicked_connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dialog_response));
  m_Dialog.signal_hide().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_dialog_hidden));
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_clicked()
{
  m_Dialog.set_visible(true);
}

void ExampleWindow::on_dialog_response(const Glib::ustring& response)
{
  m_Dialog.set_visible(false);

  if (response == "OK")
    std::cout << "Name: " << m_Dialog.get_entry1() << " "
      << m_Dialog.get_entry2() << std::endl; 
  else
    std::cout << response << " button clicked" << std::endl;
}

void ExampleWindow::on_dialog_hidden()
{
  std::cout << "Dialog hidden" << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>namedialog.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[NameDialog::NameDialog()
: m_Label1("_First name", true),
  m_Label2("_Second name", true),
  m_ButtonBox(Gtk::Orientation::HORIZONTAL, 5),
  m_Button_OK("_OK", true),
  m_Button_Cancel("_Cancel", true)
{
  set_destroy_with_parent(true);

  set_title("Name Dialog");
  set_child(m_Grid);

  m_Grid.set_row_spacing(4);
  m_Grid.set_column_spacing(4);
  m_Grid.set_expand(true);

  m_Image.set_from_icon_name("dialog-question");
  m_Image.set_icon_size(Gtk::IconSize::LARGE);
  m_Grid.attach(m_Image, 0, 0, 1, 2);

  m_Grid.attach(m_Label1, 1, 0);
  m_Grid.attach(m_Entry1, 2, 0);
  m_Label1.set_mnemonic_widget(m_Entry1);

  m_Grid.attach(m_Label2, 1, 1);
  m_Grid.attach(m_Entry2, 2, 1);
  m_Label2.set_mnemonic_widget(m_Entry2);

  m_Grid.attach(m_ButtonBox, 0, 2, 3, 1);
  m_ButtonBox.set_halign(Gtk::Align::END);
  m_ButtonBox.append(m_Button_OK);
  m_ButtonBox.append(m_Button_Cancel);
}

void NameDialog::buttons_clicked_connect(
  const sigc::slot<void(const Glib::ustring&)>& slot)
{
  m_Button_OK.signal_clicked().connect(sigc::bind(slot, "OK"));
  m_Button_Cancel.signal_clicked().connect(sigc::bind(slot, "Cancel"));
}

Glib::ustring NameDialog::get_entry1() const
{
  return m_Entry1.get_text();
}

Glib::ustring NameDialog::get_entry2() const
{
  return m_Entry2.get_text();
}

NameDialog::~NameDialog()
{
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

</chapter>

<chapter xml:id="chapter-drawingarea">
<title xml:lang="en">The DrawingArea Widget</title>
  <para xml:lang="en">
    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 draw 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
    <classname>DrawingArea</classname> does not, allowing you to write your own
    draw function to determine how the contents of the widget will be drawn.
    This is done by setting a draw function with a call to the
    <methodname>set_draw_func()</methodname> member function.
  </para>

  <para xml:lang="en">
      GTK uses the <link xlink:href="http://cairographics.org">Cairo</link> drawing API.
      With <application>gtkmm</application>, you may use the <link xlink:href="http://www.cairographics.org/cairomm/">cairomm</link> C++ API for cairo.
  </para>

  <para>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.</para>
  <note>
      <title>Cairo a Pango</title>
      <para>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.</para>
  </note>
  <para>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.</para>

  <section xml:id="sec-cairo-drawing-model">
  <title>Kreslicí model Cairo</title>
    <para>Základní koncept kreslení v Cairo obnáší definici „neviditelných“ cest a jejich následné obtažení a vyplnění, aby byly viditelné.</para>
    <para xml:lang="en">
        To do any drawing in <application>gtkmm</application> with Cairo, you must first get 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. Usually, you use the <classname>Cairo::Context</classname>
        that you get as input data to the draw function that you set with the call to
        <methodname>set_draw_func()</methodname>. It's also possible to create
        a <classname>Cairo::Context</classname> by calling the
        <methodname>Gdk::Surface::create_cairo_context()</methodname> and
        <methodname>Gdk::CairoContext::cairo_create()</methodname> functions.
        Since Cairo contexts are reference-counted objects, <methodname>cairo_create()</methodname>
        returns a <classname>Cairo::RefPtr&lt;Cairo::Context&gt;</classname> object.
        (Note the difference between <classname>Gdk::CairoContext</classname>
        and <classname>Cairo::Context</classname>.)
    </para>
    <para>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í.</para>
    <programlisting xml:lang="en"><code>Gtk::DrawingArea myArea;
auto gdkCairoContext = myArea.get_surface()-&gt;create_cairo_context();
auto myContext = gdkCairoContext-&gt;cairo_create();
myContext-&gt;set_source_rgb(1.0, 0.0, 0.0);
myContext-&gt;set_line_width(2.0);
    </code></programlisting>
    <para xml:lang="en">
        Each <classname>Cairo::Context</classname> is associated with a
        particular <classname>Gdk::Surface</classname>, so the first line of the
        above example creates a <classname>Gtk::DrawingArea</classname> widget
        and the next two lines use its associated <classname>Gdk::Surface</classname>
        to create a <classname>Cairo::Context</classname> object. The final
        two lines change the graphics state of the context.
    </para>
    <para xml:lang="en">
        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 <link xlink:href="http://www.cairographics.org/cairomm/">cairomm</link> API documentation.
    </para>
    <para xml:lang="en">
        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>.
        <tip>
            <para xml:lang="en">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:
          </para>
          <programlisting xml:lang="en"><code>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();
}</code></programlisting>
        </tip>
    </para>
    <para xml:lang="en">
        The draw function that you set with a call to <methodname>set_draw_func()</methodname>
        is called with 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 the draw function.
    </para>
  </section>
  <section xml:id="sec-cairo-drawing-lines">
  <title>Kreslení rovných čar</title>
    <para xml:lang="en">
        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.
        <tip>
            <para xml:lang="en">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.</para>
        </tip>
    </para>

    <section xml:id="cairo-example-lines">
    <title>Příklad</title>
    <para>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>.</para>
    <para>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.</para>
        <tip>
            <para>Mnoho 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.</para>
        </tip>

    <figure xml:id="figure-drawingarea-lines">
      <title>Kreslicí oblast – čáry</title>
      <screenshot>
        <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drawingarea_lines.png"/></imageobject></mediaobject>
      </screenshot>
    </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/simple">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>myarea.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYAREA_H
#define GTKMM_EXAMPLE_MYAREA_H

#include <gtkmm/drawingarea.h>

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
};

#endif // GTKMM_EXAMPLE_MYAREA_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <gtkmm/application.h>
#include <gtkmm/window.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

protected:
  MyArea m_area;
};

ExampleWindow::ExampleWindow()
{
  set_title("DrawingArea");
  set_child(m_area);
}

int main(int argc, char** argv)
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <cairomm/context.h>

MyArea::MyArea()
{
  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
}

MyArea::~MyArea()
{
}

void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  // coordinates for the center of the window
  int xc, yc;
  xc = width / 2;
  yc = height / 2;

  cr->set_line_width(10.0);

  // draw red lines out from the center of the window
  cr->set_source_rgb(0.8, 0.0, 0.0);
  cr->move_to(0, 0);
  cr->line_to(xc, yc);
  cr->line_to(0, height);
  cr->move_to(xc, yc);
  cr->line_to(width, yc);
  cr->stroke();
}
]]></code></programlisting>
<!-- end inserted example code -->

    <para xml:lang="en">
        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 becomes the draw function by a call to <methodname>set_draw_func()</methodname>
        in <classname>MyArea</classname>'s constructor. <methodname>on_draw()</methodname>
        is then 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>.
    </para>
    <tip>
        <title>Kreslení s relativními souřadnicemi</title>
        <para>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>.</para>
    </tip>
    </section>

    <section xml:id="cairo-line-styles">
    <title>Styly čar</title>
        <para>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ší.</para>
        <para>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í:</para>
        <figure xml:id="figure-cairo-joins">
          <title>Různé typy spojů v Cairo</title>
            <screenshot>
                <mediaobject><imageobject><imagedata format="PNG" fileref="figures/cairo_joins.png"/></imageobject></mediaobject>
            </screenshot>
        </figure>
        <para>Styl spojování čar se nastavuje pomocí funkce <methodname>Cairo::Context::set_line_join()</methodname>.</para>
        <para>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>.</para>
        <para>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.</para>
    </section>

    <section xml:id="sec-cairo-thin-lines">
    <title>Kreslení tenkých čar</title>
      <para>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).</para>
      <para xml:lang="en">
        The 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 <link xlink:href="http://cairographics.org/FAQ/#sharp_lines">Cairo FAQ</link>.
      </para>

      <figure xml:id="figure-drawingarea-thin-lines">
        <title>Kreslicí oblast – tenké čáry</title>
        <screenshot>
          <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drawingarea_thin_lines.png"/></imageobject></mediaobject>
        </screenshot>
      </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/thin_lines">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <gtkmm/checkbutton.h>
#include "myarea.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_toggled();

private:
  Gtk::Box m_HBox;
  MyArea m_Area_Lines;
  Gtk::CheckButton m_Button_FixLines;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYAREA_H
#define GTKMM_EXAMPLE_MYAREA_H

#include <gtkmm/drawingarea.h>

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

  void fix_lines(bool fix = true);

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);

private:
  double m_fix;
};

#endif // GTKMM_EXAMPLE_MYAREA_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_HBox(Gtk::Orientation::HORIZONTAL),
  m_Button_FixLines("Fix lines")
{
  set_title("Thin lines example");

  m_HBox.append(m_Area_Lines);
  m_HBox.append(m_Button_FixLines);

  set_child(m_HBox);

  m_Button_FixLines.signal_toggled().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_toggled));

  // Synchonize the drawing in m_Area_Lines with the state of the toggle button.
  on_button_toggled();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_toggled()
{
  m_Area_Lines.fix_lines(m_Button_FixLines.get_active());
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"

MyArea::MyArea()
: m_fix (0)
{
  set_content_width(200);
  set_content_height(100);
  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
}

MyArea::~MyArea()
{
}

void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  cr->set_line_width(1.0);

  // draw one line, every two pixels
  // without the 'fix', you won't notice any space between the lines,
  // since each one will occupy two pixels (width)
  for (int i = 0; i < width; i += 2)
  {
    cr->move_to(i + m_fix, 0);
    cr->line_to(i + m_fix, height);
  }

  cr->stroke();
}

// Toogle between both values (0 or 0.5)
void MyArea::fix_lines(bool fix)
{
  // to get the width right, we have to draw in the middle of the pixel
  m_fix = fix ? 0.5 : 0.0;

  // force the redraw of the image
  queue_draw();
}
]]></code></programlisting>
<!-- end inserted example code -->
    </section>
  </section>

    <section xml:id="sec-cairo-curved-lines">
    <title>Kreslení křivek</title>
        <para>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.</para>

        <section xml:id="cairo-example-curves">
        <title>Příklad</title>
            <para>Tato jednoduchá aplikace kreslí pomocí Cairo křivku a zobrazuje řídící body pro její jednotlivé konce.</para>
        <figure xml:id="figure-drawingarea-curve">
          <title>Kreslicí oblast – čáry</title>
            <screenshot>
                <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drawingarea_curve.png"/></imageobject></mediaobject>
            </screenshot>
        </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/curve">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>myarea.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYAREA_H
#define GTKMM_EXAMPLE_MYAREA_H

#include <gtkmm/drawingarea.h>

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
};

#endif // GTKMM_EXAMPLE_MYAREA_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <gtkmm/application.h>
#include <gtkmm/window.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

protected:
  MyArea m_area;
};

ExampleWindow::ExampleWindow()
{
  set_title("DrawingArea");
  set_child(m_area);
}

int main(int argc, char** argv)
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <cairomm/context.h>

MyArea::MyArea()
{
  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
}

MyArea::~MyArea()
{
}

void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  double x0=0.1, y0=0.5, // start point
         x1=0.4, y1=0.9,  // control point #1
         x2=0.6, y2=0.1,  // control point #2
         x3=0.9, y3=0.5;  // end point

  // scale to unit square (0 to 1 width and height)
  cr->scale(width, height);

  cr->set_line_width(0.05);
  // draw curve
  cr->move_to(x0, y0);
  cr->curve_to(x1, y1, x2, y2, x3, y3);
  cr->stroke();
  // show control points
  cr->set_source_rgba(1, 0.2, 0.2, 0.6);
  cr->move_to(x0, y0);
  cr->line_to (x1, y1);
  cr->move_to(x2, y2);
  cr->line_to (x3, y3);
  cr->stroke();
}
]]></code></programlisting>
<!-- end inserted example code -->
        <para>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.</para>
        <para>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.</para>
        <para>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).</para>
        </section>
  </section>

  <section xml:id="sec-cairo-drawing-arcs">
  <title>Kreslení oblouků a kružnic</title>
      <para>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ů.)</para>
      <para xml:lang="en">
          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>:
      </para>
      <programlisting xml:lang="en"><code>context-&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();</code></programlisting>

      <section xml:id="cairo-example-arcs">
      <title>Příklad</title>
          <para>Zde je příklad jednoduchého programu, který kreslí do kreslicí oblasti oblouk, kružnici a elipsu.</para>
          <figure xml:id="figure-drawingarea-arc">
            <title>Kreslicí oblast – oblouky</title>
              <screenshot>
                  <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drawingarea_arcs.png"/></imageobject></mediaobject>
              </screenshot>
          </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/arcs">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>myarea.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYAREA_H
#define GTKMM_EXAMPLE_MYAREA_H

#include <gtkmm/drawingarea.h>

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
};

#endif // GTKMM_EXAMPLE_MYAREA_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <gtkmm/application.h>
#include <gtkmm/window.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

protected:
  MyArea m_area;
};

ExampleWindow::ExampleWindow()
{
  set_title("DrawingArea");
  set_child(m_area);
}

int main(int argc, char** argv)
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <cairomm/context.h>
#include <cmath>

MyArea::MyArea()
{
  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
}

MyArea::~MyArea()
{
}

void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  const int lesser = std::min(width, height);

  // coordinates for the center of the window
  const int xc = width / 2;
  const int yc = height / 2;

  cr->set_line_width(lesser * 0.02);  // outline thickness changes
                                      // with window size

  // first draw a simple unclosed arc
  cr->save();
  cr->arc(width / 3.0, height / 4.0, lesser / 4.0, -(M_PI / 5.0), M_PI);
  cr->close_path();   // line back to start point
  cr->set_source_rgb(0.0, 0.8, 0.0);
  cr->fill_preserve();
  cr->restore();  // back to opaque black
  cr->stroke();   // outline it

  // now draw a circle
  cr->save();
  cr->arc(xc, yc, lesser / 4.0, 0.0, 2.0 * M_PI); // full circle
  cr->set_source_rgba(0.0, 0.0, 0.8, 0.6);    // partially translucent
  cr->fill_preserve();
  cr->restore();  // back to opaque black
  cr->stroke();

  // and finally an ellipse
  double ex, ey, ew, eh;
  // center of ellipse
  ex = xc;
  ey = 3.0 * height / 4.0;
  // ellipse dimensions
  ew = 3.0 * width / 4.0;
  eh = height / 3.0;

  cr->save();

  cr->translate(ex, ey);  // make (ex, ey) == (0, 0)
  cr->scale(ew / 2.0, eh / 2.0);  // for width: ew / 2.0 == 1.0
                                  // for height: eh / 2.0 == 1.0

  cr->arc(0.0, 0.0, 1.0, 0.0, 2 * M_PI);  // 'circle' centered at (0, 0)
                                          // with 'radius' of 1.0

  cr->set_source_rgba(0.8, 0.0, 0.0, 0.7);
  cr->fill_preserve();
  cr->restore();  // back to opaque black
  cr->stroke();
}
]]></code></programlisting>
<!-- end inserted example code -->

          <para>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.</para>
          <para>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.</para>
          <para>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í.</para>
          <note>
              <title>Kreslení po směru hodinových ručiček</title>
              <para>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.</para>
          </note>

      </section>
  </section>
  <section xml:id="sec-drawing-text">
  <title>Kreslení textu</title>

      <section xml:id="drawing-text-pango">
      <title>Kreslení textu pomocí knihovny Pango</title>
          <para>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>.</para>
      </section>
      <section xml:id="pango-text-example">
      <title>Příklad</title>

        <para xml:lang="en">
           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-examples">example</link> of drawing text.
        </para>
        <figure xml:id="figure-drawingarea-pango-text">
          <title>Kreslicí oblast – text</title>
            <screenshot>
                <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drawingarea_pango_text.png"/></imageobject></mediaobject>
            </screenshot>
        </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/pango_text">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>myarea.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYAREA_H
#define GTKMM_EXAMPLE_MYAREA_H

#include <gtkmm/drawingarea.h>

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);

private:
  void draw_rectangle(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
  void draw_text(const Cairo::RefPtr<Cairo::Context>& cr, int rectangle_width, int rectangle_height);

};

#endif // GTKMM_EXAMPLE_MYAREA_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <gtkmm/application.h>
#include <gtkmm/window.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

protected:
  MyArea m_area;
};

ExampleWindow::ExampleWindow()
{
  set_title("Drawing text example");
  set_child(m_area);
}

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"

MyArea::MyArea()
{
  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
}

MyArea::~MyArea()
{
}

void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  const int rectangle_width = width;
  const int rectangle_height = height / 2;

  // Draw a black rectangle
  cr->set_source_rgb(0.0, 0.0, 0.0);
  draw_rectangle(cr, rectangle_width, rectangle_height);

  // and some white text
  cr->set_source_rgb(1.0, 1.0, 1.0);
  draw_text(cr, rectangle_width, rectangle_height);

  // flip the image vertically
  // see http://www.cairographics.org/documentation/cairomm/reference/classCairo_1_1Matrix.html
  // the -1 corresponds to the yy part (the flipping part)
  // the height part is a translation (we could have just called cr->translate(0, height) instead)
  // it's height and not height / 2, since we want this to be on the second part of our drawing
  // (otherwise, it would draw over the previous part)
  Cairo::Matrix matrix(1.0, 0.0, 0.0, -1.0, 0.0, height);

  // apply the matrix
  cr->transform(matrix);

  // white rectangle
  cr->set_source_rgb(1.0, 1.0, 1.0);
  draw_rectangle(cr, rectangle_width, rectangle_height);

  // black text
  cr->set_source_rgb(0.0, 0.0, 0.0);
  draw_text(cr, rectangle_width, rectangle_height);
}

void MyArea::draw_rectangle(const Cairo::RefPtr<Cairo::Context>& cr,
                            int width, int height)
{
  cr->rectangle(0, 0, width, height);
  cr->fill();
}

void MyArea::draw_text(const Cairo::RefPtr<Cairo::Context>& cr,
                       int rectangle_width, int rectangle_height)
{
  // https://gnome.pages.gitlab.gnome.org/pangomm/classPango_1_1FontDescription.html
  Pango::FontDescription font;

  font.set_family("Monospace");
  font.set_weight(Pango::Weight::BOLD);

  // https://gnome.pages.gitlab.gnome.org/pangomm/classPango_1_1Layout.html
  auto layout = create_pango_layout("Hi there!");

  layout->set_font_description(font);

  int text_width;
  int text_height;

  //get the text dimensions (it updates the variables -- by reference)
  layout->get_pixel_size(text_width, text_height);

  // Position the text in the middle
  cr->move_to((rectangle_width-text_width)/2, (rectangle_height-text_height)/2);

  layout->show_in_cairo_context(cr);
}
]]></code></programlisting>
<!-- end inserted example code -->
      </section>

      <!--
      <sect2 id="drawing-text-cairo">
          <title>Drawing Text with Cairo</title>
          <warning>TODO: Add Cairo content.</warning>
      </sect2>
      -->
  </section>

  <section xml:id="sec-draw-images">
  <title>Kreslení obrázků</title>
          <para>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.</para>
          <para xml:lang="en">
              Probably the most common way of creating
              <classname>Gdk::Pixbuf</classname>s is to use
              <methodname>Gdk::Pixbuf::create_from_file()</methodname> or
              <methodname>Gdk::Pixbuf::create_from_resource()</methodname>,
              which can read an image file, such as a png file into a pixbuf
              ready for rendering.
          </para>
          <para><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>.</para>
          <para>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ě.)</para>
          <programlisting xml:lang="en"><code>void MyArea::on_draw(const Cairo::RefPtr&lt;Cairo::Context&gt;&amp; cr, int width, int height)
{
  auto 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();
}</code></programlisting>

        <section xml:id="cairo-example-image">
        <title>Příklad</title>
            <para xml:lang="en">
                Here is an example of a simple program that draws an image.
                The program loads the image from a resource file. See the <link linkend="sec-gio-resource">Gio::Resource and glib-compile-resources</link>
                section. Use <application>glib-compile-resources</application> to compile
                the resources into a C source file that can be compiled and
                linked with the C++ code. E.g.
                <screen xml:lang="en">$ glib-compile-resources --target=resources.c --generate-source image.gresource.xml</screen>
            </para>
        <figure xml:id="figure-drawingarea-image">
          <title>Kreslicí oblast – obrázek</title>
            <screenshot>
                <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drawingarea_image.png"/></imageobject></mediaobject>
            </screenshot>
        </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/image">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>myarea.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYAREA_H
#define GTKMM_EXAMPLE_MYAREA_H

#include <gtkmm/drawingarea.h>
#include <gdkmm/pixbuf.h>

class MyArea : public Gtk::DrawingArea
{
public:
  MyArea();
  virtual ~MyArea();

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);

  Glib::RefPtr<Gdk::Pixbuf> m_image;
};

#endif // GTKMM_EXAMPLE_MYAREA_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <gtkmm/application.h>
#include <gtkmm/window.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

protected:
  MyArea m_area;
};

ExampleWindow::ExampleWindow()
{
  set_title("DrawingArea");
  set_default_size(300, 200);
  set_child(m_area);
}

int main(int argc, char** argv)
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myarea.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myarea.h"
#include <cairomm/context.h>
#include <giomm/resource.h>
#include <gdkmm/general.h> // set_source_pixbuf()
#include <glibmm/fileutils.h>
#include <iostream>

MyArea::MyArea()
{
  try
  {
    // The fractal image has been created by the XaoS program.
    // http://xaos.sourceforge.net
    m_image = Gdk::Pixbuf::create_from_resource("/image/fractal_image.png");
  }
  catch(const Gio::ResourceError& ex)
  {
    std::cerr << "ResourceError: " << ex.what() << std::endl;
  }
  catch(const Gdk::PixbufError& ex)
  {
    std::cerr << "PixbufError: " << ex.what() << std::endl;
  }

  // Show at least a quarter of the image.
  if (m_image)
  {
    set_content_width(m_image->get_width()/2);
    set_content_height(m_image->get_height()/2);
  }

  // Set the draw function.
  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
}

MyArea::~MyArea()
{
}

void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  if (!m_image)
    return;

  // Draw the image in the middle of the drawing area, or (if the image is
  // larger than the drawing area) draw the middle part of the image.
  Gdk::Cairo::set_source_pixbuf(cr, m_image,
    (width - m_image->get_width())/2, (height - m_image->get_height())/2);
  cr->paint();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>image.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/image">
    <file>fractal_image.png</file>
  </gresource>
</gresources>
]]></code></programlisting>
<!-- end inserted example code -->
        </section>
  </section>
  <!--
  <sect1 id="sec-drawing-fill">
      <title>Gradients and other fill techniques</title>
      <warning>TODO: Add content.</warning>
  </sect1>
  <sect1 id="sec-drawing-transformations">
      <title>Transformations with Cairo</title>
      <warning>TODO: Add content.</warning>
  </sect1>
  -->
  <section xml:id="sec-drawing-clock-example">
  <title>Ukázková aplikace: Kreslení hodin pomocí knihovny Cairo</title>

      <para>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ě.</para>
      <screenshot>
          <mediaobject><imageobject><imagedata format="PNG" fileref="figures/cairo_clock.png"/></imageobject></mediaobject>
      </screenshot>
<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drawingarea/clock">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>clock.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_CLOCK_H
#define GTKMM_EXAMPLE_CLOCK_H

#include <gtkmm/drawingarea.h>

class Clock : public Gtk::DrawingArea
{
public:
  Clock();
  virtual ~Clock();

protected:
  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);

  bool on_timeout();

  double m_radius;
  double m_line_width;
};

#endif // GTKMM_EXAMPLE_CLOCK_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>clock.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <ctime>
#include <cmath>
#include <cairomm/context.h>
#include <glibmm/main.h>
#include "clock.h"

Clock::Clock()
: m_radius(0.42), m_line_width(0.05)
{
  Glib::signal_timeout().connect( sigc::mem_fun(*this, &Clock::on_timeout), 1000 );
  set_draw_func(sigc::mem_fun(*this, &Clock::on_draw));
}

Clock::~Clock()
{
}

void Clock::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
  // scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
  // the center of the window
  cr->scale(width, height);
  cr->translate(0.5, 0.5);
  cr->set_line_width(m_line_width);

  cr->save();
  cr->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
  cr->paint();
  cr->restore();
  cr->arc(0, 0, m_radius, 0, 2 * M_PI);
  cr->save();
  cr->set_source_rgba(1.0, 1.0, 1.0, 0.8);
  cr->fill_preserve();
  cr->restore();
  cr->stroke_preserve();
  cr->clip();

  //clock ticks
  for (int i = 0; i < 12; i++)
  {
    double inset = 0.05;

    cr->save();
    cr->set_line_cap(Cairo::Context::LineCap::ROUND);

    if(i % 3 != 0)
    {
      inset *= 0.8;
      cr->set_line_width(0.03);
    }

    cr->move_to(
      (m_radius - inset) * cos (i * M_PI / 6),
      (m_radius - inset) * sin (i * M_PI / 6));
    cr->line_to (
      m_radius * cos (i * M_PI / 6),
      m_radius * sin (i * M_PI / 6));
    cr->stroke();
    cr->restore(); /* stack-pen-size */
  }

  // store the current time
  time_t rawtime;
  time(&rawtime);
  struct tm * timeinfo = localtime (&rawtime);

  // compute the angles of the indicators of our clock
  double minutes = timeinfo->tm_min * M_PI / 30;
  double hours = timeinfo->tm_hour * M_PI / 6;
  double seconds= timeinfo->tm_sec * M_PI / 30;

  cr->save();
  cr->set_line_cap(Cairo::Context::LineCap::ROUND);

  // draw the seconds hand
  cr->save();
  cr->set_line_width(m_line_width / 3);
  cr->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray
  cr->move_to(0, 0);
  cr->line_to(sin(seconds) * (m_radius * 0.9),
    -cos(seconds) * (m_radius * 0.9));
  cr->stroke();
  cr->restore();

  // draw the minutes hand
  cr->set_source_rgba(0.117, 0.337, 0.612, 0.9);   // blue
  cr->move_to(0, 0);
  cr->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8),
    -cos(minutes + seconds / 60) * (m_radius * 0.8));
  cr->stroke();

  // draw the hours hand
  cr->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
  cr->move_to(0, 0);
  cr->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5),
    -cos(hours + minutes / 12.0) * (m_radius * 0.5));
  cr->stroke();
  cr->restore();

  // draw a little dot in the middle
  cr->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI);
  cr->fill();
}

bool Clock::on_timeout()
{
  // force our program to redraw the entire clock.
  queue_draw();
  return true;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "clock.h"
#include <gtkmm/application.h>
#include <gtkmm/window.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

protected:
  Clock m_clock;
};

ExampleWindow::ExampleWindow()
{
  set_title("Cairomm Clock");
  set_child(m_clock);
}

int main(int argc, char** argv)
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
      <para xml:lang="en">
          As before, almost all of the interesting stuff is done in the draw
          function <methodname>on_draw()</methodname>. Before we dig
          into the draw function, 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.
      </para>
      <para>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.</para>
      <para>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.</para>
      <para>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.</para>
  </section>
</chapter>

<chapter xml:id="chapter-draganddrop">
<title>Táhni a upusť</title>
<para xml:lang="en">
The <classname>Gtk::DragSource</classname> and <classname>Gtk::DropTarget</classname>
event controllers have methods and signals which are used for Drag and Drop.
</para>

<section xml:id="sec-dnd-sources-targets">
<title xml:lang="en">Sources and Targets</title>
<para xml:lang="en">
Things are dragged from <literal>sources</literal> to be dropped on
<literal>targets</literal>. Each source and target has information
about the data formats that it can send or receive, provided by
<classname>Gdk::ContentFormats</classname>. A drop target will only
accept a dragged item if they both share a compatible format. Appropriate
signals will then be emitted, telling the signal handlers which format was used.
</para>
<para xml:lang="en">
<classname>Gdk::ContentFormats</classname> objects contain information about
available <type>GType</type>s and mime types (media types).
</para>

</section>

<section xml:id="sec-dnd-methods">
<title>Metody</title>

<para xml:lang="en">
<classname>Widget</classname>s can be identified as sources or targets using
<classname>Gtk::DragSource</classname> and <classname>Gtk::DropTarget</classname>
event controllers.
</para>
<programlisting xml:lang="en"><code>auto source = Gtk::DragSource::create();
m_source_widget.add_controller(source);</code></programlisting>

<para xml:lang="en">
Some <classname>DragSource</classname> methods:
<itemizedlist>
<listitem>
    <para xml:lang="en">
        <literal>void set_content(const Glib::RefPtr&lt;Gdk::ContentProvider&gt;&amp; content)</literal>:
        Sets a content provider on the drag source.
    </para>
</listitem>
<listitem>
    <para xml:lang="en">
        <literal>void set_actions(Gdk::DragAction actions)</literal>:
        Sets the actions on the drag source. For instance <literal>Gdk::DragAction::COPY
        | Gdk::DragAction::MOVE</literal>.
    </para>
</listitem>
<listitem>
    <para xml:lang="en">
        <literal>void set_icon(const Glib::RefPtr&lt;const Gdk::Paintable&gt;&amp; paintable, int hot_x, int hot_y)</literal>:
        Sets a paintable to use as icon during DND operations.
    </para>
</listitem>
</itemizedlist>
</para>

<programlisting xml:lang="en"><code>auto target = Gtk::DropTarget::create(gtype, actions);
m_target_widget.add_controller(target);</code></programlisting>

<para xml:lang="en">
Some <classname>DropTarget</classname> methods:
<itemizedlist>
<listitem>
    <para xml:lang="en">
        <literal>void set_gtypes(const std::vector&lt;GType&gt;&amp; types)</literal>:
        Sets the supported types for this drop target.
    </para>
</listitem>
<listitem>
    <para xml:lang="en">
        <literal>void set_actions(Gdk::DragAction actions)</literal>:
        Sets the actions that this drop target supports.
    </para>
</listitem>
<listitem>
    <para xml:lang="en">
        <literal>Glib::ValueBase get_value() const</literal>:
        Gets the current drop data, as a <classname>Glib::Value</classname>.
    </para>
</listitem>
<listitem>
    <para xml:lang="en">
        <literal>void reject()</literal>:
        Rejects the ongoing drop operation. This function should be used when
        delaying the decision on whether to accept a drag or not until after
        reading the data. 
    </para>
</listitem>
</itemizedlist>
</para>
</section>

<section xml:id="sec-dnd-signals">
<title>Signály</title>

<para xml:lang="en">
When a drop target 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>Gtk::DragSource::set_actions()</methodname> and
<methodname>Gtk::DropTarget::set_actions()</methodname>.
</para>

<para xml:lang="en">
The source widget will emit these <classname>DragSource</classname> signals:
<itemizedlist>
<listitem><para xml:lang="en"><literal>drag_begin</literal>: Provides a <classname>Gdk::Drag</classname>.</para></listitem>
<listitem><para xml:lang="en"><literal>prepare</literal>: Shall return a <classname>Gdk::ContentProvider</classname>,
  with the data to use for the drag that is about to start.</para></listitem>
<listitem><para xml:lang="en"><literal>drag_end</literal>: Provides a <classname>Gdk::Drag</classname>,
  and a <type>bool</type> that tells if the drag was performing a <literal>move</literal>
  and the data should be deleted.</para></listitem>
<listitem><para xml:lang="en"><literal>drag_cancel</literal>: Emitted on the drag source when a drag has failed.</para></listitem>
</itemizedlist>
</para>
<para xml:lang="en">
The target widget will emit these <classname>DropTarget</classname> signals:
<itemizedlist>
<listitem><para xml:lang="en"><literal>enter</literal>: Provides coordinates.
  Shall return the preferred <type>Gdk::DragAction</type>.</para></listitem>
<listitem><para xml:lang="en"><literal>motion</literal>: Provides coordinates.
  Shall return the preferred <type>Gdk::DragAction</type>.</para></listitem>
<listitem><para xml:lang="en"><literal>leave</literal>: Emitted on the drop site when the pointer
  leaves the widget.</para></listitem>
<listitem><para xml:lang="en"><literal>accept</literal>: Provides a <classname>Gdk::Drop</classname>.
  You can call the <methodname>status()</methodname> method of the
  <classname>Gdk::Drop</classname> to indicate which actions will be accepted.</para></listitem>
<listitem><para xml:lang="en"><literal>drop</literal>: Provides the data being dropped and coordinates.
  Shall return a <type>bool</type> indicating whether the drop was accepted.</para></listitem>
</itemizedlist>
</para>
<para xml:lang="en">
  The following signals call only one signal handler when emitted. When you connect
  a handler to such a signal, your signal handler must be called before (instead of)
  the default handler, otherwise it won't be called. Set the <literal>after</literal>
  parameter in <methodname>connect()</methodname> to <literal>false</literal>.
<itemizedlist>
<listitem><para xml:lang="en"><methodname>Gtk::DragSource::signal_prepare()</methodname></para></listitem>
<listitem><para xml:lang="en"><methodname>Gtk::DropTarget::signal_enter()</methodname></para></listitem>
<listitem><para xml:lang="en"><methodname>Gtk::DropTarget::signal_motion()</methodname></para></listitem>
<listitem><para xml:lang="en"><methodname>Gtk::DropTarget::signal_accept()</methodname></para></listitem>
<listitem><para xml:lang="en"><methodname>Gtk::DropTarget::signal_drop()</methodname></para></listitem>
</itemizedlist>
</para>

</section>

<section xml:id="sec-dnd-example">
<title>Příklad</title>

<para>Zde je velmi jednoduchý příklad předvádějící operaci <literal>kopírování</literal> pomocí tažení a upuštění:</para>

<figure xml:id="figure-drag-and-drop">
  <title>Táhni a upusť</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/drag_and_drop.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/drag_and_drop">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>dndwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_DNDWINDOW_H
#define GTKMM_EXAMPLE_DNDWINDOW_H

#include <gdkmm/drop.h>
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/window.h>
#include <gtkmm/button.h>

class DnDWindow : public Gtk::Window
{

public:
  DnDWindow();
  virtual ~DnDWindow();

protected:
  //Signal handlers:
  Glib::RefPtr<Gdk::ContentProvider> on_label_drag_prepare_data(double x, double y);
  bool on_button_drop_drop_data(const Glib::ValueBase& value, double x, double y);

  //Member widgets:
  Gtk::Box m_HBox;
  Gtk::Label m_Label_Drag;
  Gtk::Button m_Button_Drop;
};

#endif // GTKMM_EXAMPLE_DNDWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>dndwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "dndwindow.h"
#include <gdkmm/contentprovider.h>
#include <gtkmm/dragsource.h>
#include <gtkmm/droptarget.h>
#include <iostream>

DnDWindow::DnDWindow()
: m_Label_Drag("Drag Here\n"),
  m_Button_Drop("Drop here\n")
{
  set_title("DnD example");

  set_child(m_HBox);

  //Drag site:

  //Make m_Label_Drag a DnD drag source:
  auto source = Gtk::DragSource::create();
  source->set_actions(Gdk::DragAction::COPY);
  source->signal_prepare().connect(
    sigc::mem_fun(*this, &DnDWindow::on_label_drag_prepare_data), false);
  m_Label_Drag.add_controller(source);

  m_HBox.append(m_Label_Drag);
  m_Label_Drag.set_expand(true);

  //Drop site:

  //Make m_Button_Drop a DnD drop destination:
  const GType ustring_type = Glib::Value<Glib::ustring>::value_type();
  auto target = Gtk::DropTarget::create(ustring_type, Gdk::DragAction::COPY);
  target->signal_drop().connect(
    sigc::mem_fun(*this, &DnDWindow::on_button_drop_drop_data), false);
  m_Button_Drop.add_controller(target);

  m_HBox.append(m_Button_Drop);
  m_Button_Drop.set_expand(true);
}

DnDWindow::~DnDWindow()
{
}

// In this simple example where just a small amount of data is copied,
// it would be reasonable to store the ContentProvider in the DragSource.
// Then this signal handler would be unnecessary.
Glib::RefPtr<Gdk::ContentProvider> DnDWindow::on_label_drag_prepare_data(double, double)
{
  Glib::Value<Glib::ustring> ustring_value;
  ustring_value.init(ustring_value.value_type());
  ustring_value.set("I'm Data!");
  return Gdk::ContentProvider::create(ustring_value);
}

bool DnDWindow::on_button_drop_drop_data(const Glib::ValueBase& value, double, double)
{
  if (G_VALUE_HOLDS(value.gobj(), Glib::Value<Glib::ustring>::value_type()))
  {
    // We got the value type that we expected.
    Glib::Value<Glib::ustring> ustring_value;
    ustring_value.init(value.gobj());
    const Glib::ustring dropped_string = ustring_value.get();

    std::cout << "Received \"" << dropped_string << "\" in button " << std::endl;
    return true;
  }
  else
  {
    std::cout << "Received unexpected data type \""
      << G_VALUE_TYPE_NAME(value.gobj()) << "\" in button " << std::endl;
    return false;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "dndwindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<DnDWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

<para>V <filename>examples/others/dnd</filename> najdete ucelenější příklad.</para>

</section>

</chapter>

<chapter xml:id="chapter-clipboard">
<title>Schránka</title>

<para>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.</para>

<para xml:lang="en">
You can get a clipboard instance with <methodname>Gtk::Widget::get_clipboard()</methodname>
or <methodname>Gdk::Display::get_clipboard()</methodname>.
</para>

<para xml:lang="en">
Your application doesn't need to wait for clipboard operations, particularly
between the time when the user chooses Copy and then later chooses Paste. Many
<classname>Gdk::Clipboard</classname> methods take <classname>sigc::slot</classname>s
which specify callback methods. When <classname>Gdk::Clipboard</classname> is ready,
it will call these methods, providing the requested data.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGdk_1_1Clipboard.html">Reference</link></para>

<section xml:id="sec-clipboard-formats">
<title xml:lang="en">Formats</title>

<para xml:lang="en">
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>format</literal>s.</para>

<para xml:lang="en">
For instance, <application>gedit</application> can supply and receive the <literal>text/plain</literal> mime type,
so you can paste data into <application>gedit</application> from any application that supplies that format.
Or two different image editing applications might supply and receive a variety of image formats.
As long as one application can receive one of the formats that the other supplies
then you will be able to copy data from one to the other.
</para>

<para xml:lang="en">
Clipboard data 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.
</para>

<para xml:lang="en">The <link linkend="chapter-draganddrop">Drag and Drop</link> API uses the same mechanism.
You should probably use the same data formats for both Clipboard and Drag and Drop operations.</para>
</section>

<section xml:id="sec-clipboard-copy">
<title>Kopírování</title>

<para xml:lang="en">
When the user asks to copy some data, you should copy the data to the
<classname>Clipboard</classname>. For instance,
</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_button_copy()
{
  get_clipboard()-&gt;set_text("example_custom_target");
}</code></programlisting>

</section>

<section xml:id="sec-clipboard-paste">
<title>Vložení</title>

<para>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:</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_button_paste()
{
  get_clipboard()-&gt;read_text_async(sigc::mem_fun(*this,
              &amp;ExampleWindow::on_clipboard_received));
}</code></programlisting>

<para>Zde je příklad metody zpětného volání:</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_clipboard_received(Glib::RefPtr&lt;Gio::AsyncResult&gt;&amp; result)
{
  auto text = get_clipboard()-&gt;read_text_finish(result);
  //Do something with the pasted data.
}</code></programlisting>

<section xml:id="sec-clipboard-discovering-formats">
<title xml:lang="en">Discovering the available formats</title>

<para xml:lang="en">
To find out what formats are currently available on the <classname>Clipboard</classname>
for pasting, call the <methodname>get_formats()</methodname> method. Then call a
<classname>Gdk::ContentFormats</classname> method to find out if a format that
your application supports is available.
</para>
</section>

</section>

<section xml:id="sec-clipboard-examples">
<title>Příklady</title>

<section xml:id="sec-clipboard-example-simple">
<title>Jednoduchý</title>
<para xml:lang="en">
This example allows copy and pasting of application-specific data, using the
standard text format. Although this is simple, it's not ideal because it does
not identify the <classname>Clipboard</classname> data as being of a particular
type.
</para>

<figure xml:id="figure-clipboard-simple">
  <title>Schránka – jednoduchý příklad</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/clipboard_simple.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/clipboard/simple/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_copy();
  void on_button_paste();

  void on_clipboard_text_received(Glib::RefPtr<Gio::AsyncResult>& result);

  Glib::ustring m_strData;

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::Label m_Label;

  Gtk::Grid m_Grid;
  Gtk::ToggleButton m_ButtonA1, m_ButtonA2, m_ButtonB1, m_ButtonB2;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Copy, m_Button_Paste;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Label("Select cells in the grid, click Copy, then open a second "
        "instance of this example to try pasting the copied data."),
  m_ButtonA1("A1"), m_ButtonA2("A2"), m_ButtonB1("B1"), m_ButtonB2("B2"),
  m_Button_Copy("_Copy", /* mnemonic= */ true), m_Button_Paste("_Paste", true)
{
  set_title("Gtk::Clipboard example");

  m_VBox.set_margin(12);
  set_child(m_VBox);

  m_VBox.append(m_Label);

  //Fill Grid:
  m_VBox.append(m_Grid);
  m_Grid.set_expand(true);
  m_Grid.set_row_homogeneous(true);
  m_Grid.set_column_homogeneous(true);
  m_Grid.attach(m_ButtonA1, 0, 0);
  m_Grid.attach(m_ButtonA2, 1, 0);
  m_Grid.attach(m_ButtonB1, 0, 1);
  m_Grid.attach(m_ButtonB2, 1, 1);

  //Add ButtonBox to bottom:
  m_VBox.append(m_ButtonBox);
  m_VBox.set_spacing(6);

  //Fill ButtonBox:
  m_ButtonBox.append(m_Button_Copy);
  m_Button_Copy.set_hexpand(true);
  m_Button_Copy.set_halign(Gtk::Align::END);
  m_Button_Copy.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_copy) );
  m_ButtonBox.append(m_Button_Paste);
  m_Button_Paste.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_paste) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_copy()
{
  //Build a string representation of the stuff to be copied:
  //Ideally you would use XML, with an XML parser here:
  m_strData = m_ButtonA1.get_active() ? "1" : "0";
  m_strData += m_ButtonA2.get_active() ? "1" : "0";
  m_strData += m_ButtonB1.get_active() ? "1" : "0";
  m_strData += m_ButtonB2.get_active() ? "1" : "0";

  // Gdk::Clipboard::set_text() does not take a copy of the text.
  // The text can only be pasted (in this program or in some other program)
  // for as long as it exists.
  get_clipboard()->set_text(m_strData);
}

void ExampleWindow::on_button_paste()
{
  //Tell the clipboard to call our method when it is ready:
  get_clipboard()->read_text_async(sigc::mem_fun(*this,
              &ExampleWindow::on_clipboard_text_received));
}

void ExampleWindow::on_clipboard_text_received(Glib::RefPtr<Gio::AsyncResult>& result)
{
  Glib::ustring text;
  try
  {
    text = get_clipboard()->read_text_finish(result);
  }
  catch (const Glib::Error& err)
  {
    // Print an error about why pasting failed.
    // Usually you probably want to ignore such failures,
    // but for demonstration purposes, we show the error.
    std::cout << "Pasting failed: " << err.what() << std::endl;
  }

  //See comment in on_button_copy() about this silly clipboard format.
  if(text.size() >= 4)
  {
    m_ButtonA1.set_active( text[0] == '1' );
    m_ButtonA2.set_active( text[1] == '1' );
    m_ButtonB1.set_active( text[2] == '1' );
    m_ButtonB2.set_active( text[3] == '1' );
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  // Gio::Application::Flags::NON_UNIQUE because it shall be possible to run
  // several instances of this application simultaneously.
  auto app = Gtk::Application::create(
    "org.gtkmm.example", Gio::Application::Flags::NON_UNIQUE);

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-clipboard-example-ideal">
<title>Ideální</title>
<para xml:lang="en">This is like the simple example, but it
<orderedlist inheritnum="ignore" continuation="restarts">
<listitem><simpara xml:lang="en">Defines a custom clipboard target, though the format is still text.</simpara></listitem>
<listitem><simpara xml:lang="en">It uses the <methodname>Gdk::ContentFormats::signal_changed()</methodname>
  signal and disables the Paste button if it can't use anything on the clipboard.</simpara></listitem>
</orderedlist>
</para>

<figure xml:id="figure-clipboard-ideal">
  <title>Schránka – ideální příklad</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/clipboard_ideal.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/clipboard/ideal/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_copy();
  void on_button_paste();

  void on_clipboard_content_changed();

  void on_clipboard_received(Glib::RefPtr<Gio::AsyncResult>& result);
  void on_clipboard_received_status(Glib::RefPtr<Gio::AsyncResult>& result);

  void update_paste_status(); //Disable the paste button if there is nothing to paste.

  Glib::ustring m_strData;

  //Child widgets:
  Gtk::Box m_VBox;

  Gtk::Label m_Label;

  Gtk::Grid m_Grid;
  Gtk::ToggleButton m_ButtonA1, m_ButtonA2, m_ButtonB1, m_ButtonB2;

  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Copy, m_Button_Paste;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>
#include <string>

namespace
{

const char example_format_custom[] = "gtkmmclipboardexample";

} // anonymous namespace


ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Label("Select cells in the grid, click Copy, then open a second instance "
          "of this example to try pasting the copied data.\nOr try pasting the "
          "text representation into gedit."),
  m_ButtonA1("A1"), m_ButtonA2("A2"), m_ButtonB1("B1"), m_ButtonB2("B2"),
  m_Button_Copy("_Copy", /* mnemonic= */ true), m_Button_Paste("_Paste", true)
{
  set_title("Gtk::Clipboard example");

  m_VBox.set_margin(12);
  set_child(m_VBox);

  m_VBox.append(m_Label);

  //Fill Grid:
  m_VBox.append(m_Grid);
  m_Grid.set_expand(true);
  m_Grid.set_row_homogeneous(true);
  m_Grid.set_column_homogeneous(true);
  m_Grid.attach(m_ButtonA1, 0, 0);
  m_Grid.attach(m_ButtonA2, 1, 0);
  m_Grid.attach(m_ButtonB1, 0, 1);
  m_Grid.attach(m_ButtonB2, 1, 1);

  //Add ButtonBox to bottom:
  m_VBox.append(m_ButtonBox);
  m_VBox.set_spacing(6);

  //Fill ButtonBox:
  m_ButtonBox.append(m_Button_Copy);
  m_Button_Copy.set_hexpand(true);
  m_Button_Copy.set_halign(Gtk::Align::END);
  m_Button_Copy.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_copy) );
  m_ButtonBox.append(m_Button_Paste);
  m_Button_Paste.signal_clicked().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_button_paste) );

  //Connect a signal handler that will be called when the contents of
  //the clipboard change.
  get_clipboard()->signal_changed().connect(sigc::mem_fun(*this,
              &ExampleWindow::on_clipboard_content_changed));

  update_paste_status();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_copy()
{
  //Build a string representation of the stuff to be copied:
  //Ideally you would use XML, with an XML parser here:
  m_strData = example_format_custom;
  m_strData += m_ButtonA1.get_active() ? " A1" : "";
  m_strData += m_ButtonA2.get_active() ? " A2" : "";
  m_strData += m_ButtonB1.get_active() ? " B1" : "";
  m_strData += m_ButtonB2.get_active() ? " B2" : "";

  // Gdk::Clipboard::set_text() does not take a copy of the text.
  // The text can only be pasted (in this program or in some other program)
  // for as long as it exists.
  get_clipboard()->set_text(m_strData);
}

void ExampleWindow::on_button_paste()
{
  //Tell the clipboard to call our method when it is ready:
  get_clipboard()->read_text_async(sigc::mem_fun(*this,
              &ExampleWindow::on_clipboard_received));
}

void ExampleWindow::on_clipboard_content_changed()
{
  update_paste_status();
}

void ExampleWindow::on_clipboard_received(Glib::RefPtr<Gio::AsyncResult>& result)
{
  Glib::ustring text;
  try
  {
    text = get_clipboard()->read_text_finish(result);
  }
  catch (const Glib::Error& err)
  {
    // Print an error about why pasting failed.
    // Usually you probably want to ignore such failures,
    // but for demonstration purposes, we show the error.
    std::cout << "Pasting failed: " << err.what() << std::endl;
  }

  if (text.find(example_format_custom) == 0)
  {
    // It's the expected format.
    m_ButtonA1.set_active(text.find("A1") != std::string::npos);
    m_ButtonA2.set_active(text.find("A2") != std::string::npos);
    m_ButtonB1.set_active(text.find("B1") != std::string::npos);
    m_ButtonB2.set_active(text.find("B2") != std::string::npos);
  }
  else
  {
    // Unexpected format. Disable the Paste button.
    std::cout << "Unexpected pasted text: \"" << text << "\"" << std::endl;
    m_Button_Paste.set_sensitive(false);
  }
}

void ExampleWindow::update_paste_status()
{
  // Disable the paste button if there is nothing to paste.
  get_clipboard()->read_text_async(sigc::mem_fun(*this,
              &ExampleWindow::on_clipboard_received_status));
}

void ExampleWindow::on_clipboard_received_status(Glib::RefPtr<Gio::AsyncResult>& result)
{
  Glib::ustring text;
  try
  {
    text = get_clipboard()->read_text_finish(result);
  }
  catch (const Glib::Error&)
  {
  }

  const bool bPasteIsPossible = text.find(example_format_custom) == 0;

  // Enable/Disable the Paste button appropriately:
  m_Button_Paste.set_sensitive(bPasteIsPossible);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  // Gio::Application::Flags::NON_UNIQUE because it shall be possible to run
  // several instances of this application simultaneously.
  auto app = Gtk::Application::create(
    "org.gtkmm.example", Gio::Application::Flags::NON_UNIQUE);

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-printing">
<title>Tisk</title>

<para>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.</para>

<section xml:id="sec-printoperation">
<title>Tisková operace (PrintOperation)</title>

<para>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.</para>

<section xml:id="sec-printoperation-signals">
<title>Signály</title>

<para xml:lang="en">
The <methodname>PrintOperation::run()</methodname> method starts the print loop,
during which various signals are emitted:

<itemizedlist>
  <listitem>
    <para xml:lang="en">
      <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.
    </para>
  </listitem>

  <listitem>
    <para xml:lang="en">
      <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.
    </para>
  </listitem>

  <listitem>
    <para xml:lang="en">
      For each page that needs to be rendered, the following signals
      are emitted:
      <itemizedlist>
        <listitem>
          <para xml:lang="en">
            <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.
          </para>
        </listitem>

        <listitem>
          <para xml:lang="en">
            <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.
          </para>
        </listitem>
      </itemizedlist>
    </para>
  </listitem>

  <listitem>
    <para xml:lang="en">
      <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.
    </para>
  </listitem>

  <listitem>
    <para xml:lang="en">
      <literal>done</literal>: This signal is emitted when printing is finished, meaning when the
      print data is spooled. Note that the provided
      <literal>Gtk::PrintOperation::Result</literal> may indicate that
      an error occurred. In any case you probably want to notify the user
      about the final status.
    </para>
  </listitem>

  <listitem>
    <para xml:lang="en">
      <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>.
    </para>
  </listitem>
</itemizedlist>

</para>

<para xml:lang="en">
<link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1PrintOperation.html">Reference</link>
</para>

</section>

</section>

<section xml:id="sec-page-setup">
<title>Nastavení stránky</title>

<para>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.</para>
<para>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.</para>

<para>Například</para>
<programlisting xml:lang="en"><code>// Within a class that inherits from Gtk::Window and keeps m_refPageSetup
// and m_refSettings as members...
auto new_page_setup = Gtk::run_page_setup_dialog(*this, m_refPageSetup, m_refSettings);
m_refPageSetup = new_page_setup;
</code></programlisting>

<para xml:lang="en">
<link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1PageSetup.html">Reference</link>
</para>

<para>Systé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>.</para>

</section>

<section xml:id="sec-printing-rendering-text">
<title>Vykreslování textu</title>

<para>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.</para>

<para xml:lang="en">
See <link linkend="sec-printing-examples-simple">an example</link>
of exactly how this can be done.
</para>

</section>

<section xml:id="sec-async-printing-ops">
<title>Asynchronní operace</title>

<para>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.</para>

<para xml:lang="en">
<methodname>run()</methodname> may return
<literal>PrintOperation::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:
</para>

<para>Například</para>
<programlisting xml:lang="en"><code>// in class ExampleWindow's method...
auto 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
</code></programlisting>

<para xml:lang="en">Second, check for an error and connect to the <literal>status_changed</literal> signal. For instance:
</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_printoperation_done(Gtk::PrintOperation::Result result,
  const Glib::RefPtr&lt;PrintOperation&gt;&amp; op)
{
  if (result == Gtk::PrintOperation::Result::ERROR)
    //notify user
  else if (result == Gtk::PrintOperation::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));
}
</code></programlisting>

<para xml:lang="en">Finally, check the status. For instance,</para>
<programlisting xml:lang="en"><code>void ExampleWindow::on_printoperation_status_changed(const Glib::RefPtr&lt;PrintOperation&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
}
</code></programlisting>

</section>

<section xml:id="sec-printing-export-to-pdf">
<title>Export do PDF</title>

<para xml:lang="en">
The '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,
</para>
<programlisting xml:lang="en"><code>auto op = Gtk::PrintOperation::create();
// ...set up op...
op-&gt;set_export_filename("test.pdf");
auto res = op-&gt;run(Gtk::PrintOperation::Action::EXPORT);
</code></programlisting>

</section>

<section xml:id="sec-extending-print-dialog">
<title>Rozšířené dialogové okno tisku</title>

<para xml:lang="en">
You may add a custom tab to the print dialog:

<itemizedlist>
  <listitem>
    <para xml:lang="en">
      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.
    </para>
  </listitem>

  <listitem>
    <para xml:lang="en">
      Get the data from the widgets in the
      <literal>custom_widget_apply</literal> signal handler.
    </para>
  </listitem>
</itemizedlist>
</para>

<para xml:lang="en">
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:
</para>
<programlisting xml:lang="en"><code>Gtk::Widget* CustomPrintOperation::on_create_custom_widget()
{
  set_custom_tab_label("My custom tab");

  auto hbox = new Gtk::Box(Gtk::Orientation::HORIZONTAL, 8);
  hbox-&gt;set_margin(6);

  auto label = Gtk::make_managed&lt;Gtk::Label&gt;("Enter some text: ");
  hbox-&gt;append(*label);

  hbox-&gt;append(m_Entry);

  return hbox;
}

void CustomPrintOperation::on_custom_widget_apply(Gtk::Widget* /* widget */)
{
  auto user_input = m_Entry.get_text();
  //...
}
</code></programlisting>

<para>Prakticky to předvádí příklad v examples/book/printing/advanced.</para>

</section>

<section xml:id="sec-printing-preview">
<title>Náhled</title>

<para xml:lang="en">
The native GTK print dialog has a preview button, but you may also start
a preview directly from an application:</para>

<programlisting xml:lang="en"><code>// in a class that inherits from Gtk::Window...
auto op = PrintOperation::create();
// ...set up op...
op-&gt;run(Gtk::PrintOperation::Action::PREVIEW, *this);
</code></programlisting>

<para xml:lang="en">
On 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 behavior and provide a custom preview dialog. See the example
located in /examples/book/printing/advanced.
</para>

</section>

<section xml:id="sec-printing-printdialog">
<title xml:lang="en">PrintDialog</title>

<para xml:lang="en">
Since <application>gtkmm</application> 4.14 <classname>Gtk::PrintDialog</classname> is an alternative
to <classname>Gtk::PrintOperation</classname>. <classname>PrintDialog</classname>
uses the same <classname>PageSetup</classname> and <classname>PrintSettings</classname>
classes as <classname>PrintOperation</classname>. The rendering with Cairo and
Pango is also similar.
</para>

</section>

<section xml:id="sec-printing-examples">
<title>Příklady</title>

<section xml:id="sec-printing-examples-simple">
<title>Jednoduchý</title>

<para xml:lang="en">
The following example demonstrates how to print some input from a user interface
using <classname>PrintOperation</classname>. 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.
</para>

<figure xml:id="figure-printing-simple">
  <title>Tisk – jednoduchý příklad</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/printing_simple.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/printing/simple/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

// This file is part of the printing/simple and printing/advanced examples

#include <gtkmm.h>

class PrintFormOperation;

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow(const Glib::RefPtr<Gtk::Application>& app);
  virtual ~ExampleWindow();

protected:

  void build_main_menu(const Glib::RefPtr<Gtk::Application>& app);

  void print_or_preview(Gtk::PrintOperation::Action print_action);

  //PrintOperation signal handlers.
  //We handle these so can get necessary information to update the UI or print settings.
  //Our derived PrintOperation class also overrides some default signal handlers.
  void on_printoperation_status_changed();
  void on_printoperation_done(Gtk::PrintOperation::Result result);

  //Action signal handlers:
  void on_menu_file_new();
  void on_menu_file_page_setup();
  void on_menu_file_print_preview();
  void on_menu_file_print();
  void on_menu_file_quit();

  //Printing-related objects:
  Glib::RefPtr<Gtk::PageSetup> m_refPageSetup;
  Glib::RefPtr<Gtk::PrintSettings> m_refSettings;
  Glib::RefPtr<PrintFormOperation> m_refPrintFormOperation;

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Grid m_Grid;

  Gtk::Label m_NameLabel;
  Gtk::Entry m_NameEntry;

  Gtk::Label m_SurnameLabel;
  Gtk::Entry m_SurnameEntry;

  Gtk::Label m_CommentsLabel;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TextView m_TextView;

  Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer;

  Gtk::Label m_Statusbar;

  Glib::RefPtr<Gtk::Builder> m_refBuilder;

  Glib::RefPtr<Gtk::AlertDialog> m_refDialog;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>printformoperation.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_PRINT_FORM_OPERATION_H
#define GTKMM_PRINT_FORM_OPERATION_H

#include <gtkmm.h>
#include <pangomm.h>
#include <vector>

//We derive our own class from PrintOperation,
//so we can put the actual print implementation here.
class PrintFormOperation : public Gtk::PrintOperation
{
 public:
  static Glib::RefPtr<PrintFormOperation> create();
  virtual ~PrintFormOperation();

  void set_name(const Glib::ustring& name) { m_Name = name; }
  void set_comments(const Glib::ustring& comments) { m_Comments = comments; }

 protected:
  PrintFormOperation();

  //PrintOperation default signal handler overrides:
  void on_begin_print(const Glib::RefPtr<Gtk::PrintContext>& context) override;
  void on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& context, int page_nr) override;

  Glib::ustring m_Name;
  Glib::ustring m_Comments;
  Glib::RefPtr<Pango::Layout> m_refLayout;
  std::vector<int> m_PageBreaks; // line numbers where a page break occurs
};

#endif // GTKMM_PRINT_FORM_OPERATION_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include "printformoperation.h"
#include <iostream>

ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
: m_VBox(Gtk::Orientation::VERTICAL),
  m_NameLabel("Name"),
  m_SurnameLabel("Surname"),
  m_CommentsLabel("Comments")
{
  m_refPageSetup = Gtk::PageSetup::create();
  m_refSettings = Gtk::PrintSettings::create();

  set_title("gtkmm Printing Example");
  set_default_size(400, 300);

  set_child(m_VBox);

  build_main_menu(app);

  m_VBox.append(m_Grid);

  //Arrange the widgets inside the grid:
  m_Grid.set_expand(true);
  m_Grid.set_row_spacing(5);
  m_Grid.set_column_spacing(5);
  m_Grid.attach(m_NameLabel, 0, 0);
  m_Grid.attach(m_NameEntry, 1, 0);

  m_Grid.attach(m_SurnameLabel, 0, 1);
  m_Grid.attach(m_SurnameEntry, 1, 1);

  //Add the TextView, inside a ScrolledWindow:
  m_ScrolledWindow.set_child(m_TextView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);

  m_Grid.attach(m_CommentsLabel, 0, 2);
  m_Grid.attach(m_ScrolledWindow, 1, 2);
  m_ScrolledWindow.set_expand(true);

  m_refTextBuffer = Gtk::TextBuffer::create();
  m_TextView.set_buffer(m_refTextBuffer);

  m_Statusbar.set_hexpand(true);
  m_VBox.append(m_Statusbar);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::build_main_menu(const Glib::RefPtr<Gtk::Application>& app)
{
  //Create actions for menus and toolbars:
  auto refActionGroup = Gio::SimpleActionGroup::create();

  //File menu:
  refActionGroup->add_action("new",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new));

  refActionGroup->add_action("pagesetup",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_page_setup));

  refActionGroup->add_action("printpreview",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_print_preview));

  refActionGroup->add_action("print",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_print));

  refActionGroup->add_action("quit",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit));

  insert_action_group("example", refActionGroup);

  // When the menubar is a child of a Gtk::Window, keyboard accelerators are not
  // automatically fetched from the Gio::Menu.
  // See the examples/book/menus/main_menu example for an alternative way of
  // adding the menubar when using Gtk::ApplicationWindow.
  app->set_accel_for_action("example.new", "<Primary>n");
  app->set_accel_for_action("example.print", "<Primary>p");
  app->set_accel_for_action("example.quit", "<Primary>q");

  m_refBuilder = Gtk::Builder::create();

  // Layout the actions in a menubar:
  Glib::ustring ui_menu_info =
    "<interface>"
    "  <menu id='menu-example'>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_File</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_New</attribute>"
    "          <attribute name='action'>example.new</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Page _Setup...</attribute>"
    "          <attribute name='action'>example.pagesetup</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Print Preview</attribute>"
    "          <attribute name='action'>example.printpreview</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Print...</attribute>"
    "          <attribute name='action'>example.print</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Quit</attribute>"
    "          <attribute name='action'>example.quit</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "  </menu>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_menu_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building menus failed: " << ex.what();
  }

  // Layout the actions in a toolbar:
  Glib::ustring ui_toolbar_info =
    "<!-- Generated with glade 3.18.3 and then changed manually -->"
    "<interface>"
      "<object class='GtkBox' id='toolbar'>"
        "<property name='can_focus'>False</property>"
        "<property name='spacing'>3</property>"
        "<child>"
          "<object class='GtkButton' id='toolbutton_new'>"
            "<property name='can_focus'>False</property>"
            "<property name='tooltip_text' translatable='yes'>New</property>"
            "<property name='action_name'>example.new</property>"
            "<property name='icon_name'>document-new</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
        "<child>"
          "<object class='GtkButton' id='toolbutton_print'>"
            "<property name='can_focus'>False</property>"
            "<property name='tooltip_text' translatable='yes'>Print</property>"
            "<property name='action_name'>example.print</property>"
            "<property name='icon_name'>document-print</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
        "<child>"
          "<object class='GtkSeparator' id='separator1'>"
            "<property name='can_focus'>False</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
        "<child>"
          "<object class='GtkButton' id='toolbutton_quit'>"
            "<property name='can_focus'>False</property>"
            "<property name='tooltip_text' translatable='yes'>Quit</property>"
            "<property name='action_name'>example.quit</property>"
            "<property name='icon_name'>application-exit</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
      "</object>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_toolbar_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building toolbar failed: " << ex.what();
  }

  // Get the menubar and add it to a container widget:
  auto object = m_refBuilder->get_object("menu-example");
  auto gmenu = std::dynamic_pointer_cast<Gio::Menu>(object);
  if (!gmenu)
    g_warning("GMenu not found");
  else
  {
    auto pMenuBar = Gtk::make_managed<Gtk::PopoverMenuBar>(gmenu);

    // Add the PopoverMenuBar to the window:
    m_VBox.append(*pMenuBar);
  }

  // Get the toolbar and add it to a container widget:
  auto toolbar = m_refBuilder->get_widget<Gtk::Box>("toolbar");
  if (!toolbar)
    g_warning("toolbar not found");
  else
    m_VBox.append(*toolbar);
}

void ExampleWindow::on_printoperation_status_changed()
{
  Glib::ustring status_msg;

  if (m_refPrintFormOperation->is_finished())
  {
    status_msg = "Print job completed.";
  }
  else
  {
    //You could also use get_status().
    status_msg = m_refPrintFormOperation->get_status_string();
  }

  m_Statusbar.set_text(status_msg);
}

void ExampleWindow::on_printoperation_done(Gtk::PrintOperation::Result result)
{
  //Printing is "done" when the print data is spooled.

  if (result == Gtk::PrintOperation::Result::ERROR)
  {
    if (!m_refDialog)
      m_refDialog = Gtk::AlertDialog::create("Error printing form");
    m_refDialog->show(*this);
  }
  else if (result == Gtk::PrintOperation::Result::APPLY)
  {
    //Update PrintSettings with the ones used in this PrintOperation:
    m_refSettings = m_refPrintFormOperation->get_print_settings();
  }

  if (!m_refPrintFormOperation->is_finished())
  {
    //We will connect to the status-changed signal to track status
    //and update a status bar. In addition, you can, for example,
    //keep a list of active print operations, or provide a progress dialog.
    m_refPrintFormOperation->signal_status_changed().connect(sigc::mem_fun(*this,
                    &ExampleWindow::on_printoperation_status_changed));
  }
}

void ExampleWindow::print_or_preview(Gtk::PrintOperation::Action print_action)
{
  //Create a new PrintOperation with our PageSetup and PrintSettings:
  //(We use our derived PrintOperation class)
  m_refPrintFormOperation = PrintFormOperation::create();

  m_refPrintFormOperation->set_name(m_NameEntry.get_text() + " " + m_SurnameEntry.get_text());
  m_refPrintFormOperation->set_comments(m_refTextBuffer->get_text(false /*Don't include hidden*/));
  // In the printing/advanced example, the font will be set through a custom tab
  // in the print dialog.

  m_refPrintFormOperation->set_track_print_status();
  m_refPrintFormOperation->set_default_page_setup(m_refPageSetup);
  m_refPrintFormOperation->set_print_settings(m_refSettings);

  m_refPrintFormOperation->signal_done().connect(sigc::mem_fun(*this,
                  &ExampleWindow::on_printoperation_done));
  try
  {
    m_refPrintFormOperation->run(print_action /* print or preview */, *this);
  }
  catch (const Gtk::PrintError& ex)
  {
    //See documentation for exact Gtk::PrintError error codes.
    std::cerr << "An error occurred while trying to run a print operation:"
        << ex.what() << std::endl;
  }
}

void ExampleWindow::on_menu_file_new()
{
  //Clear entries and textview:
  m_NameEntry.set_text("");
  m_SurnameEntry.set_text("");
  m_refTextBuffer->set_text("");
  m_TextView.set_buffer(m_refTextBuffer);
}

void ExampleWindow::on_menu_file_page_setup()
{
  //Show the page setup dialog, asking it to start with the existing settings:
  auto new_page_setup =
      Gtk::run_page_setup_dialog(*this, m_refPageSetup, m_refSettings);

  //Save the chosen page setup dialog for use when printing, previewing, or
  //showing the page setup dialog again:
  m_refPageSetup = new_page_setup;
}

void ExampleWindow::on_menu_file_print_preview()
{
  print_or_preview(Gtk::PrintOperation::Action::PREVIEW);
}

void ExampleWindow::on_menu_file_print()
{
  print_or_preview(Gtk::PrintOperation::Action::PRINT_DIALOG);
}

void ExampleWindow::on_menu_file_quit()
{
  set_visible(false);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv, app);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>printformoperation.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "printformoperation.h"

PrintFormOperation::PrintFormOperation()
{
}

PrintFormOperation::~PrintFormOperation()
{
}

Glib::RefPtr<PrintFormOperation> PrintFormOperation::create()
{
  return Glib::make_refptr_for_instance<PrintFormOperation>(new PrintFormOperation());
}

void PrintFormOperation::on_begin_print(
        const Glib::RefPtr<Gtk::PrintContext>& print_context)
{
  //Create and set up a Pango layout for PrintData based on the passed
  //PrintContext: We then use this to calculate the number of pages needed, and
  //the lines that are on each page.
  m_refLayout = print_context->create_pango_layout();

  Pango::FontDescription font_desc("sans 12");
  m_refLayout->set_font_description(font_desc);

  const double width = print_context->get_width();
  const double height = print_context->get_height();

  m_refLayout->set_width(static_cast<int>(width * Pango::SCALE));

  //Set and mark up the text to print:
  Glib::ustring marked_up_form_text;
  marked_up_form_text += "<b>Name</b>: " + m_Name + "\n\n";
  marked_up_form_text += "<b>Comments</b>: " + m_Comments;

  m_refLayout->set_markup(marked_up_form_text);

  //Set the number of pages to print by determining the line numbers
  //where page breaks occur:
  const int line_count = m_refLayout->get_line_count();

  Glib::RefPtr<Pango::LayoutLine> layout_line;
  double page_height = 0;

  for (int line = 0; line < line_count; ++line)
  {
    Pango::Rectangle ink_rect, logical_rect;

    layout_line = m_refLayout->get_line(line);
    layout_line->get_extents(ink_rect, logical_rect);

    const double line_height = logical_rect.get_height() / 1024.0;

    if (page_height + line_height > height)
    {
      m_PageBreaks.push_back(line);
      page_height = 0;
    }

    page_height += line_height;
  }

  set_n_pages(m_PageBreaks.size() + 1);
}

void PrintFormOperation::on_draw_page(
        const Glib::RefPtr<Gtk::PrintContext>& print_context, int page_nr)
{
  //Decide which lines we need to print in order to print the specified page:
  int start_page_line = 0;
  int end_page_line = 0;

  if(page_nr == 0)
  {
    start_page_line = 0;
  }
  else
  {
    start_page_line = m_PageBreaks[page_nr - 1];
  }

  if(page_nr < static_cast<int>(m_PageBreaks.size()))
  {
    end_page_line = m_PageBreaks[page_nr];
  }
  else
  {
    end_page_line = m_refLayout->get_line_count();
  }

  //Get a Cairo Context, which is used as a drawing board:
  Cairo::RefPtr<Cairo::Context> cairo_ctx = print_context->get_cairo_context();

  //We'll use black letters:
  cairo_ctx->set_source_rgb(0, 0, 0);

  //Render Pango LayoutLines over the Cairo context:
  auto iter = m_refLayout->get_iter();

  double start_pos = 0;
  int line_index = 0;

  do
  {
    if(line_index >= start_page_line)
    {
      auto layout_line = iter.get_line();
      auto logical_rect = iter.get_line_logical_extents();
      int baseline = iter.get_baseline();

      if (line_index == start_page_line)
      {
        start_pos = logical_rect.get_y() / 1024.0;
      }

      cairo_ctx->move_to(logical_rect.get_x() / 1024.0,
        baseline / 1024.0 - start_pos);

      layout_line->show_in_cairo_context(cairo_ctx);
    }

    line_index++;
  }
  while(line_index < end_page_line && iter.next_line());
}

]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-printing-examples-printdialog">
<title xml:lang="en">PrintDialog</title>

<para xml:lang="en">
The following example demonstrates how to print some input from a user
interface using <classname>PrintDialog</classname>. The user interface is
similar to the previous example.
</para>

<figure xml:id="figure-printing-printdialog">
  <title xml:lang="en">Printing - PrintDialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/printing_printdialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/printing/print_dialog/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class PrintFormDialog;

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow(const Glib::RefPtr<Gtk::Application>& app);
  ~ExampleWindow() override;

protected:
  void build_main_menu(const Glib::RefPtr<Gtk::Application>& app);

  // Action signal handlers:
  void on_menu_file_new();
  void on_menu_file_print_setup();
  void on_menu_file_print();
  void on_menu_file_quit();

  // Printing-related objects:
  Glib::RefPtr<PrintFormDialog> m_refPrintFormDialog;

  // Child widgets:
  Gtk::Box m_VBox;
  Gtk::Grid m_Grid;

  Gtk::Label m_NameLabel;
  Gtk::Entry m_NameEntry;

  Gtk::Label m_SurnameLabel;
  Gtk::Entry m_SurnameEntry;

  Gtk::Label m_CommentsLabel;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TextView m_TextView;

  Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer;

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
};
#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>printformdialog.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_PRINT_FORM_DIALOG_H
#define GTKMM_PRINT_FORM_DIALOG_H

#include <gtkmm.h>
#include <pangomm.h>
#include <vector>

#define HAS_PRINT_DIALOG GTKMM_CHECK_VERSION(4,13,1)

#if HAS_PRINT_DIALOG
// We derive our own class from PrintDialog,
// so we can put the actual print implementation here.
class PrintFormDialog : public Gtk::PrintDialog
{
public:
  static Glib::RefPtr<PrintFormDialog> create();
  virtual ~PrintFormDialog();

  void set_name(const Glib::ustring& name) { m_Name = name; }
  void set_comments(const Glib::ustring& comments) { m_Comments = comments; }
  void do_setup(Gtk::Window* parent);
  void do_print(Gtk::Window* parent);

protected:
  PrintFormDialog();

  // PrintDialog callback slots:
  void on_setup_finish(const Glib::RefPtr<Gio::AsyncResult>& result);
  void on_print_finish(const Glib::RefPtr<Gio::AsyncResult>& result);
  Cairo::ErrorStatus write_func(const unsigned char* data, unsigned int length,
    Glib::RefPtr<Gio::OutputStream>& stream);
  void do_printing(const Cairo::RefPtr<Cairo::Context>& cairo_ctx);

  Glib::ustring m_Name;
  Glib::ustring m_Comments;
  Glib::RefPtr<Pango::Layout> m_refLayout;
  Glib::RefPtr<Gtk::PrintSetup> m_refPrintSetup;
};
#endif // HAS_PRINT_DIALOG

#endif // GTKMM_PRINT_FORM_DIALOG_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include "printformdialog.h"
#include <iostream>

ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
: m_VBox(Gtk::Orientation::VERTICAL),
  m_NameLabel("Name"),
  m_SurnameLabel("Surname"),
  m_CommentsLabel("Comments")
{
  set_title("gtkmm PrintDialog Example");
  set_default_size(400, 300);

#if HAS_PRINT_DIALOG
  // Create a PrintDialog. (We use our derived PrintDialog class.)
  m_refPrintFormDialog = PrintFormDialog::create();
#endif // HAS_PRINT_DIALOG

  set_child(m_VBox);

  build_main_menu(app);

  m_VBox.append(m_Grid);

  // Arrange the widgets inside the grid:
  m_Grid.set_expand(true);
  m_Grid.set_row_spacing(5);
  m_Grid.set_column_spacing(5);
  m_Grid.attach(m_NameLabel, 0, 0);
  m_Grid.attach(m_NameEntry, 1, 0);

  m_Grid.attach(m_SurnameLabel, 0, 1);
  m_Grid.attach(m_SurnameEntry, 1, 1);

  // Add the TextView, inside a ScrolledWindow:
  m_ScrolledWindow.set_child(m_TextView);

  // Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);

  m_Grid.attach(m_CommentsLabel, 0, 2);
  m_Grid.attach(m_ScrolledWindow, 1, 2);
  m_ScrolledWindow.set_expand(true);

  m_refTextBuffer = Gtk::TextBuffer::create();
  m_TextView.set_buffer(m_refTextBuffer);
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::build_main_menu(const Glib::RefPtr<Gtk::Application>& app)
{
  // Create actions for menus and toolbars:
  auto refActionGroup = Gio::SimpleActionGroup::create();

  // File menu:
  refActionGroup->add_action("new",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new));

  refActionGroup->add_action("printsetup",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_print_setup));

  refActionGroup->add_action("print",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_print));

  refActionGroup->add_action("quit",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit));

  insert_action_group("example", refActionGroup);

  // When the menubar is a child of a Gtk::Window, keyboard accelerators are not
  // automatically fetched from the Gio::Menu.
  // See the examples/book/menus/main_menu example for an alternative way of
  // adding the menubar when using Gtk::ApplicationWindow.
  app->set_accel_for_action("example.new", "<Primary>n");
  app->set_accel_for_action("example.print", "<Primary>p");
  app->set_accel_for_action("example.quit", "<Primary>q");

  m_refBuilder = Gtk::Builder::create();

  // Layout the actions in a menubar:
  Glib::ustring ui_menu_info =
    "<interface>"
    "  <menu id='menu-example'>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_File</attribute>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_New</attribute>"
    "          <attribute name='action'>example.new</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>Print _Setup...</attribute>"
    "          <attribute name='action'>example.printsetup</attribute>"
    "        </item>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Print...</attribute>"
    "          <attribute name='action'>example.print</attribute>"
    "        </item>"
    "      </section>"
    "      <section>"
    "        <item>"
    "          <attribute name='label' translatable='yes'>_Quit</attribute>"
    "          <attribute name='action'>example.quit</attribute>"
    "        </item>"
    "      </section>"
    "    </submenu>"
    "  </menu>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_menu_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building menus failed: " << ex.what();
  }

  // Layout the actions in a toolbar:
  Glib::ustring ui_toolbar_info =
    "<!-- Generated with glade 3.18.3 and then changed manually -->"
    "<interface>"
      "<object class='GtkBox' id='toolbar'>"
        "<property name='can_focus'>False</property>"
        "<property name='spacing'>3</property>"
        "<child>"
          "<object class='GtkButton' id='toolbutton_new'>"
            "<property name='can_focus'>False</property>"
            "<property name='tooltip_text' translatable='yes'>New</property>"
            "<property name='action_name'>example.new</property>"
            "<property name='icon_name'>document-new</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
        "<child>"
          "<object class='GtkButton' id='toolbutton_print'>"
            "<property name='can_focus'>False</property>"
            "<property name='tooltip_text' translatable='yes'>Print</property>"
            "<property name='action_name'>example.print</property>"
            "<property name='icon_name'>document-print</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
        "<child>"
          "<object class='GtkSeparator' id='separator1'>"
            "<property name='can_focus'>False</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
        "<child>"
          "<object class='GtkButton' id='toolbutton_quit'>"
            "<property name='can_focus'>False</property>"
            "<property name='tooltip_text' translatable='yes'>Quit</property>"
            "<property name='action_name'>example.quit</property>"
            "<property name='icon_name'>application-exit</property>"
            "<property name='hexpand'>False</property>"
            "<property name='vexpand'>False</property>"
          "</object>"
        "</child>"
      "</object>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_toolbar_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building toolbar failed: " << ex.what();
  }

  // Get the menubar and add it to a container widget:
  auto object = m_refBuilder->get_object("menu-example");
  auto gmenu = std::dynamic_pointer_cast<Gio::Menu>(object);
  if (!gmenu)
    g_warning("GMenu not found");
  else
  {
    auto pMenuBar = Gtk::make_managed<Gtk::PopoverMenuBar>(gmenu);

    // Add the PopoverMenuBar to the window:
    m_VBox.append(*pMenuBar);
  }

  // Get the toolbar and add it to a container widget:
  auto toolbar = m_refBuilder->get_widget<Gtk::Box>("toolbar");
  if (!toolbar)
    g_warning("toolbar not found");
  else
    m_VBox.append(*toolbar);
}

void ExampleWindow::on_menu_file_new()
{
  // Clear entries and textview:
  m_NameEntry.set_text("");
  m_SurnameEntry.set_text("");
  m_refTextBuffer->set_text("");
  m_TextView.set_buffer(m_refTextBuffer);
}

void ExampleWindow::on_menu_file_print_setup()
{
#if HAS_PRINT_DIALOG
  m_refPrintFormDialog->do_setup(this);
#else
  std::cout << "Gtk::PrintDialog is not available.\n";
#endif // HAS_PRINT_DIALOG
}

void ExampleWindow::on_menu_file_print()
{
#if HAS_PRINT_DIALOG
  m_refPrintFormDialog->set_name(m_NameEntry.get_text() + " " + m_SurnameEntry.get_text());
  m_refPrintFormDialog->set_comments(m_refTextBuffer->get_text(false /*Don't include hidden*/));
  m_refPrintFormDialog->do_print(this);
#else
  std::cout << "Gtk::PrintDialog is not available.\n";
#endif // HAS_PRINT_DIALOG
}

void ExampleWindow::on_menu_file_quit()
{
  set_visible(false);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv, app);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>printformdialog.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "printformdialog.h"
#include <iostream>

#if HAS_PRINT_DIALOG
PrintFormDialog::PrintFormDialog()
{
  set_page_setup(Gtk::PageSetup::create());
  set_print_settings(Gtk::PrintSettings::create());
}

PrintFormDialog::~PrintFormDialog()
{
}

Glib::RefPtr<PrintFormDialog> PrintFormDialog::create()
{
  return Glib::make_refptr_for_instance<PrintFormDialog>(new PrintFormDialog());
}

void PrintFormDialog::do_setup(Gtk::Window* parent)
{
  set_title("Print setup");
  if (parent)
    setup(*parent, sigc::mem_fun(*this, &PrintFormDialog::on_setup_finish));
  else
    setup(sigc::mem_fun(*this, &PrintFormDialog::on_setup_finish));
}

void PrintFormDialog::do_print(Gtk::Window* parent)
{
  set_title("Printing");
  if (parent)
    print(*parent, sigc::mem_fun(*this, &PrintFormDialog::on_print_finish));
  else
    print(sigc::mem_fun(*this, &PrintFormDialog::on_print_finish));
}

void PrintFormDialog::on_setup_finish(const Glib::RefPtr<Gio::AsyncResult>& result)
{
  try
  {
    m_refPrintSetup = setup_finish(result);
    if (m_refPrintSetup)
    {
      set_page_setup(m_refPrintSetup->get_page_setup());
      set_print_settings(m_refPrintSetup->get_print_settings());
    }
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by setup_finish(result).
    std::cout << "No setup selected. " << err.what() << std::endl;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
  }
}

void PrintFormDialog::on_print_finish(const Glib::RefPtr<Gio::AsyncResult>& result)
{
  Glib::RefPtr<Gio::OutputStream> outputStream;
  try
  {
    outputStream = print_finish(result);
  }
  catch (const Gtk::DialogError& err)
  {
    // Can be thrown by print_finish(result).
    std::cout << "No output stream. " << err.what() << std::endl;
    return;
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Unexpected exception. " << err.what() << std::endl;
    return;
  }
  const double paper_width = get_page_setup()->get_paper_width(Gtk::Unit::POINTS);
  const double paper_height = get_page_setup()->get_paper_height(Gtk::Unit::POINTS);
  auto cairo_surface = Cairo::PdfSurface::create_for_stream(
    sigc::bind(sigc::mem_fun(*this, &PrintFormDialog::write_func), outputStream),
    paper_width, paper_height);
  auto cairo_ctx = Cairo::Context::create(cairo_surface);

  do_printing(cairo_ctx);

  // cairo_surface->finish() calls write_func(),
  // which must be done before the stream is closed.
  cairo_surface->finish();
  try
  {
    outputStream->close();
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Error closing stream. " << err.what() << std::endl;
  }
}

Cairo::ErrorStatus PrintFormDialog::write_func(const unsigned char* data,
  unsigned int length, Glib::RefPtr<Gio::OutputStream>& stream)
{
  try
  {
    gsize bytes_written = 0;
    stream->write_all(data, length, bytes_written);
  }
  catch (const Glib::Error& err)
  {
    std::cout << "Error writing to stream. " << err.what() << std::endl;
    return CAIRO_STATUS_WRITE_ERROR;
  }
  return CAIRO_STATUS_SUCCESS;
}
void PrintFormDialog::do_printing(const Cairo::RefPtr<Cairo::Context>& cairo_ctx)
{
  m_refLayout = Pango::Layout::create(cairo_ctx);
  m_refLayout->set_font_description(Pango::FontDescription("sans 12"));

  const auto page_setup = get_page_setup();
  const double page_width = page_setup->get_page_width(Gtk::Unit::POINTS);
  const double page_height = page_setup->get_page_height(Gtk::Unit::POINTS);
  const double left_margin = page_setup->get_left_margin(Gtk::Unit::POINTS);
  const double top_margin = page_setup->get_top_margin(Gtk::Unit::POINTS);
  m_refLayout->set_width(static_cast<int>(page_width * Pango::SCALE));
  m_refLayout->set_wrap(Pango::WrapMode::WORD_CHAR);
  cairo_ctx->translate(left_margin, top_margin);

  // Set and mark up the text to print:
  Glib::ustring marked_up_form_text =
    "<b>Name</b>: " + m_Name + "\n\n" +
    "<b>Comments</b>: " + m_Comments;
  m_refLayout->set_markup(marked_up_form_text);

  // We'll use black letters:
  cairo_ctx->set_source_rgb(0, 0, 0);

  // Render Pango LayoutLines over the Cairo context:
  const double inverse_pango_scale = 1.0 / Pango::SCALE;
  double page_y = 0.0;
  auto iter = m_refLayout->get_iter();
  double start_y_pos = iter.get_line_logical_extents().get_y() * inverse_pango_scale;
  do
  {
    const auto layout_line = iter.get_line();
    const auto logical_rect = iter.get_line_logical_extents();
    const double line_height = logical_rect.get_height() * inverse_pango_scale;

    if (page_y + line_height > page_height)
    {
      // Start a new page.
      cairo_ctx->show_page();
      page_y = 0.0;
      start_y_pos = logical_rect.get_y() * inverse_pango_scale;
    }
    page_y += line_height;

    cairo_ctx->move_to(logical_rect.get_x() * inverse_pango_scale,
      iter.get_baseline() * inverse_pango_scale - start_y_pos);
    layout_line->show_in_cairo_context(cairo_ctx);
  }
  while (iter.next_line());

  cairo_ctx->show_page();
}
#endif // HAS_PRINT_DIALOG
]]></code></programlisting>
<!-- end inserted example code -->

</section>
</section>
</chapter>

<chapter xml:id="chapter-recent-documents">
<title>Nedávno použité dokumenty</title>

  <para xml:lang="en">
    <application>gtkmm</application> provides an easy way to manage recently used documents. This functionality
    is implemented in the <classname>Gtk::RecentManager</classname> class.
  </para>
  <para>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í.</para>

  <section xml:id="sec-recentmanager">
  <title>Správa nedávno použitých (RecentManager)</title>
    <para><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ů.</para>
    <para>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>.</para>

    <section xml:id="recent-files-adding">
    <title>Přidání položek do seznamu nedávných souborů</title>
      <para>Když chcete do seznamu nedávných dokumentů přidat novou položku, v nejjednodušším případě stačí poskytnou adresu URI. Například:</para>
      <programlisting xml:lang="en"><code>auto recent_manager = Gtk::RecentManager::get_default();
recent_manager-&gt;add_item(uri);</code></programlisting>
      <para>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ě:</para>
      <itemizedlist xml:id="list-file-metadata">
        <listitem>
          <para><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.</para>
        </listitem>
        <listitem>
          <para><varname>app_name</varname>: Název aplikace, která registruje prostředky.</para>
        </listitem>
        <listitem>
          <para><varname>description</varname>: Krátký popis prostředku v podobě řetězce kódovaného v UTF-8.</para>
        </listitem>
        <listitem>
          <para><varname>display_name</varname>: Název prostředku v podobě řetězce kódovaného v UTF-8, který se použije k zobrazení.</para>
        </listitem>
        <listitem>
          <para><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.</para>
        </listitem>
        <listitem>
          <para><varname>is_private</varname>:Jestli má být tento prostředek viditelný jen aplikacím, které mají registraci, či nikoliv.</para>
        </listitem>
        <listitem>
          <para><varname>mime_type</varname>: Typ MIME prostředku.</para>
        </listitem>
      </itemizedlist>
      <para>Mimo přidávání položek do seznamu, můžete položky v seznamu také vyhledávat a měnit nebo odebírat.</para>
    </section>

    <section xml:id="recent-files-lookup">
    <title>Vyhledávání položek v seznamu nedávných souborů</title>
      <para>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:</para>
<programlisting xml:lang="en"><code>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
}</code></programlisting>
      <para>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>.</para>
      <para>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:</para>
      <programlisting xml:lang="en"><code>auto info_list = recent_manager-&gt;get_items();</code></programlisting>
      <para>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í.</para>
    </section>

    <section xml:id="recent-files-modifying">
    <title>Změny seznamu nedávných souborů</title>
      <para>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>.</para>
      <para>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>.</para>
      <note>
        <para>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ů.</para>
      </note>
    </section>
  </section>

  <section xml:id="sec-filechooser-filedialog">
  <title xml:lang="en">FileChooser and FileDialog</title>

    <para xml:lang="en">
      <classname>FileChooser</classname> is an interface that can be
      implemented by widgets displaying a list of files.
      <application>gtkmm</application> provides three built-in implementations for choosing recent files
      or other files:
      <classname>FileChooserWidget</classname>,
      <classname>FileChooserDialog</classname>, and
      <classname>FileChooserNative</classname>.
    </para>
    <para xml:lang="en">
      <classname>FileChooserWidget</classname> is a simple widget for
      displaying a list of recently used files or other files.
      <classname>FileChooserWidget</classname> is the basic building block for
      <classname>FileChooserDialog</classname>, but you can embed it into your
      user interface if you want to.
    </para>
    <note><para xml:lang="en"><classname>FileChooser</classname> and the classes that
      implement it are deprecated since <application>gtkmm</application> 4.10. They have been replaced
      by <classname>FileDialog</classname>, which is available since <application>gtkmm</application> 4.10.
    </para></note>

    <section xml:id="recentfiles-example">
    <title xml:lang="en">Simple FileDialog example</title>

      <para xml:lang="en">
        Shown below is a simple example of how to use the
        <classname>FileDialog</classname> class in a program.
        This simple program has a menubar with a
        <guimenuitem>File Dialog</guimenuitem> menu item.
        When you select this menu item, a dialog pops up showing a list of files.
        If you select <guimenuitem>Recent</guimenuitem> in the sidebar,
        the list of recently used files is shown.
      </para>
      <note>
        <para>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.</para>
      </note>
      <para xml:lang="en">
        After selecting the <guimenuitem>File Dialog</guimenuitem> menu
        item and the <guimenuitem>Recent</guimenuitem> sidebar item, you should
        see something similar to the following window.
      </para>
      <screenshot>
          <mediaobject><imageobject><imagedata format="PNG" fileref="figures/recentfiles.png"/></imageobject></mediaobject>
      </screenshot>
<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/recent_files">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow(const Glib::RefPtr<Gtk::Application>& app);
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_menu_file_files_dialog();
  void on_menu_file_quit();
  void on_menu_file_new();
  void on_dialog_finish(Glib::RefPtr<Gio::AsyncResult>& result);

  //Child widgets:
  Gtk::Box m_Box;

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup;

  Glib::RefPtr<Gtk::RecentManager> m_refRecentManager;
  Glib::RefPtr<Gtk::FileDialog> m_refFileDialog;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
: m_Box(Gtk::Orientation::VERTICAL),
  m_refRecentManager(Gtk::RecentManager::get_default())
{
  set_title("Recent files example");
  set_default_size(300, 150);

  //We can put a PopoverMenuBar at the top of the box and other stuff below it.
  set_child(m_Box);

  //Create actions for menus and toolbars:
  m_refActionGroup = Gio::SimpleActionGroup::create();

  //File menu:
  m_refActionGroup->add_action("new",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new));

  //A menu item to open the file dialog:
  m_refActionGroup->add_action("files-dialog",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_files_dialog));

  m_refActionGroup->add_action("quit",
    sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit) );

  insert_action_group("example", m_refActionGroup);


  m_refBuilder = Gtk::Builder::create();

  // When the menubar is a child of a Gtk::Window, keyboard accelerators are not
  // automatically fetched from the Gio::Menu.
  // See the examples/book/menus/main_menu example for an alternative way of
  // adding the menubar when using Gtk::ApplicationWindow.
  app->set_accel_for_action("example.new", "<Primary>n");
  app->set_accel_for_action("example.files-dialog", "<Primary>o");
  app->set_accel_for_action("example.quit", "<Primary>q");

  //Layout the actions in a menubar and a toolbar:
  const char* ui_info =
    "<interface>"
    "  <menu id='menubar'>"
    "    <submenu>"
    "      <attribute name='label' translatable='yes'>_File</attribute>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>_New</attribute>"
    "        <attribute name='action'>example.new</attribute>"
    "        <attribute name='accel'>&lt;Primary&gt;n</attribute>"
    "      </item>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>File _Dialog</attribute>"
    "        <attribute name='action'>example.files-dialog</attribute>"
    "        <attribute name='accel'>&lt;Primary&gt;o</attribute>"
    "      </item>"
    "      <item>"
    "        <attribute name='label' translatable='yes'>_Quit</attribute>"
    "        <attribute name='action'>example.quit</attribute>"
    "        <attribute name='accel'>&lt;Primary&gt;q</attribute>"
    "      </item>"
    "    </submenu>"
    "  </menu>"
    "  <object class='GtkBox' id='toolbar'>"
    "    <property name='can_focus'>False</property>"
    "    <child>"
    "      <object class='GtkButton' id='toolbutton_new'>"
    "        <property name='can_focus'>False</property>"
    "        <property name='tooltip_text' translatable='yes'>New</property>"
    "        <property name='action_name'>example.new</property>"
    "        <property name='icon_name'>document-new</property>"
    "        <property name='hexpand'>False</property>"
    "        <property name='vexpand'>False</property>"
    "      </object>"
    "    </child>"
    "    <child>"
    "      <object class='GtkButton' id='toolbutton_quit'>"
    "        <property name='can_focus'>False</property>"
    "        <property name='tooltip_text' translatable='yes'>Quit</property>"
    "        <property name='action_name'>example.quit</property>"
    "        <property name='icon_name'>application-exit</property>"
    "        <property name='hexpand'>False</property>"
    "        <property name='vexpand'>False</property>"
    "      </object>"
    "    </child>"
    "  </object>"
    "</interface>";

  try
  {
    m_refBuilder->add_from_string(ui_info);
  }
  catch(const Glib::Error& ex)
  {
    std::cerr << "building menubar and toolbar failed: " <<  ex.what();
  }

  //Get the menubar and toolbar widgets, and add them to a container widget:
  auto object = m_refBuilder->get_object("menubar");
  auto gmenu = std::dynamic_pointer_cast<Gio::Menu>(object);
  if (gmenu)
  {
    //Menubar:
    auto pMenubar = Gtk::make_managed<Gtk::PopoverMenuBar>(gmenu);
    m_Box.append(*pMenubar);
  }
  else
    g_warning("GMenu not found");

  auto pToolbar = m_refBuilder->get_widget<Gtk::Box>("toolbar");
  if (pToolbar)
    //Toolbar:
    m_Box.append(*pToolbar);
  else
    g_warning("toolbar not found");
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_menu_file_new()
{
  std::cout << " New File" << std::endl;
}

void ExampleWindow::on_menu_file_quit()
{
  set_visible(false); //Closes the main window to stop the app->make_window_and_run().
}

void ExampleWindow::on_menu_file_files_dialog()
{
  if (!m_refFileDialog)
  {
    m_refFileDialog = Gtk::FileDialog::create();
    m_refFileDialog->set_modal(true);
  }
  m_refFileDialog->open(*this, sigc::mem_fun(*this, &ExampleWindow::on_dialog_finish));
}

void ExampleWindow::on_dialog_finish(Glib::RefPtr<Gio::AsyncResult>& result)
{
  Glib::RefPtr<Gio::File> file;
  try
  {
    file = m_refFileDialog->open_finish(result);
  }
  catch (const Gtk::DialogError& err)
  {
    std::cout << "No file selected, " << err.what() << std::endl;
    return;
  }

  auto selected_uri = file->get_uri();
  std::cout << "URI selected = " << selected_uri << std::endl;
  std::cout << (m_refRecentManager->has_item(selected_uri) ? "A" : "Not a")
    << " recently used file" << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv, app);
}
]]></code></programlisting>
<!-- end inserted example code -->
      <para xml:lang="en">
        The constructor for <classname>ExampleWindow</classname> creates the
        menu and the toolbar using <classname>Builder</classname> (see <xref linkend="chapter-menus-and-toolbars"/> for more information). It then adds
        the menu and the toolbar to the window.
      </para>
    </section>

    <section xml:id="recent-files-filtering">
    <title xml:lang="en">Filtering Files</title>
      <para xml:lang="en">
        For any of the <classname>FileChooser</classname> classes, if you
        don't wish to display all of the items in the list of files, you
        can filter the list to show only those that you want. You can filter
        the list with the help of the <classname>FileFilter</classname> class.
        This class allows you to filter files by their name
        (<methodname>add_pattern()</methodname>), or their mime type
        (<methodname>add_mime_type()</methodname>).
      </para>
      <para xml:lang="en">
        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>FileChooser::add_filter()</methodname> function.
      </para>
    </section>
  </section>
</chapter>

<chapter xml:id="chapter-keyboardevents">
<title xml:lang="en">Keyboard and Mouse Events</title>
  <para xml:lang="en">
    Event signals differ in some ways from other signals. These differences are described
    in the <link linkend="sec-eventsignals">Event signals</link> section in
    the appendix. Here we will use keyboard events and mouse events to show how
    events can be used in a program.
  </para>
  <section xml:id="sec-keyboardevents-overview">
  <title>Přehled</title>

    <para xml:lang="en">
      Whenever you press or release a key, an event is emitted. You can add an
      event controller and connect a signal handler to handle such events.
    </para>
    <para xml:lang="en">
      The event signal handler will receive arguments that depend on the type of event.
      For key press events the arguments are (<type>guint</type> <varname>keyval</varname>,
      <type>guint</type> <varname>keycode</varname>, <type>Gdk::ModifierType</type> <varname>state</varname>).
      As described in the <link linkend="sec-eventsignals">appendix</link>,
      the key press 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>).
    </para>
    <para xml:lang="en">
      To determine which key was pressed or released, you read the value of
      the <varname>keyval</varname> argument and compare it with a constant in the
      <link xlink:href="https://gitlab.gnome.org/GNOME/gtk/tree/main/gdk/gdkkeysyms.h">
      <filename>&lt;gdk/gdkkeysyms.h&gt;</filename></link> header file. The states of
      modifier keys (shift, ctrl, etc.) are available as bit-flags in
      <varname>state</varname>.
    </para>
    <para xml:lang="en">
      Here's a simple example:
    </para>
<programlisting xml:lang="en"><code><![CDATA[
bool MyClass::on_key_pressed(guint keyval, guint, Gdk::ModifierType state)
{
  if (keyval == GDK_KEY_1 &&
    (state & (Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK |
     Gdk::ModifierType::ALT_MASK)) == Gdk::ModifierType::ALT_MASK)
  {
    handle_alt_press();
    return true;
  }
  return false;
}

// in MyClass constructor
auto controller = Gtk::EventControllerKey::create();
controller->signal_key_pressed().connect(
  sigc::mem_fun(*this, &MyClass::on_key_pressed), false);
add_controller(controller);
]]></code></programlisting>

    <section xml:id="keyboardevents-simple-example">
    <title>Příklad</title>

      <para xml:lang="en">
        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.
      </para>

      <figure xml:id="figure-keyboardevents-simple">
        <title>Události klávesnice – jednoduchý příklad</title>
        <screenshot>
          <mediaobject><imageobject><imagedata format="PNG" fileref="figures/events_simple.png"/></imageobject></mediaobject>
        </screenshot>
      </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/events/keyboard_simple/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:

  ExampleWindow();
  virtual ~ExampleWindow();

private:
  // Signal handler:
  bool on_window_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state);

  Gtk::Box m_container;
  Gtk::CheckButton m_first;
  Gtk::CheckButton m_second;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
{
  set_title("Keyboard Events");
  m_container.set_margin(10);
  set_child(m_container);

  // Radio buttons:
  m_first.set_label("First");
  m_second.set_label("Second");

  m_second.set_group(m_first);
  m_first.set_active();

  // Main Container:
  m_container.set_orientation(Gtk::Orientation::HORIZONTAL);
  m_container.append(m_first);
  m_container.append(m_second);

  // Events.
  auto controller = Gtk::EventControllerKey::create();
  controller->signal_key_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_window_key_pressed), false);
  add_controller(controller);
}

bool ExampleWindow::on_window_key_pressed(guint keyval, guint, Gdk::ModifierType state)
{
  //Gdk::ModifierType::ALT_MASK -> the 'Alt' key(mask)
  //GDK_KEY_1 -> the '1' key
  //GDK_KEY_2 -> the '2' key

  //select the first radio button, when we press alt + 1
  if((keyval == GDK_KEY_1) &&
    (state & (Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::ALT_MASK)) == Gdk::ModifierType::ALT_MASK)
  {
    m_first.set_active();
    //returning true, cancels the propagation of the event
    return true;
  }
  else if((keyval == GDK_KEY_2) &&
    (state & (Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::ALT_MASK)) == Gdk::ModifierType::ALT_MASK)
  {
    //and the second radio button, when we press alt + 2
    m_second.set_active();
    return true;
  }
  else if(keyval == GDK_KEY_Escape)
  {
    //close the window, when the 'esc' key is pressed
    set_visible(false);
    return true;
  }

  //the event has not been handled
  return false;
}

ExampleWindow::~ExampleWindow()
{
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
    </section>
  </section>

  <section xml:id="sec-keyboardevents-propagation">
  <title>Propagace události</title>

    <para xml:lang="en">
      As described in the <link linkend="signal-handler-sequence">appendix</link>
      event signals are propagated in 3 phases:
      <orderedlist inheritnum="ignore" continuation="restarts">
      <listitem><simpara xml:lang="en">Capture phase - runs from the toplevel down to the event widget.</simpara></listitem>
      <listitem><simpara xml:lang="en">Target phase - runs only on the event widget.</simpara></listitem>
      <listitem><simpara xml:lang="en">Bubble phase - runs from the event widget up to the toplevel.</simpara></listitem>
      </orderedlist>
    </para>
    <para xml:lang="en">
      A keyboard event is 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 propagated down until it reaches the widget
      which has keyboard focus. The event will then propagate up until it reaches
      the top-level widget, or until you stop the propagation by returning
      <literal>true</literal> from an event handler.
    </para>
    <para>Dejte pozor na to, že po zastavení události nebude už zavolána žádná funkce (i kdyby byla z toho stejného widgetu).</para>

    <section xml:id="keyboardevents-propagation-example">
    <title>Příklad</title>

      <para xml:lang="en">
        In this example there are 9 <classname>EventControllerKey</classname>s,
        3 in each of a <classname>Gtk::Window</classname>, a <classname>Gtk::Box</classname>
        and a <classname>Gtk::Label</classname>. In each of the widgets there is
        one event controller for each propagation phase.
      </para>
      <para>Účelem tohoto příkladu je ukázat kroky, které událost podstoupí, když je vyslána.</para>
      <para xml:lang="en">
        When you write in the label, a key press event will be emitted,
        which will go first, in the capture phase, to the toplevel window
        (<classname>Gtk::Window</classname>), then down to its child, the
        box, then to the box's child, the label with the keyboard focus.
        In the target phase the event goes only to the widget with the keyboard
        focus (the label). In the bubble phase the event goes first to the widget
        with the keyboard focus (the label), then to its parent (the box), then
        to the box's parent (the window). If the event propagates all the way
        down to the label and then up to the window without being stopped,
        the text you're writing will appear in the <classname>Label</classname>
        above the <classname>Label</classname> you're writing in.
      </para>

      <figure xml:id="figure-keyboardevents-propagation">
        <title>Události klávesnice – propagace událostí</title>
        <screenshot>
          <mediaobject><imageobject><imagedata format="PNG" fileref="figures/events_propagation.png"/></imageobject></mediaobject>
        </screenshot>
      </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/events/keyboard_propagation/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EVENT_PROPAGATION_H
#define GTKMM_EVENT_PROPAGATION_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:

  ExampleWindow();
  ~ExampleWindow() override;

private:
  // Signal handlers:
  bool label2_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state, const Glib::ustring& phase);
  bool box_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state, const Glib::ustring& phase);
  bool window_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state, const Glib::ustring& phase);

  bool m_first = true;
  Gtk::Box m_container;
  Gtk::Frame m_frame;
  Gtk::Label m_label1 {"A label"};
  Gtk::Label m_label2 {"Write here"};
  Gtk::CheckButton m_checkbutton_can_propagate_down {"Can propagate down in the capture phase"};
  Gtk::CheckButton m_checkbutton_can_propagate_up {"Can propagate up in the bubble phase"};
};

#endif //GTKMM_EVENT_PROPAGATION_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("Event Propagation");
  m_container.set_margin(10);
  set_child(m_container);

  m_frame.set_child(m_label2);
  m_label2.set_selectable();
  m_checkbutton_can_propagate_down.set_active();
  m_checkbutton_can_propagate_up.set_active();

  // Main container
  m_container.set_orientation(Gtk::Orientation::VERTICAL);
  m_container.append(m_label1);
  m_container.append(m_frame);
  m_container.append(m_checkbutton_can_propagate_down);
  m_container.append(m_checkbutton_can_propagate_up);

  // Event controllers
  const bool after = false; // Run before or after the default signal handlers.

  // Called in the capture phase of the event handling.
  auto controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::label2_key_pressed), "capture"), after);
  m_label2.add_controller(controller);

  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::box_key_pressed), "capture"), after);
  m_container.add_controller(controller);

  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::window_key_pressed), "capture"), after);
  add_controller(controller);

  // Called in the target phase of the event handling.
  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::TARGET);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::label2_key_pressed), "target"), after);
  m_label2.add_controller(controller);

  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::TARGET);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::box_key_pressed), "target"), after);
  m_container.add_controller(controller);

  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::TARGET);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::window_key_pressed), "target"), after);
  add_controller(controller);

  // Called in the bubble phase of the event handling.
  // This is the default, if set_propagation_phase() is not called.
  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::label2_key_pressed), "bubble"), after);
  m_label2.add_controller(controller);

  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::box_key_pressed), "bubble"), after);
  m_container.add_controller(controller);

  controller = Gtk::EventControllerKey::create();
  controller->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
  controller->signal_key_pressed().connect(
    sigc::bind(sigc::mem_fun(*this, &ExampleWindow::window_key_pressed), "bubble"), after);
  add_controller(controller);
}

// By changing the return value we allow, or don't allow, the event to propagate to other elements.
bool ExampleWindow::label2_key_pressed(guint keyval, guint, Gdk::ModifierType, const Glib::ustring& phase)
{
  std::cout << "Label,  " << phase << " phase" << std::endl;

  if (phase == "bubble")
  {
    const gunichar unichar = gdk_keyval_to_unicode(keyval);
    if (unichar != 0)
    {
      if (m_first)
      {
        m_label2.set_label("");
        m_first = false;
      }
      if (unichar == '\b')
        m_label2.set_label("");
      else
      {
        const Glib::ustring newchar(1, unichar);
        m_label2.set_label(m_label2.get_label() + newchar);
      }
    }

    if (!m_checkbutton_can_propagate_up.get_active())
      return true; // Don't propagate
  }
  return false;
}

bool ExampleWindow::box_key_pressed(guint, guint, Gdk::ModifierType, const Glib::ustring& phase)
{
  std::cout << "Box,    " << phase << " phase" << std::endl;

  // Let it propagate
  return false;
}

// This will set the second label's text in the first label every time a key is pressed.
bool ExampleWindow::window_key_pressed(guint, guint, Gdk::ModifierType, const Glib::ustring& phase)
{
  if (phase == "capture")
    std::cout << std::endl;
  std::cout << "Window, " << phase << " phase";

  // Checking if the second label is on focus, otherwise the label would get
  // changed by pressing keys on the window (when the label is not on focus),
  // even if m_checkbutton_can_propagate_up wasn't active.
  if (phase == "bubble" && m_label2.has_focus())
  {
    m_label1.set_label(m_label2.get_label());
    std::cout << ", " << m_label2.get_label();
  }
  std::cout << std::endl;

  if (phase == "capture" && !m_checkbutton_can_propagate_down.get_active())
    return true; // Don't propagate
  return false;
}

ExampleWindow::~ExampleWindow()
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
    </section>
  </section>

  <section xml:id="sec-keyboardevents-mouse">
  <title xml:lang="en">Mouse Events</title>

  <para xml:lang="en">
    Mouse events are similar to keyboard events. There are some differences, though.
    <itemizedlist>
      <listitem><para xml:lang="en">You use <classname>Gtk::GestureClick</classname> instead of
        <classname>Gtk::EventControllerKey</classname>.</para></listitem>
      <listitem><para xml:lang="en">There are other event classes that can be used for handling
        mouse events, for instance <classname>Gtk::EventControllerMotion</classname> and
        <classname>Gtk::EventControllerScroll</classname>.</para></listitem>
      <listitem><para xml:lang="en">Many signal handlers don't return a <literal>bool</literal>.
        You can't stop those events from propagating.</para></listitem>
    </itemizedlist>
  </para>

  <para xml:lang="en">
    The event classes that handle mouse events are also useful for handling
    events from touchscreens. There are also many subclasses of
    <classname>Gtk::EventController</classname> which are only (or mainly) useful
    for touchscreens. Examples: <classname>Gtk::GestureRotate</classname>,
    <classname>Gtk::GestureZoom</classname>, <classname>Gtk::GestureSwipe</classname>,
    <classname>Gtk::GestureLongPress</classname>.
  </para>

  <para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1EventController.html">Reference</link></para>

    <section xml:id="keyboardevents-mouse-example">
    <title>Příklad</title>
      <para xml:lang="en">
        This is an expanded version of the simple keyboard events example.
      </para>

      <figure xml:id="figure-keyboardevents-mouse">
        <title xml:lang="en">Keyboard and Mouse Events</title>
        <screenshot>
          <mediaobject><imageobject><imagedata format="PNG" fileref="figures/events_mouse.png"/></imageobject></mediaobject>
        </screenshot>
      </figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/events/mouse/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

private:
  // Signal handlers:
  void on_window_mouse_pressed(int n_press, double x, double y);
  void on_first_button_mouse_pressed(int n_press, double x, double y);
  void on_second_button_mouse_pressed(int n_press, double x, double y);
  void on_third_button_mouse_pressed(int n_press, double x, double y);
  void on_third_button_clicked();
  void on_mouse_released(int n_press, double x, double y);
  void on_mouse_motion(double x, double y);
  bool on_mouse_scroll(double dx, double dy);
  bool on_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state);

  Gtk::Box m_box;
  Gtk::CheckButton m_first;
  Gtk::CheckButton m_second;
  Gtk::Button m_third;

  Glib::RefPtr<Gtk::GestureClick> m_window_click;
  Glib::RefPtr<Gtk::GestureClick> m_first_button_click;
  Glib::RefPtr<Gtk::GestureClick> m_second_button_click;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <map>
#include <iostream>

namespace
{
std::map<unsigned int, Glib::ustring> mouse_buttons
{
  {0, "No button"},
  {GDK_BUTTON_PRIMARY, "Primary"},
  {GDK_BUTTON_MIDDLE, "Middle"},
  {GDK_BUTTON_SECONDARY, "Secondary"},
};
}

ExampleWindow::ExampleWindow()
: m_first("First"),
  m_second("Second"),
  m_third("Click me")
{
  set_title("Keyboard and Mouse Events");
  m_box.set_margin(10);
  set_child(m_box);

  // Radio buttons
  m_second.set_group(m_first);
  m_first.set_active();

  // Main container
  m_box.set_orientation(Gtk::Orientation::HORIZONTAL);
  m_box.append(m_first);
  m_box.append(m_second);
  m_box.append(m_third);

  // Keyboard events
  auto key_controller = Gtk::EventControllerKey::create();
  key_controller->signal_key_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_key_pressed), false);
  add_controller(key_controller);

  // Mouse events, window
  auto motion_controller = Gtk::EventControllerMotion::create();
  motion_controller->signal_motion().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_mouse_motion));
  add_controller(motion_controller);

  m_window_click = Gtk::GestureClick::create();
  m_window_click->set_button(0); // All mouse buttons
  m_window_click->signal_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_window_mouse_pressed));
  add_controller(m_window_click);

  auto mouse_click = Gtk::GestureClick::create();
  mouse_click->set_button(GDK_BUTTON_PRIMARY);
  mouse_click->signal_released().connect(sigc::mem_fun(*this, &ExampleWindow::on_mouse_released));
  add_controller(mouse_click);

  auto mouse_scroll = Gtk::EventControllerScroll::create();
  mouse_scroll->set_flags(Gtk::EventControllerScroll::Flags::VERTICAL);
  // Handle mouse wheel rotations
  mouse_scroll->signal_scroll().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_mouse_scroll), true);
  add_controller(mouse_scroll);

  // Mouse events, buttons
  m_first_button_click = Gtk::GestureClick::create();
  m_first_button_click->set_button(GDK_BUTTON_PRIMARY);
  m_first_button_click->signal_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_first_button_mouse_pressed));
  m_first.add_controller(m_first_button_click);

  m_second_button_click = Gtk::GestureClick::create();
  m_second_button_click->set_button(GDK_BUTTON_PRIMARY);
  m_second_button_click->signal_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_second_button_mouse_pressed));
  m_second.add_controller(m_second_button_click);

  mouse_click = Gtk::GestureClick::create();
  // This mouse event must be handled in the capture phase.
  // The GtkButton C class handles the event in the capture phase and
  // does not let it propagate to the bubble phase where events are
  // handled by default.
  mouse_click->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
  mouse_click->set_button(GDK_BUTTON_PRIMARY);
  mouse_click->signal_pressed().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_third_button_mouse_pressed));
  m_third.add_controller(mouse_click);
  m_third.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_third_button_clicked));
}

void ExampleWindow::on_window_mouse_pressed(int n_press, double x, double y)
{
  const auto current_button = mouse_buttons[m_window_click->get_current_button()];
  std::cout << "Mouse pressed in window: " << current_button
    << ", " << n_press << ", " << x << ", " << y << std::endl;
}

void ExampleWindow::on_first_button_mouse_pressed(int n_press, double x, double y)
{
  const auto current_button = mouse_buttons[m_first_button_click->get_current_button()];
  std::cout << "Mouse pressed in first button: " << current_button
    << ", " << n_press << ", " << x << ", " << y << std::endl;
}

void ExampleWindow::on_second_button_mouse_pressed(int n_press, double x, double y)
{
  const auto current_button = mouse_buttons[m_second_button_click->get_current_button()];
  std::cout << "Mouse pressed in second button: " << current_button
    << ", " << n_press << ", " << x << ", " << y << std::endl;
}

void ExampleWindow::on_third_button_mouse_pressed(int n_press, double x, double y)
{
  std::cout << "Mouse pressed in third button: "
    << n_press << ", " << x << ", " << y << std::endl;
}

void ExampleWindow::on_third_button_clicked()
{
  std::cout << "Third button clicked" << std::endl;
}

void ExampleWindow::on_mouse_released(int n_press, double x, double y)
{
  std::cout << "Mouse released: " << n_press << ", " << x << ", " << y << std::endl;
}

void ExampleWindow::on_mouse_motion(double x, double y)
{
  std::cout << "Mouse motion: "  << x << ", " << y << std::endl;
}

bool ExampleWindow::on_mouse_scroll(double dx, double dy)
{
  std::cout << "Mouse scroll: "  << dx << ", " << dy << std::endl;
  return true; // handled
}

bool ExampleWindow::on_key_pressed(guint keyval, guint, Gdk::ModifierType state)
{
  // Gdk::ModifierType::ALT_MASK -> the 'Alt' key(mask)
  // GDK_KEY_1 -> the '1' key
  // GDK_KEY_2 -> the '2' key

  // Select the first radio button, when we press Alt + 1
  if ((keyval == GDK_KEY_1) &&
    (state & (Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::ALT_MASK)) == Gdk::ModifierType::ALT_MASK)
  {
    m_first.set_active();
    // Returning true, cancels the propagation of the event
    return true;
  }
  else if ((keyval == GDK_KEY_2) &&
    (state & (Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::ALT_MASK)) == Gdk::ModifierType::ALT_MASK)
  {
    // and the second radio button, when we press Alt + 2
    m_second.set_active();
    return true;
  }
  else if (keyval == GDK_KEY_Escape)
  {
    // Close the window, when the 'Esc' key is pressed
    set_visible(false);
    return true;
  }

  // The event has not been handled
  return false;
}

ExampleWindow::~ExampleWindow()
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->
    </section>
  </section>
</chapter>

<chapter xml:id="chapter-chapter-timeouts">
<title>Časové limity, V/V a funkce při nečinnosti</title>

<section xml:id="sec-timeouts">
<title>Časové limity</title>

<para>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.</para>

<programlisting xml:lang="en"><code>sigc::connection Glib::SignalTimeout::connect(const sigc::slot&lt;bool()&gt;&amp; slot,
                                      unsigned int interval, int priority = Glib::PRIORITY_DEFAULT);
</code></programlisting>

<para>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>:</para>

<programlisting xml:lang="en"><code>my_connection.disconnect();
</code></programlisting>

<para xml:lang="en">
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:
</para>

<programlisting xml:lang="en"><code>bool MyCallback() { std::cout &lt;&lt; "Hello World!\n" &lt;&lt; std::endl; return true; }
</code></programlisting>

<para>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>.</para>

<para>Zde je příklad této techniky:</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/timeout/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>timerexample.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_TIMEREXAMPLE_H
#define GTKMM_EXAMPLE_TIMEREXAMPLE_H

#include <gtkmm.h>
#include <iostream>
#include <map>

class TimerExample : public Gtk::Window
{
public:
  TimerExample();

protected:
  // signal handlers
  void on_button_add_timer();
  void on_button_delete_timer();
  void on_button_quit();

  // This is the callback function the timeout will call
  bool on_timeout(int timer_number);

  // Member data:

  Gtk::Box m_Box;
  Gtk::Button m_ButtonAddTimer, m_ButtonDeleteTimer, m_ButtonQuit;

  // Keep track of the timers being added:
  int m_timer_number;

  // These two constants are initialized in the constructor's member initializer:
  const int count_value;
  const int timeout_value;

  // STL map for storing our connections
  std::map<int, sigc::connection> m_timers;

  // STL map for storing our timer values.
  // Each timer counts back from COUNT_VALUE to 0 and is removed when it reaches 0
  std::map<int, int> m_counters;
};

#endif // GTKMM_EXAMPLE_TIMEREXAMPLE_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "timerexample.h"
#include <gtkmm/application.h>

int main (int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<TimerExample>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>timerexample.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "timerexample.h"

TimerExample::TimerExample() :
  m_Box(Gtk::Orientation::HORIZONTAL, 10),
  m_ButtonAddTimer("_Add", true),
  m_ButtonDeleteTimer("_Remove", true),
  m_ButtonQuit("_Quit", true),
  m_timer_number(0), // start numbering the timers at 0
  count_value(5), // each timer will count down 5 times before disconnecting
  timeout_value(1500) // 1500 ms = 1.5 seconds
{
  m_Box.set_margin(10);
  set_child(m_Box);
  m_Box.append(m_ButtonAddTimer);
  m_Box.append(m_ButtonDeleteTimer);
  m_Box.append(m_ButtonQuit);
  m_ButtonAddTimer.set_expand();
  m_ButtonDeleteTimer.set_expand();
  m_ButtonQuit.set_expand();

  // Connect the three buttons:
  m_ButtonQuit.signal_clicked().connect(sigc::mem_fun(*this,
              &TimerExample::on_button_quit));
  m_ButtonAddTimer.signal_clicked().connect(sigc::mem_fun(*this,
              &TimerExample::on_button_add_timer));
  m_ButtonDeleteTimer.signal_clicked().connect(sigc::mem_fun(*this,
              &TimerExample::on_button_delete_timer));
}

void TimerExample::on_button_quit()
{
  set_visible(false);
}

void TimerExample::on_button_add_timer()
{
  // Creation of a new object prevents long lines and shows us a little
  // how slots work.  We have 0 parameters and bool as a return value
  // after calling sigc::bind.
  sigc::slot<bool()> my_slot = sigc::bind(sigc::mem_fun(*this,
              &TimerExample::on_timeout), m_timer_number);

  // This is where we connect the slot to the Glib::signal_timeout()
  auto conn = Glib::signal_timeout().connect(my_slot,
          timeout_value);

  // Remember the connection:
  m_timers[m_timer_number] = conn;

  // Initialize timer count:
  m_counters[m_timer_number] = count_value + 1;

  // Print some info to the console for the user:
  std::cout << "added timeout " << m_timer_number++ << std::endl;
}

void TimerExample::on_button_delete_timer()
{
  // any timers?
  if(m_timers.empty())
  {
    // no timers left
    std::cout << "Sorry, there are no timers left." << std::endl;
  }
  else
  {
    // get the number of the first timer
    int timer_number = m_timers.begin()->first;

    // Give some info to the user:
    std::cout << "manually disconnecting timer " << timer_number
        << std::endl;

    // Remove the entry in the counter values
    m_counters.erase(timer_number);

    // Diconnect the signal handler:
    m_timers[timer_number].disconnect();

    // Forget the connection:
    m_timers.erase(timer_number);
  }
}

bool TimerExample::on_timeout(int timer_number)
{
  // Print the timer:
  std::cout << "This is timer " << timer_number;

  // decrement and check counter value
  if (--m_counters[timer_number] == 0)
  {
    std::cout << " being disconnected" <<  std::endl;

    // delete the counter entry in the STL MAP
    m_counters.erase(timer_number);

    // delete the connection entry in the STL MAP
    m_timers.erase(timer_number);

    // Note that we do not have to explicitly call disconnect() on the
    // connection since Gtk::Main does this for us when we return false.
    return false;
  }

  // Print the timer value
  std::cout << " - " << m_counters[timer_number] << "/"
      << count_value << std::endl;

 // Keep going (do not disconnect yet):
  return true;
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-monitoring-io">
<title>Sledování V/V</title>

<para>Š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á:</para>

<programlisting xml:lang="en"><code>sigc::connection Glib::SignalIO::connect(const sigc::slot&lt;bool(Glib::IOCondition)&gt;&amp; slot,
                                 Glib::PollFD::fd_t fd, Glib::IOCondition condition,
                                 int priority = Glib::PRIORITY_DEFAULT);
</code></programlisting>

<para>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:</para>

<itemizedlist>
<listitem>
<para xml:lang="en">
Glib::IOCondition::IO_IN - Call your method when there is data ready for
reading on your file descriptor.
</para>
</listitem>
<listitem>
<para xml:lang="en">
Glib::IOCondition::IO_OUT - Call your method when the file descriptor is
ready for writing.
</para>
</listitem>
<listitem>
<para xml:lang="en">
Glib::IOCondition::IO_PRI - Call your method when the file descriptor has urgent data to be read.
</para>
</listitem>
<listitem>
<para xml:lang="en">
Glib::IOCondition::IO_ERR - Call your method when an error has occurred on the file descriptor.
</para>
</listitem>
<listitem>
<para xml:lang="en">
Glib::IOCondition::IO_HUP - Call your method when hung up (the connection has been broken usually for pipes and sockets).
</para>
</listitem>
</itemizedlist>

<para>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ě:</para>

<programlisting xml:lang="en"><code>bool input_callback(Glib::IOCondition condition);
</code></programlisting>

<para xml:lang="en">
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). A lambda expression can
be used, if you don't need the automatic disconnection that <function>sigc::mem_fun()</function>
provides when the object goes out of scope.
</para>

<para>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>.</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/input/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <gtkmm/application.h>
#include <glibmm/main.h>
#include <glibmm/iochannel.h>
#include <fcntl.h>
#include <iostream>

#include <unistd.h> //The SUN Forte compiler puts F_OK here.

//The SUN Forte compiler needs these for mkfifo:
#include <sys/types.h>
#include <sys/stat.h>

Glib::RefPtr<Gtk::Application> app;

int read_fd;
Glib::RefPtr<Glib::IOChannel> iochannel;

/*
  send to the fifo with:
  echo "Hello" > testfifo

  quit the program with:
  echo "Q" > testfifo
*/

// this will be our signal handler for read operations
// it will print out the message sent to the fifo
// and quit the program if the message was 'Q'.
bool MyCallback(Glib::IOCondition io_condition)
{
  if ((io_condition & Glib::IOCondition::IO_IN) != Glib::IOCondition::IO_IN)
  {
    std::cerr << "Invalid fifo response" << std::endl;
  }
  else
  {
   Glib::ustring buf;

   iochannel->read_line(buf);
   std::cout << buf;
   if (buf == "Q\n")
     app->quit();
  }
  return true;
}

int main(int argc, char *argv[])
{
  app = Gtk::Application::create("org.gtkmm.example");

  if (access("testfifo", F_OK) == -1)
  {
    // fifo doesn't exist - create it
    #ifndef DONT_HAVE_MKFIFO
    if (mkfifo("testfifo", 0666) != 0)
    {
      std::cerr << "error creating fifo" << std::endl;
      return -1;
    }
    #else
      std::cerr << "error creating fifo: This platform does not have mkfifo()"
          << std::endl;
    #endif //DONT_HAVE_MKFIFO
  }

  // Although we will only read from the fifo, we open it in read/write mode.
  // Due to a peculiarity with the poll() system call, used deep down in glib,
  // this small program will use all available CPU time, if the fifo is opened
  // as O_RDONLY. See a discussion on the gtkmm-list, e.g.
  // https://mail.gnome.org/archives/gtkmm-list/2015-September/msg00034.html
  // and the link from there to stackoverflow.
  read_fd = open("testfifo", O_RDWR);
  if (read_fd == -1)
  {
    std::cerr << "error opening fifo" << std::endl;
    return -1;
  }

  // connect the signal handler
  Glib::signal_io().connect(
    [](Glib::IOCondition io_condition){ return MyCallback(io_condition); },
    read_fd, Glib::IOCondition::IO_IN);

  // Creates a iochannel from the file descriptor
  iochannel = Glib::IOChannel::create_from_fd(read_fd);

  // and last but not least - run the application main loop
  app->hold(); // keep the application running without a window
  app->run(argc, argv);

  // now remove the temporary fifo
  if(unlink("testfifo"))
    std::cerr << "error removing fifo" << std::endl;

  return 0;
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-idle-functions">
<title>Funkce při nečinnosti</title>

<para>Když chcete určit metodu, která má být zavolána, když se nic jiného neděje, použijte následující:</para>

<programlisting xml:lang="en"><code>sigc::connection  Glib::SignalIdle::connect(const sigc::slot&lt;bool()&gt;&amp; slot,
                                    int priority = Glib::PRIORITY_DEFAULT_IDLE);
</code></programlisting>

<para>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ě:</para>

<programlisting xml:lang="en"><code>bool idleFunc();
</code></programlisting>

<para>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:</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/idle/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>idleexample.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_IDLEEXAMPLE_H
#define GTKMM_EXAMPLE_IDLEEXAMPLE_H

#include <gtkmm.h>
#include <iostream>

class IdleExample : public Gtk::Window
{
public:
  IdleExample();

protected:
  // Signal Handlers:
  bool on_timer();
  bool on_idle();
  void on_button_clicked();

  // Member data:
  Gtk::Box m_Box;
  Gtk::Button m_ButtonQuit;
  Gtk::ProgressBar m_ProgressBar_c;
  Gtk::ProgressBar m_ProgressBar_d;
};

#endif // GTKMM_EXAMPLE_IDLEEXAMPLE_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>idleexample.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "idleexample.h"

IdleExample::IdleExample() :
  m_Box(Gtk::Orientation::VERTICAL, 5),
  m_ButtonQuit("_Quit", true)
{
  m_Box.set_margin(5);

  // Put buttons into container

  // Adding a few widgets:
  set_child(m_Box);
  m_Box.append(*Gtk::make_managed<Gtk::Label>("Formatting Windows drive C:"));
  m_Box.append(*Gtk::make_managed<Gtk::Label>("100 MB"));
  m_Box.append(m_ProgressBar_c);
  m_ProgressBar_c.set_expand();

  m_Box.append(*Gtk::make_managed<Gtk::Label>(""));

  m_Box.append(*Gtk::make_managed<Gtk::Label>("Formatting Windows drive D:"));
  m_Box.append(*Gtk::make_managed<Gtk::Label>("5000 MB"));
  m_Box.append(m_ProgressBar_d);
  m_ProgressBar_d.set_expand();

  auto hbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL,10);
  m_Box.append(*hbox);
  hbox->append(m_ButtonQuit);
  m_ButtonQuit.set_expand();
  m_ButtonQuit.set_halign(Gtk::Align::END);
  m_ButtonQuit.set_valign(Gtk::Align::END);

  // Connect the signal handlers:
  m_ButtonQuit.signal_clicked().connect( sigc::mem_fun(*this,
              &IdleExample::on_button_clicked) );

  // formatting drive c in timeout signal handler - called once every 50ms
  Glib::signal_timeout().connect( sigc::mem_fun(*this, &IdleExample::on_timer),
          50 );

  // formatting drive d in idle signal handler - called as quickly as possible
  Glib::signal_idle().connect( sigc::mem_fun(*this, &IdleExample::on_idle) );
}


void IdleExample::on_button_clicked()
{
  set_visible(false);
}

// this timer callback function is executed once every 50ms (set in connection
// above).  Use timeouts when speed is not critical. (ie periodically updating
// something).
bool IdleExample::on_timer()
{
  double value = m_ProgressBar_c.get_fraction();

  // Update progressbar 1/500th each time:
  m_ProgressBar_c.set_fraction(value + 0.002);

  return value < 0.99;  // return false when done
}


// This idle callback function is executed as often as possible, hence it is
// ideal for processing intensive tasks.
bool IdleExample::on_idle()
{
  double value = m_ProgressBar_d.get_fraction();

  // Update progressbar 1/5000th each time:
  m_ProgressBar_d.set_fraction(value + 0.0002);

  return value < 0.99;  // return false when done
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "idleexample.h"
#include <gtkmm/application.h>

int main (int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  return app->make_window_and_run<IdleExample>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

<para>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>.</para>

<para>Zkuste příklad spustit a zvýšit zátěž systému. Horní ukazatel průběhu bude nabývat rovnoměrně, dolní se zpomalí.</para>

</section>

</chapter>

<chapter xml:id="chapter-memory">
<title>Správa paměti</title>

<section xml:id="sec-memory-widgets">
<title>Widgety</title>

<section xml:id="memory-normal">
<title>Normální správa paměti v C++</title>

<para><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++.</para>
<para xml:lang="en">
An important difference in <application>gtkmm</application>-4.0 vs. older versions is that a C++ widgetʼs
destruction no longer causes the widget to be destroyed if itʼs within a parent;
in that case the C GtkWidget stays alive. If you had relied on that behavior in
an older version, in <application>gtkmm</application>-4.0 you must now remove the widget from its parent
first. See <link linkend="changes-gtkmm4">Changes in <application>gtkmm</application>-4.0</link>.
</para>
<para>Zde je nějaký příklad normální správy paměti v C++:</para>

<section xml:id="memory-class-scope">
<title>Widgety v rozsahu působnosti třídy</title>
<para>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.</para>
<para>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.</para>
<programlisting xml:lang="en"><code>#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
};
</code></programlisting>
</section>

<section xml:id="memory-function-scope">
<title>Widgety v rozsahu působnosti funkce</title>
<para xml:lang="en">
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.
</para>
<programlisting xml:lang="en"><code>{
  Gtk::Button aButton;
  aButton.set_visible(true);
  ...
  app-&gt;run();
}
</code></programlisting>
<para xml:lang="en">
However, this technique is rarely useful. Most widgets can't safely be created
before the application has been registered or activated. They can't safely be
deleted after <methodname>Gtk::Application::run()</methodname> or
<methodname>Gtk::Application::make_window_and_run()</methodname> returns.
</para>

</section>

<section xml:id="memory-dynamic-allocation">
<title>Dynamická alokace pomocí new a delete</title>
<para xml:lang="en">
Usually, the programmer will prefer to allow containers to automatically destroy
their children by creating them using <function>Gtk::make_managed()</function>
(see below). This is not strictly required, as the <literal>new</literal> and
<literal>delete</literal> operators may also be used, but modern C++ style
discourages those in favor of safer models of memory management, so it is
better to create widgets using <function>Gtk::make_managed()</function> and
let their parent destroy them, than to manually perform dynamic allocation.
</para>
<programlisting xml:lang="en"><code>auto pButton = new Gtk::Button("Test");
// do something useful with pButton
delete pButton;
</code></programlisting>
<para xml:lang="en">Here, the programmer deletes <varname>pButton</varname> to prevent a memory leak.
</para>
</section>

</section>

<section xml:id="memory-managed-widgets">
<title>Widgety pod správou</title>

<para xml:lang="en">
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, create it with <function>Gtk::make_managed()</function> and then
pack it into its container with <methodname>Gtk::Box::append()</methodname> or
a similar method. Now the widget will be destroyed whenever its container is destroyed.
</para>

<section xml:id="memory-managed-dynamic">
<title xml:lang="en">Dynamic allocation with make_managed() and append()</title>

<para xml:lang="en">
<application>gtkmm</application> provides ways including the <function>make_managed()</function> function
and <methodname>Gtk::Box::append()</methodname> method to simplify creation
and destruction of widgets whose lifetime can be managed by a parent.
</para>

<para xml:lang="en">
Every widget except a top-level window must be added to a parent container in
order to be displayed. The <function>manage()</function> function marks a widget
so that when that widget is added to a parent container, said container becomes
responsible for deleting the widget, meaning the user no longer needs to do so.
The original way to create widgets whose lifetime is managed by their parent in
this way was to call <function>manage()</function>, passing in the result of a
<literal>new</literal> expression that created a dynamically allocated widget.
</para>

<para xml:lang="en">
However, usually, when you create such a widget, you will already know that its
parent container should be responsible for destroying it. In addition, modern
C++ style discourages use of the <literal>new</literal> operator, which was
required when passing a newly created widget to <function>manage()</function>.
Therefore, <application>gtkmm</application> has added <function>make_managed()</function>, which combines
creation and marking with <function>manage()</function> into a single step. This
avoids you having to write <literal>new</literal>, which is discouraged in
modern C++ style, and more clearly expresses intent to create a managed widget.
</para>

<programlisting xml:lang="en"><code>MyContainer::MyContainer()
{
  auto pButton = Gtk::make_managed&lt;Gtk::Button&gt;("Test");
  append(*pButton); //add *pButton to MyContainer
}
</code></programlisting>
<para xml:lang="en">
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.
</para>

<para xml:lang="en">
If you never added the widget to any parent container, it's your responsibility
to delete it. If you add it to a container widget, and later
remove it (for instance with <methodname>Gtk::Box::remove()</methodname>),
it's deleted by the container.
</para>

<para xml:lang="en">
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. Or you can let <methodname>Gtk::Application::make_window_and_run()</methodname>
create a top-level window and delete it when it's hidden.
</para>

</section>
</section>
</section>

<section xml:id="sec-memory-shared-resources">
<title>Sdílené prostředky</title>

<para>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>.</para>

<para xml:lang="en">
Objects such as <classname>Gdk::Pixbuf</classname> can only be instantiated
with a <methodname>create()</methodname> function. For instance,
</para>
<programlisting xml:lang="en"><code>auto pixbuf = Gdk::Pixbuf::create_from_file(filename);
</code></programlisting>

<para xml:lang="en">
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:
</para>
<programlisting xml:lang="en"><code>auto width = 0;
if(pixbuf)
{
  width = pixbuf-&gt;get_width();
}
</code></programlisting>

<para>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>.</para>
<para xml:lang="en">
If you copy a <classname>RefPtr</classname>, for instance</para>
<programlisting xml:lang="en"><code>auto pixbuf2 = pixbuf;
</code></programlisting>
<para xml:lang="en">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.
</para>
<para>Podrobné informace o RefPtr viz <link linkend="chapter-refptr">dodatek</link>.</para>
<para xml:lang="en">
If you wish to learn more about smartpointers, you might look in these
books:
<itemizedlist>
<listitem><para xml:lang="en">
Bjarne Stroustrup, "The C++ Programming Language" Fourth Edition - section 34.3
</para></listitem>
<listitem><para xml:lang="en">
Nicolai M. Josuttis, "The C++ Standard Library" - section 4.2
</para></listitem>
</itemizedlist>
</para>

</section>

</chapter>

<chapter xml:id="chapter-builder">
<title xml:lang="en">Gtk::Builder</title>

<para xml:lang="en">
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 <link xlink:href="https://gitlab.gnome.org/jpu/cambalache">Cambalache</link>
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.
</para>

<para xml:lang="en">
This has the following advantages:
<orderedlist inheritnum="ignore" continuation="restarts">
<listitem><simpara xml:lang="en">Less C++ code is required.</simpara></listitem>
<listitem><simpara xml:lang="en">UI changes can be seen more quickly, so UIs are able to improve.</simpara></listitem>
<listitem><simpara xml:lang="en">Designers without programming skills can create and edit UIs.</simpara></listitem>
</orderedlist>
</para>

<para>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ě.</para>

<para xml:lang="en">
<application>Cambalache</application> replaces the <application>Glade</application>
application. <application>Glade</application> can generate XML files to be used
with gtk3/<application>gtkmm</application>3, but it does not support gtk4/<application>gtkmm</application>4.
</para>

<section xml:id="sec-builder-loading-ui-file">
<title xml:lang="en">Loading the .ui file</title>

<para xml:lang="en">
<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,</para>
<programlisting xml:lang="en"><code>auto builder = Gtk::Builder::create_from_file("basic.ui");
</code></programlisting>
<para xml:lang="en">This will instantiate the windows defined in the <filename class="extension">.ui</filename> file.
</para>

<para xml:lang="en">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,
</para>
<programlisting xml:lang="en"><code>auto builder = Gtk::Builder::create_from_file("basic.ui", "treeview_products");
</code></programlisting>

</section>

<section xml:id="sec-builder-accessing-widgets">
<title>Přístup k widgetům</title>

<para xml:lang="en">
To access a widget, for instance to show a dialog, use
the <methodname>get_widget()</methodname> method, providing the widget's name.
This name should be specified in the <application>Cambalache</application>
window. If the widget could not be found, or is of the wrong type, then the
pointer will be set to <literal>nullptr</literal>.
</para>
<para xml:lang="en">
The dialogs in this chapter are derived from <classname>Gtk::Window</classname>
because <classname>Gtk::Dialog</classname> is deprecated since <application>gtkmm</application> 4.10.
</para>
<programlisting xml:lang="en"><code>auto pDialog = builder-&gt;get_widget&lt;Gtk::Window&gt;("DialogBasic");
</code></programlisting>

<para xml:lang="en">
<classname>Gtk::Builder</classname> 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.
</para>

<para>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>.</para>

<para xml:lang="en">
<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. <classname>Window</classname>s (such as <classname>Dialog</classname>s)
cannot be managed because they have no parent container, so you must delete them at
some point. The documentation of <classname>Gtk::Builder</classname> has more to say
about the memory management of different kinds of objects.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Builder.html">Reference</link></para>

<section xml:id="builder-example-basic">
<title>Příklad</title>

<para xml:lang="en">
This simple example shows how to load a <filename class="extension">.ui</filename>
file at runtime and access the widgets with <classname>Gtk::Builder</classname>.
</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/builder/basic">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include <gtkmm.h>
#include <iostream>

namespace
{
Gtk::Window* pDialog = nullptr;
Glib::RefPtr<Gtk::Application> app;

void on_button_clicked()
{
  if (pDialog)
    pDialog->set_visible(false); // set_visible(false) will cause Gtk::Application::run() to end.
}

void on_app_activate()
{
  // Load the GtkBuilder file and instantiate its widgets:
  auto refBuilder = Gtk::Builder::create();
  try
  {
    refBuilder->add_from_file("basic.ui");
  }
  catch(const Glib::FileError& ex)
  {
    std::cerr << "FileError: " << ex.what() << std::endl;
    return;
  }
  catch(const Glib::MarkupError& ex)
  {
    std::cerr << "MarkupError: " << ex.what() << std::endl;
    return;
  }
  catch(const Gtk::BuilderError& ex)
  {
    std::cerr << "BuilderError: " << ex.what() << std::endl;
    return;
  }

  // Get the GtkBuilder-instantiated dialog:
  pDialog = refBuilder->get_widget<Gtk::Window>("DialogBasic");
  if (!pDialog)
  {
    std::cerr << "Could not get the dialog" << std::endl;
    return;
  }

  // Get the GtkBuilder-instantiated button, and connect a signal handler:
  auto pButton = refBuilder->get_widget<Gtk::Button>("quit_button");
  if (pButton)
    pButton->signal_clicked().connect([] () { on_button_clicked(); });

  // It's not possible to delete widgets after app->run() has returned.
  // Delete the dialog with its child widgets before app->run() returns.
  pDialog->signal_hide().connect([] () { delete pDialog; });

  app->add_window(*pDialog);
  pDialog->set_visible(true);
}
} // anonymous namespace

int main(int argc, char** argv)
{
  app = Gtk::Application::create("org.gtkmm.example");

  // Instantiate a dialog when the application has been activated.
  // This can only be done after the application has been registered.
  // It's possible to call app->register_application() explicitly, but
  // usually it's easier to let app->run() do it for you.
  app->signal_activate().connect([] () { on_app_activate(); });

  return app->run(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

<section xml:id="sec-builder-using-derived-widgets">
<title>Používání odvozených widgetů</title>

<para xml:lang="en">
You can use <application>Cambalache</application> and
<classname>Gtk::Builder</classname> to layout your own custom widgets
derived from <application>gtkmm</application> widget classes. This keeps your code organized and
encapsulated, separating declarative presentation from business logic, avoiding
having most of your source just be setting properties and packing in containers.
</para>

<para xml:lang="en">Use <methodname>Gtk::Builder::get_widget_derived()</methodname> like so:
</para>
<programlisting xml:lang="en"><code>auto pDialog = Gtk::Builder::get_widget_derived&lt;DerivedDialog&gt;(builder, "DialogDerived");
</code></programlisting>

<para xml:lang="en">
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::Window</classname>
typedefs <classname>BaseObjectType</classname> as <type>GtkWindow</type>, for instance).
</para>
<para xml:lang="en">
You must call the base class's constructor in the initialization list, providing the C pointer. For
instance,
</para>
<programlisting xml:lang="en"><code>DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Gtk::Window(cobject)
{
}
</code></programlisting>

<para xml:lang="en">
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,
</para>
<programlisting xml:lang="en"><code>DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Gtk::Window(cobject),
  m_builder(builder),
  // Get the GtkBuilder-instantiated Button, and connect a signal handler:
  m_pButton(m_builder-&gt;get_widget&lt;Gtk::Button&gt;("quit_button"))
{
  if (m_pButton)
  {
    m_pButton-&gt;signal_clicked().connect( sigc::mem_fun(*this, &amp;DerivedDialog::on_button_quit) );
  }
}
</code></programlisting>

<para xml:lang="en">
It's possible to pass additional arguments from
<methodname>get_widget_derived()</methodname> to the constructor of the derived
widget. For instance, this call to <methodname>get_widget_derived()</methodname>
</para>
<programlisting xml:lang="en"><code>auto pDialog = Gtk::Builder::get_widget_derived&lt;DerivedDialog&gt;(builder, "DialogDerived", true);
</code></programlisting>
<para xml:lang="en">can invoke this constructor
</para>
<programlisting xml:lang="en"><code>DerivedDialog::DerivedDialog(BaseObjectType* cobject,
  const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder, bool warning)
: Gtk::Window(cobject),
  m_builder(builder),
  m_pButton(m_builder-&gt;get_widget&lt;Gtk::Button&gt;("quit_button"))
{
  // ....
}
</code></programlisting>

<section xml:id="sec-builder-and-property">
<title xml:lang="en">Gtk::Builder and Glib::Property</title>

<para xml:lang="en">
If your derived widget uses <classname>Glib::Property</classname>, it becomes slightly
more complicated. A derived widget that contains <classname>Glib::Property</classname>
members must be registered with its own name in the <type>GType</type> system.
It must be registered before any of the <methodname>create_from_*()</methodname> or
<methodname>add_from_*()</methodname> methods are called, meaning that you may have
to create an instance of your derived widget just to have its class registered.
Your derived widget must have a constructor that has the parameters required by
<methodname>get_widget_derived()</methodname> and calls the <classname>Glib::ObjectBase</classname>
constructor to register the <type>GType</type>.
</para>
<programlisting xml:lang="en"><code>DerivedButton::DerivedButton(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Glib::ObjectBase("MyButton"), // The GType name will be gtkmm__CustomObject_MyButton.
  Gtk::Button(cobject),
  prop_ustring(*this, "button-ustring"),
  prop_int(*this, "button-int", 10)
{
  // ....
}
</code></programlisting>
<para xml:lang="en">
It is possible also to specify properties of derived widgets, declared in C++
using <application>gtkmm</application>, within <filename class="extension">.ui</filename> files and load/set
these using <classname>Gtk::Builder</classname>. See the documentation of
<classname>Gtk::Builder</classname> for more details on how to achieve this.
<application>Cambalache</application> won’t recognize such properties as-is,
but you should be able to add a few lines of hand-coded XML to the XML code
generated by <application>Cambalache</application>.
</para>
</section>

<section xml:id="builder-example-derived">
<title>Příklad</title>

<para xml:lang="en">
This example shows how to load a <filename class="extension">.ui</filename> file
at runtime and access the widgets via derived classes.
</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/builder/derived">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>derivedbutton.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_DERIVED_BUTTON_H
#define GTKMM_EXAMPLE_DERIVED_BUTTON_H

#include <gtkmm.h>

class DerivedButton : public Gtk::Button
{
public:
  DerivedButton();
  DerivedButton(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder);
  virtual ~DerivedButton();

  // Provide proxies for the properties. The proxy allows you to connect to
  // the 'changed' signal, etc.
  Glib::PropertyProxy<Glib::ustring> property_ustring() { return prop_ustring.get_proxy(); }
  Glib::PropertyProxy<int> property_int() { return prop_int.get_proxy(); }

private:
  Glib::Property<Glib::ustring> prop_ustring;
  Glib::Property<int> prop_int;
};

#endif //GTKMM_EXAMPLE_DERIVED_BUTTON_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>deriveddialog.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_DERIVED_DIALOG_H
#define GTKMM_EXAMPLE_DERIVED_DIALOG_H

#include <gtkmm.h>
#include "derivedbutton.h"

class DerivedDialog : public Gtk::Window
{
public:
  DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder);
  DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder,
    bool is_glad);
  ~DerivedDialog() override;

protected:
  //Signal handlers:
  void on_button_quit();

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  DerivedButton* m_pButton;
};

#endif //GTKMM_EXAMPLE_DERIVED_DIALOG_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>derivedbutton.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "derivedbutton.h"
#include <iostream>

// For creating a dummy object in main.cc.
DerivedButton::DerivedButton()
: Glib::ObjectBase("MyButton"),
  prop_ustring(*this, "button-ustring"),
  prop_int(*this, "button-int", 10)
{
}

DerivedButton::DerivedButton(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& /* refBuilder */)
: // To register custom properties, you must register a custom GType.  If
  // you don't know what that means, don't worry, just remember to add
  // this Glib::ObjectBase constructor call to your class' constructor.
  // The GType name will be gtkmm__CustomObject_MyButton.
  Glib::ObjectBase("MyButton"),
  Gtk::Button(cobject),
  // register the properties with the object and give them names
  prop_ustring(*this, "button-ustring"),
  // this one has a default value
  prop_int(*this, "button-int", 10)
{
  // Register some handlers that will be called when the values of the
  // specified parameters are changed.
  property_ustring().signal_changed().connect(
    [](){ std::cout << "- ustring property changed!" << std::endl; }
  );
  property_int().signal_changed().connect(
    [](){ std::cout << "- int property changed!" << std::endl; }
  );
}

DerivedButton::~DerivedButton()
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>deriveddialog.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "deriveddialog.h"
#include <iostream>

DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::Window(cobject),
  m_refBuilder(refBuilder),
  m_pButton(nullptr)
{
  // Get the GtkBuilder-instantiated Button, and connect a signal handler:
  m_pButton = Gtk::Builder::get_widget_derived<DerivedButton>(m_refBuilder, "quit_button");
  if (m_pButton)
  {
    m_pButton->signal_clicked().connect( sigc::mem_fun(*this, &DerivedDialog::on_button_quit) );
    std::cout << "ustring, int: " << m_pButton->property_ustring()
              << ", " << m_pButton->property_int() << std::endl;
    m_pButton->property_int() = 99;
    std::cout << "ustring, int: " << m_pButton->property_ustring()
              << ", " << m_pButton->property_int() << std::endl;
  }
}

// The first two parameters are mandatory in a constructor that will be called
// from Gtk::Builder::get_widget_derived().
// Additional parameters, if any, correspond to additional arguments in the call
// to Gtk::Builder::get_widget_derived().
DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder,
  bool is_glad)
: DerivedDialog(cobject, refBuilder) // Delegate to the other constructor
{
  // Show an icon.
  auto content_area = refBuilder->get_widget<Gtk::Box>("dialog-content_area");
  if (!content_area)
  {
    std::cerr << "Could not get the content area" << std::endl;
    return;
  }
  auto pImage = Gtk::make_managed<Gtk::Image>();
  pImage->set_from_icon_name(is_glad ? "face-smile" : "face-sad");
  pImage->set_icon_size(Gtk::IconSize::LARGE);
  pImage->set_expand();
  content_area->append(*pImage);
}

DerivedDialog::~DerivedDialog()
{
}

void DerivedDialog::on_button_quit()
{
  set_visible(false); // set_visible(false) will cause Gtk::Application::run() to end.
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "deriveddialog.h"
#include <iostream>
#include <cstring>

namespace
{
bool show_icon = false;
bool is_glad = true;

DerivedDialog* pDialog = nullptr;
Glib::RefPtr<Gtk::Application> app;

void on_app_activate()
{
  // Create a dummy instance before the call to refBuilder->add_from_file().
  // This creation registers DerivedButton's class in the GType system.
  // This is necessary because DerivedButton contains user-defined properties
  // (Glib::Property) and is created by Gtk::Builder.
  static_cast<void>(DerivedButton());

  // Load the GtkBuilder file and instantiate its widgets:
  auto refBuilder = Gtk::Builder::create();
  try
  {
    refBuilder->add_from_file("derived.ui");
  }
  catch(const Glib::FileError& ex)
  {
    std::cerr << "FileError: " << ex.what() << std::endl;
    return;
  }
  catch(const Glib::MarkupError& ex)
  {
    std::cerr << "MarkupError: " << ex.what() << std::endl;
    return;
  }
  catch(const Gtk::BuilderError& ex)
  {
    std::cerr << "BuilderError: " << ex.what() << std::endl;
    return;
  }

  // Get the GtkBuilder-instantiated dialog:
  if (show_icon)
    pDialog = Gtk::Builder::get_widget_derived<DerivedDialog>(refBuilder, "DialogDerived", is_glad);
  else
    pDialog = Gtk::Builder::get_widget_derived<DerivedDialog>(refBuilder, "DialogDerived");

  if (!pDialog)
  {
    std::cerr << "Could not get the dialog" << std::endl;
    return;
  }

  // It's not possible to delete widgets after app->run() has returned.
  // Delete the dialog with its child widgets before app->run() returns.
  pDialog->signal_hide().connect([] () { delete pDialog; });

  app->add_window(*pDialog);
  pDialog->set_visible(true);
}
} // anonymous namespace

int main(int argc, char** argv)
{
  int argc1 = argc;
  if (argc > 1)
  {
    if (std::strcmp(argv[1], "--glad") == 0)
    {
      show_icon = true;
      is_glad = true;
      argc1 = 1; // Don't give the command line arguments to Gtk::Application.
    }
    else if (std::strcmp(argv[1], "--sad") == 0)
    {
      show_icon = true;
      is_glad = false;
      argc1 = 1; // Don't give the command line arguments to Gtk::Application.
    }
  }

  app = Gtk::Application::create("org.gtkmm.example");

  // Instantiate a dialog when the application has been activated.
  // This can only be done after the application has been registered.
  // It's possible to call app->register_application() explicitly, but
  // usually it's easier to let app->run() do it for you.
  app->signal_activate().connect([] () { on_app_activate(); });

  return app->run(argc1, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</section>

</chapter>

<chapter xml:id="chapter-internationalization">
<title>Internacionalizace a lokalizace</title>

  <para>Aplikace 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é.</para>
  <para>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.</para>

  <para>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ů.</para>

  <para>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.</para>

  <para>Ř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.</para>

  <section xml:id="sec-internationalization-intro">
  <title>Příprava vašeho projektu</title>

    <note>
      <para xml:lang="en">
        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 <filename class="extension">.ui</filename> files, into standard
        <application>gettext</application> <filename>.pot/.po</filename> files.
      </para>
      <para xml:lang="en">
        We also assume that you are using autotools (<application>automake</application>
        and <application>autoconf</application>) to build your project (although
        autotools is not recommended for new applications), and
        that you are using <link xlink:href="https://gitlab.gnome.org/GNOME/gnome-common/blob/master/autogen.sh">
          <literal>./autogen.sh</literal> from <application>gnome-common</application></link>
        or a similar <literal>autogen.sh</literal> file, which, among other
        things, takes care of some <application>intltool</application>
        initialization.
      </para>
    </note>
    <note>
      <para xml:lang="en">
        If you are using <application>meson</application> (recommended), see the
        <link xlink:href="https://mesonbuild.com/Localisation.html">Localisation</link>
        chapter in Meson's manual. You can then skip this section.
      </para>
    </note>

    <para xml:lang="en">
      An alternative to <application>gnome-common</application>'s
      <literal>autogen.sh</literal> may look like this:
    </para>
    <programlisting xml:lang="en"><code>#! /bin/sh -e
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.

autoreconf --force --install --verbose --warnings=all "$srcdir"
echo "Running intltoolize --copy --force --automake"
intltoolize --copy --force --automake
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"</code></programlisting>

    <para>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.</para>

    <para>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:</para>
    <programlisting xml:lang="en"><code># keep this file sorted alphabetically, one language code per line
de
ja</code></programlisting>
    <para xml:lang="en">
      (In addition, you'd have the files <literal>de.po</literal> and
      <literal>ja.po</literal> in your
      <literal>po</literal> directory which contain the German and Japanese
      translations, respectively.)
    </para>

    <para>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:</para>

    <programlisting xml:lang="en"><code>src/main.cc
src/other.cc</code></programlisting>

    <para xml:lang="en">
      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
      <filename class="extension">.ui</filename> files, xml,
      <link xlink:href="http://standards.freedesktop.org/desktop-entry-spec/latest/">.desktop files</link>
      and several more. So, if you have designed some of the
      application UI in xml files then also add your
      <filename class="extension">.ui</filename> files to the list in
      <literal>POTFILES.in</literal>.
    </para>

    <para>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).</para>

    <programlisting xml:lang="en"><code>IT_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_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.17])

PROGRAMNAME_LOCALEDIR=[${datadir}/locale]
AC_SUBST(PROGRAMNAME_LOCALEDIR)</code></programlisting>

    <para>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>.</para>

    <para xml:lang="en">
      <literal>AM_GLIB_GNU_GETTEXT</literal> has been an alternative to
      <literal>AM_GNU_GETTEXT</literal> and <literal>AM_GNU_GETTEXT_VERSION</literal>,
      but <literal>AM_GLIB_GNU_GETTEXT</literal> is now deprecated, and shall
      not be used in new code.
    </para>

    <para xml:lang="en">
      In the top-level Makefile.am:
      <itemizedlist>
        <listitem>
          <para xml:lang="en">Add <literal>po</literal> to the <literal>SUBDIRS</literal>
            variable. Without this, your translations won't get built and
            installed when you build the program</para>
        </listitem>
        <listitem>
          <para xml:lang="en">
            Define <literal>INTLTOOL_FILES</literal> as:</para>
            <programlisting xml:lang="en"><code>INTLTOOL_FILES = intltool-extract.in \
                 intltool-merge.in \
                 intltool-update.in</code></programlisting>
        </listitem>
        <listitem>
          <para xml:lang="en">
            Add <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 files will be
            included in the source tarball.
          </para>
        </listitem>
        <listitem>
          <para xml:lang="en">
            Update your <literal>DISTCLEANFILES</literal>:</para>
            <programlisting xml:lang="en"><code>DISTCLEANFILES = ... intltool-extract \
                 intltool-merge \
                 intltool-update \
                 po/.intltool-merge-cache</code></programlisting>
        </listitem>
        <listitem>
          <para xml:lang="en">
            Depending on the types of files that contain translatable strings,
            add code such as</para>
            <programlisting xml:lang="en"><code>desktopdir = $(datadir)/applications
desktop_in_files = programname.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@</code></programlisting>
        </listitem>
      </itemizedlist>
    </para>

    <para>V souboru <literal>src/Makefile.am</literal> aktualizujte <literal>AM_CPPFLAGS</literal> přidáním následujících definic maker preprocesoru:</para>
    <programlisting xml:lang="en"><code>AM_CPPFLAGS = ... -DPROGRAMNAME_LOCALEDIR=\"${PROGRAMNAME_LOCALEDIR}\"</code></programlisting>
    <para>Toto makro se použije, když inicializujete <literal>gettext</literal> ve svém zdrojovém kódu.</para>
  </section>

<section xml:id="sec-i18n-marking-strings">
<title>Označení řetězců k překladu</title>

  <para>Ř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.</para>

  <para>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.</para>

  <para xml:lang="en">
    However, <application>Glib</application> defines
    <function>gettext()</function>
    support macros which are shorter wrappers in an easy-to-use form.
    To use these macros, include <literal>&lt;glibmm/i18n.h&gt;</literal>,
    and then, for example, substitute:</para>
    <programlisting xml:lang="en"><code>display_message("Getting ready for i18n.");</code></programlisting>
    <para xml:lang="en">with:</para>
    <programlisting xml:lang="en"><code>display_message(_("Getting ready for i18n."));</code></programlisting>

  <para xml:lang="en">
    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:
  </para>

  <programlisting xml:lang="en"><code>xgettext -a -o my-strings --omit-header *.cc *.h</code></programlisting>

  <para xml:lang="en">
    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.
  </para>

<programlisting xml:lang="en"><code>bindtextdomain(GETTEXT_PACKAGE, PROGRAMNAME_LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);</code></programlisting>

  <section xml:id="sec-i18n-gettext">
  <title>Jak gettext funguje</title>

    <para xml:lang="en">
      The <application>intltool-update</application> or
      <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
      <application>msgmerge</application> or <application>intltool-update</application>
      script is used to update the <filename>localename.po</filename> files from
      the regenerated <filename>.pot</filename> file.
    </para>

    <para>Př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>.</para>

    <para>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í.</para>
  </section>

  <section xml:id="sec-i18n-testing">
  <title>Testování a přidávání překladů</title>

    <para xml:lang="en">
      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:
    </para>
    <programlisting xml:lang="en"><code>intltool-update --pot</code></programlisting>

    <para>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).</para>

    <!-- TODO: This need more explanation. What's the point of the fuzzy tag then? murrayc -->
    <note>
      <para xml:lang="en">
      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.
      A <literal>fuzzy</literal> tag appears if a string content changed,
      but the location is still the same.
      </para>
    </note>
  </section>

  <section xml:id="sec-i18n-resources">
  <title>Zdroje</title>

    <para xml:lang="en">
      More information about what lies behind the internationalization and localization process
      is presented and demonstrated in:

      <itemizedlist>
        <listitem>
          <para xml:lang="en">
            <link xlink:href="https://wiki.gnome.org/TranslationProject/DevGuidelines">
              L10N Guidelines for Developers</link>
          </para>
        </listitem>

        <listitem>
          <para xml:lang="en">
            <link xlink:href="http://bazaar.launchpad.net/~intltool/intltool/trunk/view/head:/README">Intltool README</link>
          </para>
        </listitem>

        <listitem>
          <para xml:lang="en">
            <link xlink:href="https://wiki.gnome.org/TranslationProject/GitHowTo">How to use Git for GNOME translators</link>
          </para>
        </listitem>

        <listitem>
          <para xml:lang="en">
            <link xlink:href="http://www.gnu.org/software/gettext/manual/gettext.html">gettext manual</link>
          </para>
        </listitem>

        <listitem>
          <para xml:lang="en">
            <link xlink:href="http://ftp.gnome.org/pub/GNOME/sources/gtkmm_hello/"><literal>gtkmm_hello</literal> example package</link>
          </para>
        </listitem>

        <listitem>
          <para xml:lang="en">
            <link xlink:href="http://ftp.gnome.org/pub/GNOME/sources/gnomemm_hello/"><literal>gnomemm_hello</literal> example package</link>
          </para>
        </listitem>
      </itemizedlist>
    </para>
  </section>

</section>

<section xml:id="sec-i18n-expecting-utf8">
<title>Očekává se UTF-8</title>

<para>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í.</para>
<para>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>.</para>

<section xml:id="i18n-ustring-iostreams">
<title>Glib::ustring and std::iostreams</title>

<!-- <para>TODO: This section is not clear - it needs to spell things out more clearly and obviously.</para> -->
<para xml:lang="en">
Unfortunately, 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::ustring</classname>s 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>:
</para>
<programlisting xml:lang="en"><code>std::locale::global(std::locale("")); // Set the global locale to the user's preferred locale.
                                      // Usually unnecessary here, because Glib::init()
                                      // or Gtk::Application::create() does it for you.
std::ostringstream output;
output &lt;&lt; percentage &lt;&lt; " % done";
label-&gt;set_text(Glib::locale_to_utf8(output.str()));</code></programlisting>
</section>

</section>

<section xml:id="sec-i18n-pitfalls">
<title>Úskalí</title>

      <para>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.</para>

<section xml:id="i18n-string-semantics">
<title>Stejné řetězce, jiný význam</title>

        <para xml:lang="en">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.</para>

<para>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:</para>
<programlisting xml:lang="en"><code>// 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]");</code></programlisting>

<para xml:lang="en">
If you use <application>Glib</application>'s support macros, it's easier. Use
<function>C_()</function> instead of <function>_()</function>. For instance:
</para>
<programlisting xml:lang="en"><code>GLib::ustring text(C_("noun", "jumps"));</code></programlisting>

</section>

<section xml:id="i18n-composition">
<title>Skládání řetězců</title>

<para xml:lang="en">
C programmers use <function>sprintf()</function> to compose and concatenate
strings. C++ favors 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.</para>

<para>Například takovýto kód by mohl přinést problémy:</para>

<programlisting xml:lang="en"><code>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?"));</code></programlisting>

<para xml:lang="en">
So you should either avoid this situation or use
<link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/classGlib_1_1ustring.html"><function>Glib::ustring::compose()</function></link>
which supports syntax such as:
</para>
<programlisting xml:lang="en"><code>std::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));</code></programlisting>
</section>

<section xml:id="i18n-display-size">
<title>Počítejte s dostatečnou šířkou pro zobrazení řetězců</title>

        <para>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.</para>
</section>

<section xml:id="i18n-unusual-words">
<title>Neobvyklá slova</title>

        <para>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“.</para>
</section>

<section xml:id="i18n-non-ascii-characters">
<title>Používání jiných znaků než ASCII v řetězcích</title>

<para>V 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 (©).</para>

        <para xml:lang="en">To 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.</para>
      </section>
    </section>

    <section xml:id="sec-i18n-getting-help-with-translations">
    <title>Získání pomoci s překladem</title>

      <para xml:lang="en">If your program is free software, there is a whole <literal>GNOME</literal>
        subproject devoted to helping you make translations, the
        <link xlink:href="https://wiki.gnome.org/TranslationProject/"><literal>GNOME</literal>
        Translation Project</link>.</para>

      <para xml:lang="en">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
        <link xlink:href="http://l10n.gnome.org/module/">list of modules to translate</link>.</para>

      <para xml:lang="en">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.</para>

      <para>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.</para>
    </section>
</chapter>

<chapter xml:id="chapter-customwidgets">
<title>Vlastní widgety</title>

    <para xml:lang="en"><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 behavior.
      But you might occasionally find that no suitable starting point already exists.
      In this case, you can implement a widget from scratch.</para>

    <section xml:id="sec-custom-containers">
    <title>Vlastní kontejnery</title>

    <para xml:lang="en">When deriving a custom container widget directly from <classname>Gtk::Widget</classname>,
      you should override the following virtual methods:
    <itemizedlist>
      <listitem><para xml:lang="en"><methodname>get_request_mode_vfunc()</methodname>: Return what <literal>Gtk::SizeRequestMode</literal> is preferred by the container.</para></listitem>
      <listitem><para xml:lang="en"><methodname>measure_vfunc()</methodname>: Calculate the minimum and natural width or height of the container.</para></listitem>
      <listitem><para xml:lang="en"><methodname>size_allocate_vfunc()</methodname>: Position the child widgets, given the height and width that the container has actually been given.</para></listitem>
    </itemizedlist>
    </para>

    <para xml:lang="en">The <methodname>get_request_mode_vfunc()</methodname>,
        <methodname>measure_vfunc()</methodname>, and
        <methodname>size_allocate_vfunc()</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>measure_vfunc()</methodname>
        might report the maximum of the widths of the child widgets when asked
        to report width, and it might report the sum of their heights when asked
        to report height. 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.</para>

    <para xml:lang="en">You are not guaranteed to get the <literal>Gtk::SizeRequestMode</literal>
        that you request. Therefore <methodname>measure_vfunc()</methodname> must
        return sensible values for all reasonable values of its input parameters.
        For a description of <methodname>measure_vfunc()</methodname>'s parameters see
        also the description of <methodname>Gtk::Widget::measure()</methodname>, which
        may be better documented than <methodname>measure_vfunc()</methodname>.</para>

   <para xml:lang="en"><methodname>size_allocate_vfunc()</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.</para>

   <para xml:lang="en">Your container must unparent its children before the underlying C object
       (a <classname>gtkmm__GtkWidget</classname>) is finalized. If your container
       is used as a managed widget, it shall unparent its children in a
       <methodname>Gtk::Widget::signal_destroy()</methodname> handler (available
       since <application>gtkmm</application> 4.8). If your container is not managed, that signal handler
       is not called. Instead the children shall be unparented in the C++ destructor.
       If you want your container to be useful both ways, unparent the children
       both in the destructor and in a signal handler. See the example code.</para>

<section xml:id="custom-container-example">
<title>Příklad</title>

    <para xml:lang="en">This example implements a container with 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> or <classname>Gtk::Grid</classname>.</para>

<figure xml:id="figure-custom-container">
  <title>Vlastní kontejner</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/custom_container.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/custom/custom_container/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "mycontainer.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  //Signal handlers:
  void on_button_quit();

  //Child widgets:
  Gtk::Box m_VBox;
  MyContainer m_MyContainer;
  Gtk::Button m_Button_Child;
  Gtk::Label m_Label_Child;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>mycontainer.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_CUSTOM_CONTAINER_MYCONTAINER_H
#define GTKMM_CUSTOM_CONTAINER_MYCONTAINER_H

#include <gtkmm/widget.h>
#include <gtkmm/version.h>

#define HAS_SIGNAL_DESTROY GTKMM_CHECK_VERSION(4,7,1)

class MyContainer : public Gtk::Widget
{
public:
  MyContainer();
  ~MyContainer() override;

  void append(Gtk::Widget& child);
  void prepend(Gtk::Widget& child);
  void remove(Gtk::Widget& child);

protected:
  int get_nvis_children() const;

  //Overrides:
  Gtk::SizeRequestMode get_request_mode_vfunc() const override;
  void measure_vfunc(Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
    int& minimum_baseline, int& natural_baseline) const override;
  void size_allocate_vfunc(int width, int height, int baseline) override;

#if HAS_SIGNAL_DESTROY
  // Signal handler:
  void on_container_destroy();
#endif
};

#endif //GTKMM_CUSTOM_CONTAINER_MYCONTAINER_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Child("Child button"),
  m_Label_Child("Child label", Gtk::Align::END, Gtk::Align::CENTER),
  m_Button_Quit("Quit")
{
  set_title("Custom Container example");
  set_default_size(400, 200);

  m_VBox.set_margin(6);
  set_child(m_VBox);

  //Add the child widgets to the custom container:
  m_MyContainer.append(m_Button_Child);
  m_MyContainer.append(m_Label_Child);
  m_MyContainer.prepend(*Gtk::make_managed<Gtk::Label>(
    "First line\nSecond line\nThird line"));
  m_MyContainer.set_expand();
  m_VBox.append(m_MyContainer);

#if HAS_SIGNAL_DESTROY
  // A managed custom container.
  auto container = Gtk::make_managed<MyContainer>();
  container->prepend(*Gtk::make_managed<Gtk::Label>("Second custom container"));
  container->set_expand();
  m_VBox.append(*container);
#endif
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(6);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>mycontainer.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "mycontainer.h"

#include <algorithm> // std::max()

// This example container is a simplified vertical Box.
//
// It can't be used as a managed widget, managed by another container
// unless Gtk::Widget::signal_destroy() exists.
// It would cause an error like
// Gtk-WARNING **: 08:31:48.137: Finalizing gtkmm__GtkWidget 0x561b777462c0, but it still has children left:

MyContainer::MyContainer()
{
#if HAS_SIGNAL_DESTROY
  signal_destroy().connect(sigc::mem_fun(*this, &MyContainer::on_container_destroy));
#endif
}

MyContainer::~MyContainer()
{
  // If MyContainer is a managed widget, the underlying C object is destructed
  // before this C++ destructor is executed.
  if (!gobj())
    return;

  // If MyContainer is not a managed widget, unparent all children here.
  while (Widget* child = get_first_child())
    child->unparent();
}

#if HAS_SIGNAL_DESTROY
// This signal handler is called only if MyContainer is a managed widget.
void MyContainer::on_container_destroy()
{
  while (Widget* child = get_first_child())
    child->unparent();
}
#endif

// Get number of visible children.
int MyContainer::get_nvis_children() const
{
  int nvis_children = 0;
  for (const Widget* child = get_first_child(); child; child = child->get_next_sibling())
    if (child->get_visible())
      ++nvis_children;

  return nvis_children;
}

Gtk::SizeRequestMode MyContainer::get_request_mode_vfunc() const
{
  return Gtk::SizeRequestMode::HEIGHT_FOR_WIDTH;
}

// Discover the total amount of minimum space and natural space needed by
// this container and its children.
void MyContainer::measure_vfunc(Gtk::Orientation orientation, int for_size,
  int& minimum, int& natural, int& minimum_baseline, int& natural_baseline) const
{
  // Don't use baseline alignment.
  minimum_baseline = -1;
  natural_baseline = -1;

  minimum = 0;
  natural = 0;

  // Number of visible children.
  const int nvis_children = get_nvis_children();

  if (orientation == Gtk::Orientation::HORIZONTAL)
  {
    // Divide the height equally among the visible children.
    if (for_size > 0 && nvis_children > 0)
      for_size /= nvis_children;

    // Request a width equal to the width of the widest visible child.
  }

  for (const Widget* child = get_first_child(); child; child = child->get_next_sibling())
    if (child->get_visible())
    {
      int child_minimum, child_natural, ignore;
      child->measure(orientation, for_size, child_minimum, child_natural, ignore, ignore);
      minimum = std::max(minimum, child_minimum);
      natural = std::max(natural, child_natural);
    }

  if (orientation == Gtk::Orientation::VERTICAL)
  {
    // The allocated height will be divided equally among the visible children.
    // Request a height equal to the number of visible children times the height
    // of the highest child.
    minimum *= nvis_children;
    natural *= nvis_children;
  }
}

void MyContainer::size_allocate_vfunc(int width, int height, int baseline)
{
  //Do something with the space that we have actually been given:
  //(We will not be given heights or widths less than we have requested, though
  //we might get more.)

  // Number of visible children.
  const int nvis_children = get_nvis_children();

  if (nvis_children <= 0)
  {
    // No visible child.
    return;
  }

  //Assign space to the children:
  Gtk::Allocation child_allocation;
  const int height_per_child = height / nvis_children;

  //Place the first visible child at the top-left:
  child_allocation.set_x(0);
  child_allocation.set_y(0);

  //Make it take up the full width available:
  child_allocation.set_width(width);
  child_allocation.set_height(height_per_child);

  //Divide the height equally among the visible children.
  for (Widget* child = get_first_child(); child; child = child->get_next_sibling())
    if (child->get_visible())
    {
      child->size_allocate(child_allocation, baseline);
      child_allocation.set_y(child_allocation.get_y() + height_per_child);
    }
}

void MyContainer::append(Gtk::Widget& child)
{
   child.insert_at_end(*this);
}

void MyContainer::prepend(Gtk::Widget& child)
{
   child.insert_at_start(*this);
}

void MyContainer::remove(Gtk::Widget& child)
{
  child.unparent();
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>

    </section>

    <section xml:id="sec-custom-widgets">
    <title>Vlastní widgety</title>

    <para>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ů.</para>

    <para xml:lang="en">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.
    <itemizedlist>
      <listitem><para xml:lang="en"><methodname>get_request_mode_vfunc()</methodname>: (optional) Return what <literal>Gtk::SizeRequestMode</literal> is preferred by the widget.</para></listitem>
      <listitem><para xml:lang="en"><methodname>measure_vfunc()</methodname>: Calculate the minimum and natural width or height of the widget.</para></listitem>
      <listitem><para xml:lang="en"><methodname>size_allocate_vfunc()</methodname>: (optional) Position the widget, given the height and width that it has actually been given.</para></listitem>
      <listitem><para xml:lang="en"><methodname>on_realize()</methodname>:  (optional)</para></listitem>
      <listitem><para xml:lang="en"><methodname>on_unrealize()</methodname>: (optional)</para></listitem>
      <listitem><para xml:lang="en"><methodname>on_map()</methodname>: (optional)</para></listitem>
      <listitem><para xml:lang="en"><methodname>on_unmap()</methodname>: (optional)</para></listitem>
      <listitem><para xml:lang="en"><methodname>snapshot_vfunc()</methodname>: Create a render node, e.g. a <classname>Cairo::Context</classname> node, and draw on it.</para></listitem>
    </itemizedlist>
    </para>

    <para xml:lang="en">The first 3 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.
    </para>

<section xml:id="custom-init-functions">
<title xml:lang="en">Class Init and Instance Init Functions</title>

<para xml:lang="en">Some <application>GTK</application> functions, if called at all, must be
called from the class init function. Some other <application>GTK</application>
functions, if called, must be called from the instance init function.
If your custom widget must call any of those functions, you can derive a class
from <classname>Glib::ExtraClassInit</classname> and derive your custom class
from that class. The <link linkend="custom-css-name-example">custom CSS name example</link>
shows how that's done.</para>
</section>

<section xml:id="custom-widget-example">
<title>Příklad</title>

<para xml:lang="en">This example implements a widget which draws Penrose triangles.</para>

<figure xml:id="figure-custom-widget">
  <title>Vlastní widget</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/custom_widget.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/custom/custom_widget/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "mywidget.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_quit();

  //Child widgets:
  Gtk::Grid m_Grid;
  MyWidget m_MyWidgetS1;
  MyWidget m_MyWidgetS2;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>mywidget.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_CUSTOM_WIDGET_MYWIDGET_H
#define GTKMM_CUSTOM_WIDGET_MYWIDGET_H

#include <gtkmm/widget.h>
#include <gtkmm/border.h>
#include <gdkmm/rgba.h>

class MyWidget : public Gtk::Widget
{
public:
  MyWidget();
  ~MyWidget() override;

protected:
  // Overrides:
  Gtk::SizeRequestMode get_request_mode_vfunc() const override;
  void measure_vfunc(Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
    int& minimum_baseline, int& natural_baseline) const override;
  void on_map() override;
  void on_unmap() override;
  void on_realize() override;
  void on_unrealize() override;
  void snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot) override;

  Gtk::Border m_padding;
  Gdk::RGBA m_foreground{0.0, 0.0, 1.0};
  Gdk::RGBA m_background{1.0, 0.0, 0.0};
};

#endif //GTKMM_CUSTOM_WIDGET_MYWIDGET_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"

ExampleWindow::ExampleWindow()
: m_Button_Quit("Quit")
{
  set_title("Custom Widget example");
  set_default_size(600, 400);

  m_Grid.set_margin(6);
  m_Grid.set_row_spacing(10);
  m_Grid.set_column_spacing(10);

  set_child(m_Grid);

  m_Grid.attach(m_MyWidgetS1, 0, 0);
  m_Grid.attach(m_MyWidgetS2, 1, 1);

  m_Grid.attach(m_ButtonBox, 0, 2, 2, 1);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(6);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button_quit) );
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>mywidget.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "mywidget.h"
#include <gdkmm/general.h>  // for Gdk::Cairo:: functions
#include <gtkmm/snapshot.h>

MyWidget::MyWidget()
{
  // Expand, if there is extra space.
  set_expand(true);

  m_padding.set_left(5);
  m_padding.set_right(15);
  m_padding.set_top(10);
  m_padding.set_bottom(20);
}

MyWidget::~MyWidget()
{
}

Gtk::SizeRequestMode MyWidget::get_request_mode_vfunc() const
{
  //Accept the default value supplied by the base class.
  return Gtk::Widget::get_request_mode_vfunc();
}

//Discover the total amount of minimum space and natural space needed by
//this widget.
//Let's make this simple example widget always need minimum 60 by 50 and
//natural 100 by 70.
void MyWidget::measure_vfunc(Gtk::Orientation orientation, int /* for_size */,
  int& minimum, int& natural, int& minimum_baseline, int& natural_baseline) const
{
  if (orientation == Gtk::Orientation::HORIZONTAL)
  {
    minimum = 60;
    natural = 100;
  }
  else
  {
    minimum = 50;
    natural = 70;
  }

  // Don't use baseline alignment.
  minimum_baseline = -1;
  natural_baseline = -1;
}

void MyWidget::on_map()
{
  //Call base class:
  Gtk::Widget::on_map();
}

void MyWidget::on_unmap()
{
  //Call base class:
  Gtk::Widget::on_unmap();
}

void MyWidget::on_realize()
{
  //Call base class:
  Gtk::Widget::on_realize();
}

void MyWidget::on_unrealize()
{
  //Call base class:
  Gtk::Widget::on_unrealize();
}

void MyWidget::snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot)
{
  const auto allocation = get_allocation();
  const Gdk::Rectangle rect(0, 0, allocation.get_width(), allocation.get_height());

  // Create a cairo context to draw on.
  auto cr = snapshot->append_cairo(rect);

  // paint the background
  Gdk::Cairo::set_source_rgba(cr, m_background);
  Gdk::Cairo::add_rectangle_to_path(cr, rect);
  cr->fill();

  // draw the foreground
  const double scale_x = 0.001 * (allocation.get_width() - m_padding.get_left() - m_padding.get_right());
  const double scale_y = 0.001 * (allocation.get_height() - m_padding.get_top() - m_padding.get_bottom());
  Gdk::Cairo::set_source_rgba(cr, m_foreground);
  cr->translate(m_padding.get_left(), m_padding.get_top());
  cr->rectangle(0.0, 0.0, 1000.0*scale_x, 1000.0*scale_y);
  cr->move_to(155.*scale_x, 165.*scale_y);
  cr->line_to(155.*scale_x, 838.*scale_y);
  cr->line_to(265.*scale_x, 900.*scale_y);
  cr->line_to(849.*scale_x, 564.*scale_y);
  cr->line_to(849.*scale_x, 438.*scale_y);
  cr->line_to(265.*scale_x, 100.*scale_y);
  cr->line_to(155.*scale_x, 165.*scale_y);
  cr->move_to(265.*scale_x, 100.*scale_y);
  cr->line_to(265.*scale_x, 652.*scale_y);
  cr->line_to(526.*scale_x, 502.*scale_y);
  cr->move_to(369.*scale_x, 411.*scale_y);
  cr->line_to(633.*scale_x, 564.*scale_y);
  cr->move_to(369.*scale_x, 286.*scale_y);
  cr->line_to(369.*scale_x, 592.*scale_y);
  cr->move_to(369.*scale_x, 286.*scale_y);
  cr->line_to(849.*scale_x, 564.*scale_y);
  cr->move_to(633.*scale_x, 564.*scale_y);
  cr->line_to(155.*scale_x, 838.*scale_y);
  cr->stroke();
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

<section xml:id="sec-custom-css-names">
<title xml:lang="en">Custom CSS Names</title>

<para xml:lang="en">Many aspects of the look of widgets are controlled by CSS (Cascading Style
Sheet) files. With CSS files you can choose color, font, line thickness, etc.
If you give some widgets their own names or their own CSS classes, you can define
CSS rules that apply only to those widgets, for instance certain buttons,
without affecting other similar widgets.</para>

<section xml:id="css-widget-class-name">
<title xml:lang="en">CSS Node Name, Widget Name, CSS Class Name</title>

<para xml:lang="en">There are three ways of referring from a widget to data in a CSS file:
  <itemizedlist>
    <listitem><para xml:lang="en"><methodname>gtk_widget_class_set_css_name()</methodname>
    can only be called from the class init function. It sets the CSS node name
    of all instances of a class (a GType). See the <link linkend="custom-init-functions">
    Class Init and Instance Init Functions</link> section.</para></listitem>
    <listitem><para xml:lang="en"><methodname>Gtk::Widget::set_name()</methodname>
    can be called from a C++ constructor. It sets the name of
    a widget instance.</para></listitem>
    <listitem><para xml:lang="en"><methodname>Gtk::Widget::add_class_name()</methodname>
    can be called from a C++ constructor. It adds the name of a CSS class,
    used by a widget instance.</para></listitem>
  </itemizedlist>
The following example shows a button with its own CSS node name, a label with
a widget name and a label that uses its own CSS class.</para>
</section>

<section xml:id="custom-style-information">
<title xml:lang="en">Custom Style Information</title>

<para xml:lang="en">To add a style sheet to an application, use one of the
<methodname>Gtk::CssProvider::load_from_*()</methodname> methods.
Then add it with <methodname>Gtk::StyleProvider::add_provider_for_display()</methodname>
(available since <application>gtkmm</application> 4.10) or <methodname>Gtk::StyleContext::add_provider_for_display()</methodname>.
<classname>Gtk::StyleContext</classname> also contains methods to read some style
information, but this class is deprecated since <application>gtkmm</application> 4.10.</para>

<para xml:lang="en">CSS files are described in the documentation of GTK.</para>
</section>

<section xml:id="custom-css-name-example">
<title>Příklad</title>

<para xml:lang="en">This example implements a button and two labels with custom style information.</para>

<figure xml:id="figure-custom-css-name">
  <title xml:lang="en">Custom CSS Name</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/custom_css_name.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/custom/custom_css_name/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "mybutton.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  ~ExampleWindow() override;

protected:
  // Signal handlers:
  void on_button_quit();
  static void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section,
    const Glib::Error& error);

  // Child widgets:
  Gtk::Box m_VBox;
  MyButton m_Button_Child;
  Gtk::Label m_Label_Child1;
  Gtk::Label m_Label_Child2;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_Button_Quit;

  Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;
};

#endif //GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>mybutton.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYBUTTON_H
#define GTKMM_EXAMPLE_MYBUTTON_H

#include <gtkmm/button.h>
#include "myextrainit.h"

class MyButton : public MyExtraInit, public Gtk::Button
{
public:
  MyButton(const Glib::ustring& label, bool mnemonic=false);
  ~MyButton() override;
};

#endif //GTKMM_EXAMPLE_MYBUTTON_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>myextrainit.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_MYEXTRAINIT_H
#define GTKMM_EXAMPLE_MYEXTRAINIT_H

#include <glibmm/extraclassinit.h>
#include <glibmm/ustring.h>

// Calls gtk_widget_class_set_css_name() in the class init function.
class MyExtraInit : public Glib::ExtraClassInit
{
public:
  MyExtraInit(const Glib::ustring& css_name);

private:
  Glib::ustring m_css_name;
};

#endif //GTKMM_EXAMPLE_MYEXTRAINIT_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>
#include <gtkmm/version.h>

#define HAS_STYLE_PROVIDER_ADD_PROVIDER_FOR_DISPLAY GTKMM_CHECK_VERSION(4,9,1)

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::Orientation::VERTICAL),
  m_Button_Child("Button with custom CSS node name"),
  m_Label_Child1("Label with custom name"),
  m_Label_Child2("Label with custom CSS class"),
  m_Button_Quit("Quit")
{
  set_title("Custom CSS name example");
  set_default_size(400, 200);

  m_VBox.set_margin(10);
  m_VBox.set_spacing(5);
  set_child(m_VBox);

  // There are 3 ways to set custom CSS data for a widget:
  // 1. The CSS name can be set for a GType with gtk_widget_class_set_css_name().
  // 2. The CSS name can be set for a widget instance with gtk_widget_set_name()
  //    (Gtk::Widget::set_name()).
  // 3. A CSS class can be set for a widget instance with
  //    gtk_widget_add_css_class() (Gtk::Widget::add_css_class()).
  //
  // gtk_widget_class_set_css_name(), if used, must be called in the class init
  // function. It has not been wrapped in a C++ function.
  // Gtk::Widget::set_name() and Gtk::Widget::add_css_class() can be called in
  // a C++ constructor.

  // CSS widget name, which must be used in the CSS file, preceded by "#".
  m_Label_Child1.set_name("my-label1");

  // CSS class name, which must be used in the CSS file, preceded by ".".
  m_Label_Child2.add_css_class("my-label2");

  // Add the child widgets to m_VBox:
  m_VBox.append(*Gtk::make_managed<Gtk::Label>("Ordinary label"));
  m_VBox.append(m_Button_Child);
  m_VBox.append(m_Label_Child1);
  m_VBox.append(m_Label_Child2);
  m_VBox.set_expand();
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_Button_Quit);
  m_ButtonBox.set_margin(6);
  m_Button_Quit.set_hexpand(true);
  m_Button_Quit.set_halign(Gtk::Align::END);
  m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_quit) );

  // Load extra CSS file.
  m_refCssProvider = Gtk::CssProvider::create();
#if HAS_STYLE_PROVIDER_ADD_PROVIDER_FOR_DISPLAY
  Gtk::StyleProvider::add_provider_for_display(get_display(), m_refCssProvider,
    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
#else
  Gtk::StyleContext::add_provider_for_display(get_display(), m_refCssProvider,
    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
#endif

  m_refCssProvider->signal_parsing_error().connect(
    [](const auto& section, const auto& error)
    { on_parsing_error(section, error); }
  );
  m_refCssProvider->load_from_path("custom_gtkmm.css");
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  set_visible(false);
}

void ExampleWindow::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section,
  const Glib::Error& error)
{
  std::cerr << "on_parsing_error(): " << error.what() << std::endl;
  if (section)
  {
    const auto file = section->get_file();
    if (file)
    {
      std::cerr << "  URI = " << file->get_uri() << std::endl;
    }

    auto start_location = section->get_start_location();
    auto end_location = section->get_end_location();
    std::cerr << "  start_line = " << start_location.get_lines()+1
              << ", end_line = " << end_location.get_lines()+1 << std::endl;
    std::cerr << "  start_position = " << start_location.get_line_chars()
              << ", end_position = " << end_location.get_line_chars() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  // Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>mybutton.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "mybutton.h"
#include <gtk/gtk.h> // For GTK_IS_BUTTON()
#include <iostream>

MyButton::MyButton(const Glib::ustring& label, bool mnemonic)
  :
  // The GType name will actually be gtkmm__CustomObject_MyButton
  Glib::ObjectBase("MyButton"),
  MyExtraInit("my-button"), // CSS node name, which must be used in the CSS file.
  Gtk::Button(label, mnemonic)
{
  // This shows the GType name:
  std::cout << "GType name: " << G_OBJECT_TYPE_NAME(gobj()) << std::endl;

  // This shows that the GType still derives from GtkButton:
  std::cout << "Gtype is a GtkButton?: " << GTK_IS_BUTTON(gobj()) << std::endl;

  // The CSS name can be set either
  // - for a GType (in this case for your custom class) with gtk_widget_class_set_css_name(), or
  // - for a widget instance with gtk_widget_set_name() (Gtk::Widget::set_name()).
  //
  // gtk_widget_class_set_css_name(), if used, must be called in the class init function.
  // It has not been wrapped in a C++ function.
  // Gtk::Widget::set_name() can be called in a C++ constructor.
  //
  // Another alternative: The custom button inherits the CSS name "button" from
  // GtkButton. That name can be used in the CSS file.
}

MyButton::~MyButton()
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>myextrainit.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "myextrainit.h"
#include <gtkmm/widget.h>
#include <gtk/gtk.h>

namespace
{
using BaseObjectType = GtkWidget;
using BaseClassType = GtkWidgetClass;

// These callback functions are called from GLib (a C library).
// They shall have C linkage. (Many compilers accept callback functions
// with C++ linkage, but such a program has undefined behavior.)
//
// If you want the functions with C linkage to have internal linkage,
// they must be declared 'static', even though they are defined in an anonymous
// namespace. The compiler respects namespace declarations of functions
// with C linkage, but the linker does not.
extern "C"
{
// Extra class init function.
static void class_init_function(void* g_class, void* class_data)
{
  g_return_if_fail(GTK_IS_WIDGET_CLASS(g_class));

  const auto klass = static_cast<BaseClassType*>(g_class);
  const auto css_name = static_cast<Glib::ustring*>(class_data);

  gtk_widget_class_set_css_name(klass, css_name->c_str());
}

// Extra instance init function.
static void instance_init_function(GTypeInstance* instance, void* /* g_class */)
{
  g_return_if_fail(GTK_IS_WIDGET(instance));

  // Nothing to do here.
  // This extra instance init function just shows how such a function can
  // be added to a custom widget, if necessary.
}
} // extern "C"
} // anonymous namespace

MyExtraInit::MyExtraInit(const Glib::ustring& css_name)
:
Glib::ExtraClassInit(class_init_function, &m_css_name, instance_init_function),
m_css_name(css_name)
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>custom_gtkmm.css</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[/* Example of a CSS style sheet. */

my-button {
  background-color: red;
  color:            blue;
  padding:          10px 15px 20px 5px; /* top right bottom left */
  border:           solid black 2px;
  border-radius:    8px;   
}
my-button:active {
  background-color: rgb(0,255,0);
}
#my-label1 {
  background-color: rgb(180,180,180);
  color:            rgb(0,255,255);
  padding:          10px 15px 10px 25px; /* top right bottom left */
}
#my-label1:hover {
  background-color: rgb(220,220,220);
}
.my-label2 {
  background-color: rgb(180,180,100);
  color:            black;
  padding:          5px 15px 5px 25px; /* top right bottom left */
}
.my-label2:hover {
  background-color: rgb(220,220,140);
}
]]></code></programlisting>
<!-- end inserted example code -->
</section>
</section>

</chapter>

<chapter xml:id="chapter-multi-threaded-programs">
<title>Vícevláknové programy</title>

<section xml:id="sec-the-constraints">
<title>Omezení</title>

<para xml:lang="en">
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.
<footnote>
<para xml:lang="en">
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.
</para>
</footnote>
</para>

<section xml:id="the-rules">
<title>Pravidla</title>

<para>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).</para>

<orderedlist inheritnum="ignore" continuation="restarts">

<listitem>
<para>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).</para>
</listitem>

<listitem>
<para>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ě.</para>
</listitem>

<listitem>
<para>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.</para>
</listitem>

<listitem>
<para xml:lang="en">
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.
</para>
</listitem>

<listitem>
<para>Pokud 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.</para>
</listitem>

<listitem>
<para>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í.</para>
<para xml:lang="en">
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>.
</para>
</listitem>

</orderedlist>

</section>

</section>

<section xml:id="sec-using-glib-dispatcher">
<title>Používání Glib::Dispatcher</title>

<para>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>. </para>

<para>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).</para>

<para xml:lang="en">
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).
</para>

<para xml:lang="en">
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.
</para>

</section>

<section xml:id="sec-multithread-example">
<title>Příklad</title>

<para>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>.</para>

<para xml:lang="en">
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>std::mutex</classname>.
Only the GUI thread updates the GUI.
</para>

<para xml:lang="en">
Compiling and linking a multi-threaded program can require special compiler and
linker options. If you use the <application>g++</application> compiler, add the
<literal>-pthread</literal> option. Other compilers may require other options.
If you build with <application>meson</application>, it handles the multi-threading
complications for you, if you add <function>dependency('threads')</function>.
</para>

<figure xml:id="figure-multithread">
  <title>Vícevláknový program</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/multithread.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/multithread">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>examplewindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include "exampleworker.h"

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();

  // Called from the worker thread.
  void notify();

private:
  // Signal handlers.
  void on_start_button_clicked();
  void on_stop_button_clicked();
  void on_quit_button_clicked();

  void update_start_stop_buttons();
  void update_widgets();

  // Dispatcher handler.
  void on_notification_from_worker_thread();

  // Member data.
  Gtk::Box m_VBox;
  Gtk::Box m_ButtonBox;
  Gtk::Button m_ButtonStart;
  Gtk::Button m_ButtonStop;
  Gtk::Button m_ButtonQuit;
  Gtk::ProgressBar m_ProgressBar;
  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TextView m_TextView;

  Glib::Dispatcher m_Dispatcher;
  ExampleWorker m_Worker;
  std::thread* m_WorkerThread;
};

#endif // GTKMM_EXAMPLEWINDOW_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleworker.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEWORKER_H
#define GTKMM_EXAMPLEWORKER_H

#include <gtkmm.h>
#include <thread>
#include <mutex>

class ExampleWindow;

class ExampleWorker
{
public:
  ExampleWorker();

  // Thread function.
  void do_work(ExampleWindow* caller);

  void get_data(double* fraction_done, Glib::ustring* message) const;
  void stop_work();
  bool has_stopped() const;

private:
  // Synchronizes access to member data.
  mutable std::mutex m_Mutex;

  // Data used by both GUI thread and worker thread.
  bool m_shall_stop;
  bool m_has_stopped;
  double m_fraction_done;
  Glib::ustring m_message;
};

#endif // GTKMM_EXAMPLEWORKER_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>examplewindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow() :
  m_VBox(Gtk::Orientation::VERTICAL, 5),
  m_ButtonBox(Gtk::Orientation::HORIZONTAL),
  m_ButtonStart("Start work"),
  m_ButtonStop("Stop work"),
  m_ButtonQuit("_Quit", /* mnemonic= */ true),
  m_ProgressBar(),
  m_ScrolledWindow(),
  m_TextView(),
  m_Dispatcher(),
  m_Worker(),
  m_WorkerThread(nullptr)
{
  set_title("Multi-threaded example");
  set_default_size(300, 300);

  m_VBox.set_margin(5);
  set_child(m_VBox);

  // Add the ProgressBar.
  m_VBox.append(m_ProgressBar);

  m_ProgressBar.set_text("Fraction done");
  m_ProgressBar.set_show_text();

  // Add the TextView, inside a ScrolledWindow.
  m_ScrolledWindow.set_child(m_TextView);

  // Only show the scrollbars when they are necessary.
  m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
  m_ScrolledWindow.set_expand();

  m_VBox.append(m_ScrolledWindow);

  m_TextView.set_editable(false);

  // Add the buttons to the ButtonBox.
  m_VBox.append(m_ButtonBox);

  m_ButtonBox.append(m_ButtonStart);
  m_ButtonBox.append(m_ButtonStop);
  m_ButtonBox.append(m_ButtonQuit);
  m_ButtonBox.set_margin(5);
  m_ButtonBox.set_spacing(5);
  m_ButtonStart.set_hexpand(true);
  m_ButtonStart.set_halign(Gtk::Align::END);

  // Connect the signal handlers to the buttons.
  m_ButtonStart.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_start_button_clicked));
  m_ButtonStop.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_stop_button_clicked));
  m_ButtonQuit.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_quit_button_clicked));

  // Connect the handler to the dispatcher.
  m_Dispatcher.connect(sigc::mem_fun(*this, &ExampleWindow::on_notification_from_worker_thread));

  // Create a text buffer mark for use in update_widgets().
  auto buffer = m_TextView.get_buffer();
  buffer->create_mark("last_line", buffer->end(), /* left_gravity= */ true);

  update_start_stop_buttons();
}

void ExampleWindow::on_start_button_clicked()
{
  if (m_WorkerThread)
  {
    std::cout << "Can't start a worker thread while another one is running." << std::endl;
  }
  else
  {
    // Start a new worker thread.
    m_WorkerThread = new std::thread(
      [this]
      {
        m_Worker.do_work(this);
      });
  }
  update_start_stop_buttons();
}

void ExampleWindow::on_stop_button_clicked()
{
  if (!m_WorkerThread)
  {
    std::cout << "Can't stop a worker thread. None is running." << std::endl;
  }
  else
  {
   // Order the worker thread to stop.
    m_Worker.stop_work();
    m_ButtonStop.set_sensitive(false);
  }
}

void ExampleWindow::update_start_stop_buttons()
{
  const bool thread_is_running = m_WorkerThread != nullptr;

  m_ButtonStart.set_sensitive(!thread_is_running);
  m_ButtonStop.set_sensitive(thread_is_running);
}

void ExampleWindow::update_widgets()
{
  double fraction_done;
  Glib::ustring message_from_worker_thread;
  m_Worker.get_data(&fraction_done, &message_from_worker_thread);

  m_ProgressBar.set_fraction(fraction_done);

  if (message_from_worker_thread != m_TextView.get_buffer()->get_text())
  {
    auto buffer = m_TextView.get_buffer();
    buffer->set_text(message_from_worker_thread);

    // Scroll the last inserted line into view. That's somewhat complicated.
    auto iter = buffer->end();
    iter.set_line_offset(0); // Beginning of last line
    auto mark = buffer->get_mark("last_line");
    buffer->move_mark(mark, iter);
    m_TextView.scroll_to(mark);
    // TextView::scroll_to(iter) is not perfect.
    // We do need a TextMark to always get the last line into view.
  }
}

void ExampleWindow::on_quit_button_clicked()
{
  if (m_WorkerThread)
  {
    // Order the worker thread to stop and wait for it to stop.
    m_Worker.stop_work();
    if (m_WorkerThread->joinable())
      m_WorkerThread->join();
  }
  set_visible(false);
}

// notify() is called from ExampleWorker::do_work(). It is executed in the worker
// thread. It triggers a call to on_notification_from_worker_thread(), which is
// executed in the GUI thread.
void ExampleWindow::notify()
{
  m_Dispatcher.emit();
}

void ExampleWindow::on_notification_from_worker_thread()
{
  if (m_WorkerThread && m_Worker.has_stopped())
  {
    // Work is done.
    if (m_WorkerThread->joinable())
      m_WorkerThread->join();
    delete m_WorkerThread;
    m_WorkerThread = nullptr;
    update_start_stop_buttons();
  }
  update_widgets();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleworker.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleworker.h"
#include "examplewindow.h"
#include <sstream>
#include <chrono>

ExampleWorker::ExampleWorker() :
  m_Mutex(),
  m_shall_stop(false),
  m_has_stopped(false),
  m_fraction_done(0.0),
  m_message()
{
}

// Accesses to these data are synchronized by a mutex.
// Some microseconds can be saved by getting all data at once, instead of having
// separate get_fraction_done() and get_message() methods.
void ExampleWorker::get_data(double* fraction_done, Glib::ustring* message) const
{
  std::lock_guard<std::mutex> lock(m_Mutex);

  if (fraction_done)
    *fraction_done = m_fraction_done;

  if (message)
    *message = m_message;
}

void ExampleWorker::stop_work()
{
  std::lock_guard<std::mutex> lock(m_Mutex);
  m_shall_stop = true;
}

bool ExampleWorker::has_stopped() const
{
  std::lock_guard<std::mutex> lock(m_Mutex);
  return m_has_stopped;
}

void ExampleWorker::do_work(ExampleWindow* caller)
{
  {
    std::lock_guard<std::mutex> lock(m_Mutex);
    m_has_stopped = false;
    m_fraction_done = 0.0;
    m_message = "";
  } // The mutex is unlocked here by lock's destructor.

  // Simulate a long calculation.
  for (int i = 0; ; ++i) // do until break
  {
    std::this_thread::sleep_for(std::chrono::milliseconds(250));

    {
      std::lock_guard<std::mutex> lock(m_Mutex);

      m_fraction_done += 0.01;

      if (i % 4 == 3)
      {
        std::ostringstream ostr;
        ostr << (m_fraction_done * 100.0) << "% done\n";
        m_message += ostr.str();
      }

      if (m_fraction_done >= 1.0)
      {
        m_message += "Finished";
        break;
      }
      if (m_shall_stop)
      {
        m_message += "Stopped";
        break;
      }
    }

    caller->notify();
  }

  {
    std::lock_guard<std::mutex> lock(m_Mutex);
    m_shall_stop = false;
    m_has_stopped = true;
  }

  caller->notify();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app->make_window_and_run<ExampleWindow>(argc, argv);
}
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</chapter>

<chapter xml:id="chapter-recommended-techniques">
<title>Doporučené techniky</title>

<para>V této kapitole je taková všehochuť mouder, obecných pokynů a rad k vytváření aplikací s <application>gtkmm</application>.</para>

<para xml:lang="en">Use <application>Meson</application>! It is your friend :)
    It examines C and C++ files, determines how they depend on each other,
    and generates <filename>build.ninja</filename> or an equivalent file so the
    files can be compiled in the correct order. <application>Meson</application>
    permits automatic configuration of software installation, handling a large
    number of system quirks to increase portability.
</para>

<para>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.</para>

<para xml:lang="en">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 use 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.</para>

<section xml:id="sec-application-lifetime">
<title>Životnost aplikace</title>
<para xml:lang="en">Most applications will have only one <classname>Window</classname>, or
    only one main window. These applications can use
    <methodname>Gtk::Application::make_window_and_run(int argc, char** argv, T_Args&amp;&amp;... args)</methodname>.
    It creates and shows a window. When the window is hidden, <methodname>make_window_and_run()</methodname>
    deletes the window and returns to the caller.
    This might happen when the user closes the window, or when your code decides to
    hide the window with <methodname>set_visible(false)</methodname>. You can prevent the user from
    closing the window (for instance, if there are unsaved changes) by
    overriding <methodname>Gtk::Window::on_close_request()</methodname>.</para>
<para>Většina našich příkladů používá tuto techniku.</para>
</section>

<section xml:id="sec-using-a-gtkmm-widget">
<title>Používání widgetů <application>gtkmm</application></title>

<para>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ů:</para>

<para>

<orderedlist inheritnum="ignore" continuation="restarts">
<listitem>
<para xml:lang="en">
Declare 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> or <function>Gtk::make_managed()</function> in your code.
</para>
</listitem>

<listitem>
<para xml:lang="en">
 Set the attributes of the widget. If the widget has no default constructor,
 then you will need to initialize the widget in the initializer list of your
 container class's constructor.
</para>
</listitem>

<listitem>
<para>Napojit případné signály, které si přejete používat s příslušnou obsluhou.</para>
</listitem>

<listitem>
<para xml:lang="en">
Pack the widget into a container using the appropriate call,
e.g. <methodname>Gtk::Box::append()</methodname>.
</para>
</listitem>

</orderedlist>

</para>

<para xml:lang="en">
If you don't want all widgets to be shown, call <methodname>Gtk::Widget::set_visible(false)</methodname>
on the widgets that you don't want to show. If a container widget is hidden, all
of its child widgets are also hidden, even if <methodname>set_visible(false)</methodname> is
not called on the child widgets.
</para>

</section>
</chapter>

<chapter xml:id="chapter-building-applications">
<title xml:lang="en">Building applications</title>

<para xml:lang="en">
This chapter is similar to <emphasis>Building applications</emphasis> and following sections in the
<link xlink:href="https://docs.gtk.org/gtk4/getting_started.html">Getting Started</link>
chapter in the GTK documentation.
The same application is built, but <application>gtkmm</application> is used instead of <application>GTK</application>.
</para>
<para xml:lang="en">
An application consists of a number of files:
<variablelist>
  <varlistentry>
    <term xml:lang="en">The binary file</term>
    <listitem><para xml:lang="en">This gets installed in <filename>/usr/bin</filename>.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">A desktop file</term>
    <listitem><para xml:lang="en">The desktop file provides important information about the application
      to the desktop shell, such as its name, icon, D-Bus name, commandline to launch it,
      etc. It is installed in <filename>/usr/share/applications</filename>.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">An icon</term>
    <listitem><para xml:lang="en">The icon gets installed in <filename>/usr/share/icons/hicolor/48x48/apps</filename>,
      where it will be found regardless of the current theme.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">A settings schema</term>
    <listitem><para xml:lang="en">If the application uses <classname>Gio::Settings</classname>,
      it will install its schema in <filename>/usr/share/glib-2.0/schemas</filename>,
      so that tools like dconf-editor can find it.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">Other resources</term>
    <listitem><para xml:lang="en">Other files, such as <classname>Gtk::Builder</classname> ui files,
      are best loaded from resources stored in the application binary itself. This
      eliminates the need for most of the files that would traditionally be installed
      in an application-specific location in <filename>/usr/share</filename>.</para></listitem>
  </varlistentry>
</variablelist>
</para>

<para xml:lang="en">
<application>gtkmm</application> includes application support that is built on top of <classname>Gio::Application</classname>.
In this chapter we'll build a simple application by starting from scratch, adding more
and more pieces over time. Along the way, we'll learn about <classname>Gtk::Application</classname>,
<classname>Gtk::Builder</classname>, resources, menus, settings,
<classname>Gtk::HeaderBar</classname>, <classname>Gtk::Stack</classname>,
<classname>Gtk::SearchBar</classname>, <classname>Gtk::ListBox</classname>, and more.
</para>

<para xml:lang="en">
The full, buildable sources for these examples can be found in the
<filename>examples/book/buildapp</filename> directory of the
<application>gtkmm-documentation</application> source distribution, or online in the
<link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp"><application>gtkmm-documentation</application>
git repository</link>. You can build each example separately by using <command>meson</command>
and <command>ninja</command> with the <filename>meson.build</filename> file or by using
<command>make</command> with the <filename>Makefile.example</filename> file. For more
information, see the <filename>README</filename> included in the <filename>buildapp</filename>
directory.
</para>

<section xml:id="sec-buildapp-trivial-app">
<title xml:lang="en">A trivial application</title>

<para xml:lang="en">
When using <classname>Gtk::Application</classname>, the <function>main()</function> function
can be very simple. We just call <methodname>Gtk::Application::run()</methodname> on an
instance of our application class.
</para>

<para xml:lang="en">
All the application logic is in the application class, which is a subclass of
<classname>Gtk::Application</classname>. Our example does not yet have any interesting
functionality. All it does is open a window when it is activated without arguments,
and open the files it is given, if it is started with arguments. (Or rather, our
application class tries to open the files, but our subclassed application window
does not yet do what it's told to do.)
</para>

<para xml:lang="en">
To handle these two cases, we override <methodname>signal_activate()</methodname>'s
default handler, which gets called when the application is launched without commandline
arguments, and <methodname>signal_open()</methodname>'s default handler, which gets
called when the application is launched with commandline arguments.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1Application.html">Gio::Application Reference</link></para>
<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Application.html">Gtk::Application Reference</link></para>

<para xml:lang="en">
Another important class that is part of the application support in <application>gtkmm</application> is
<classname>Gtk::ApplicationWindow</classname>. It is typically subclassed as well.
Our subclass does not do anything yet, so we will just get an empty window.
</para>

<para xml:lang="en">
As part of the initial setup of our application, we also create an icon and a desktop file.
Note that @bindir@ in the desktop file needs to be replaced with the actual path
to the binary before this desktop file can be used.
</para>

<para xml:lang="en">
Here is what we've achieved so far:
</para>

<figure xml:id="figure-buildapp-trivial-app">
  <title xml:lang="en">A trivial application</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_trivial_app.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en">
This does not look very impressive yet, but our application is already presenting itself
on the session bus, it has single-instance semantics, and it accepts files as commandline arguments.
</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step1">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPLICATION_H
#define GTKMM_EXAMPLEAPPLICATION_H

#include <gtkmm.h>

class ExampleAppWindow;

class ExampleApplication: public Gtk::Application
{
protected:
  ExampleApplication();

public:
  static Glib::RefPtr<ExampleApplication> create();

protected:
  // Override default signal handlers:
  void on_activate() override;
  void on_open(const Gio::Application::type_vec_files& files,
    const Glib::ustring& hint) override;

private:
  ExampleAppWindow* create_appwindow();
};

#endif /* GTKMM_EXAMPLEAPPLICATION_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"
#include "exampleappwindow.h"

ExampleApplication::ExampleApplication()
: Gtk::Application("org.gtkmm.examples.application", Gio::Application::Flags::HANDLES_OPEN)
{
}

Glib::RefPtr<ExampleApplication> ExampleApplication::create()
{
  return Glib::make_refptr_for_instance<ExampleApplication>(new ExampleApplication());
}

ExampleAppWindow* ExampleApplication::create_appwindow()
{
  auto appwindow = new ExampleAppWindow();

  // Make sure that the application runs for as long this window is still open.
  add_window(*appwindow);

  // A window can be added to an application with Gtk::Application::add_window()
  // or Gtk::Window::set_application(). When all added windows have been hidden
  // or removed, the application stops running (Gtk::Application::run() returns()),
  // unless Gio::Application::hold() has been called.

  // Delete the window when it is hidden.
  appwindow->signal_hide().connect([appwindow](){ delete appwindow; });

  return appwindow;
}

void ExampleApplication::on_activate()
{
  // The application has been started, so let's show a window.
  auto appwindow = create_appwindow();
  appwindow->present();
}

void ExampleApplication::on_open(const Gio::Application::type_vec_files& files,
  const Glib::ustring& /* hint */)
{
  // The application has been asked to open some files,
  // so let's open a new view for each one.
  ExampleAppWindow* appwindow = nullptr;
  auto windows = get_windows();
  if (windows.size() > 0)
    appwindow = dynamic_cast<ExampleAppWindow*>(windows[0]);

  if (!appwindow)
    appwindow = create_appwindow();

  for (const auto& file : files)
    appwindow->open_file_view(file);

  appwindow->present();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"

ExampleAppWindow::ExampleAppWindow()
: Gtk::ApplicationWindow()
{
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& /* file */)
{
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"

int main(int argc, char* argv[])
{
  auto application = ExampleApplication::create();

  // Start the application, showing the initial window,
  // and opening extra views for any files that it is asked to open,
  // for instance as a command-line parameter.
  // run() will return when the last window has been closed.
  return application->run(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapp.desktop.in</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[[Desktop Entry]
Type=Application
Name=Gtkmm example
GenericName=Example
Comment=From the "Programming with gtkmm 4" tutorial
Icon=exampleapp
StartupNotify=true
Exec=@bindir@/exampleapp %U
Categories=GNOME;GTK;Utility
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-populating-window">
<title xml:lang="en">Populating the window</title>

<para xml:lang="en">
In this step, we use a <classname>Gtk::Builder</classname> instance to associate a
<classname>Gtk::Builder</classname> ui file with our application window class.
</para>

<para xml:lang="en">
Our simple ui file gives the window a title, and puts a <classname>Gtk::Stack</classname>
widget as the main content.
</para>

<para xml:lang="en">
To make use of this file in our application, we revisit our
<classname>Gtk::ApplicationWindow</classname> subclass, and call
<methodname>Gtk::Builder::create_from_resource()</methodname> and
<methodname>Gtk::Builder::get_widget_derived()</methodname> from the
<methodname>ExampleAppWindow::create()</methodname> method to get an instance of
our subclassed <classname>Gtk::ApplicationWindow</classname>. See the
<link linkend="sec-builder-using-derived-widgets">Using derived widgets</link> section
for more information about <methodname>get_widget_derived()</methodname>.
</para>

<para xml:lang="en">
You may have noticed that we use the <methodname>_from_resource()</methodname> variant
of the method that reads the ui file. Now we need to use <application>GLib</application>'s
resource functionality to include the ui file in the binary. This is commonly done by
listing all resources in a .gresource.xml file.
This file has to be converted into a C source file that will be compiled and linked
into the application together with the other source files. To do so, we use the
<application>glib-compile-resources</application> utility:
<screen xml:lang="en">$ glib-compile-resources --target=resources.c --generate-source exampleapp.gresource.xml</screen>
The <link linkend="sec-gio-resource">Gio::Resource and glib-compile-resources</link>
section contains more information about resource files. If you build with Meson,
use the <function>compile_resources()</function> function in Meson's
<link xlink:href="https://mesonbuild.com/Gnome-module.html">GNOME module</link>.
</para>

<para xml:lang="en">
Our application now looks like this:
</para>

<figure xml:id="figure-buildapp-populating-window">
  <title xml:lang="en">Populating the window</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_populating_window.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step2">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step1/exampleapplication.h"
// Equal to the corresponding file in step1
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  Glib::RefPtr<Gtk::Builder> m_refBuilder;
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"
#include "exampleappwindow.h"
#include <iostream>
#include <exception>

ExampleApplication::ExampleApplication()
: Gtk::Application("org.gtkmm.examples.application", Gio::Application::Flags::HANDLES_OPEN)
{
}

Glib::RefPtr<ExampleApplication> ExampleApplication::create()
{
  return Glib::make_refptr_for_instance<ExampleApplication>(new ExampleApplication());
}

ExampleAppWindow* ExampleApplication::create_appwindow()
{
  auto appwindow = ExampleAppWindow::create();

  // Make sure that the application runs for as long this window is still open.
  add_window(*appwindow);

  // A window can be added to an application with Gtk::Application::add_window()
  // or Gtk::Window::set_application(). When all added windows have been hidden
  // or removed, the application stops running (Gtk::Application::run() returns()),
  // unless Gio::Application::hold() has been called.

  // Delete the window when it is hidden.
  appwindow->signal_hide().connect([appwindow](){ delete appwindow; });

  return appwindow;
}

void ExampleApplication::on_activate()
{
  try
  {
    // The application has been started, so let's show a window.
    auto appwindow = create_appwindow();
    appwindow->present();
  }
  // If create_appwindow() throws an exception (perhaps from Gtk::Builder),
  // no window has been created, no window has been added to the application,
  // and therefore the application will stop running.
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_activate(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_activate(): " << ex.what() << std::endl;
  }
}

void ExampleApplication::on_open(const Gio::Application::type_vec_files& files,
  const Glib::ustring& /* hint */)
{
  // The application has been asked to open some files,
  // so let's open a new view for each one.
  ExampleAppWindow* appwindow = nullptr;
  auto windows = get_windows();
  if (windows.size() > 0)
    appwindow = dynamic_cast<ExampleAppWindow*>(windows[0]);

  try
  {
    if (!appwindow)
      appwindow = create_appwindow();

    for (const auto& file : files)
      appwindow->open_file_view(file);

    appwindow->present();
  }
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_open(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_open(): " << ex.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <stdexcept>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& /* file */)
{
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step1/main.cc"
// Equal to the corresponding file in step1
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapp.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gtkmm/exampleapp">
    <file preprocess="xml-stripblanks">window.ui</file>
  </gresource>
</gresources>
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkStack" id="stack"/>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-opening-files">
<title xml:lang="en">Opening files</title>

<para xml:lang="en">
In this step, we make our application show the contents of all the files that it is
given on the commandline.
</para>

<para xml:lang="en">
To this end, we add a data member to our application window and keep a pointer to the
<classname>Gtk::Stack</classname> there. We get the pointer with a call to
<methodname>Gtk::Builder::get_widget()</methodname> in the application window's constructor.
</para>

<para xml:lang="en">
Now we revisit the <methodname>ExampleAppWindow::open_file_view()</methodname> method
that is called for each commandline argument, and construct a <classname>Gtk::TextView</classname>
that we then add as a page to the stack.
</para>

<para xml:lang="en">
Lastly, we add a <classname>Gtk::StackSwitcher</classname> to the titlebar area
in the ui file, and we tell it to display information about our stack.
</para>

<para xml:lang="en">
The stack switcher gets all its information it needs to display tabs from
the stack that it belongs to. Here, we are passing the label to show for
each file as the last argument to the <methodname>Gtk::Stack::add()</methodname>
method.
</para>

<para xml:lang="en">
Our application is beginning to take shape:
</para>

<figure xml:id="figure-buildapp-opening-files">
  <title xml:lang="en">Opening files</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_opening_files.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step3">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step1/exampleapplication.h"
// Equal to the corresponding file in step1
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Gtk::Stack* m_stack {nullptr};
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step2/exampleapplication.cc"
// Equal to the corresponding file in step2
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    view->get_buffer()->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step1/main.cc"
// Equal to the corresponding file in step1
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header">
        <child type="title">
          <object class="GtkStackSwitcher" id="tabs">
            <property name="stack">stack</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkStack" id="stack"/>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-menu">
<title xml:lang="en">A menu</title>

<para xml:lang="en">
The menu is shown at the right side of the headerbar. It is meant to collect
infrequently used actions that affect the whole application.
</para>

<para xml:lang="en">
Just like the application window, we specify our menu in a ui file, and add it
as a resource to our binary.
</para>

<para xml:lang="en">
To make the menu appear, we have to load the ui file and associate the
resulting menu model with the menu button that we've added to the headerbar.
Since menus work by activating <classname>Gio::Action</classname>s, we also
have to add a suitable set of actions to our application.
</para>

<para xml:lang="en">
Adding the actions is best done in the <methodname>on_startup()</methodname> default
signal handler, which is guaranteed to be called once for each primary application instance.
</para>

<para xml:lang="en">
Our preferences menu item does not do anything yet, but the Quit menu item is fully
functional. It can also be activated by the usual Ctrl-Q shortcut. The shortcut
is added with <methodname>Gtk::Application::set_accel_for_action()</methodname>.
</para>

<para xml:lang="en">
The menu looks like this:
</para>

<figure xml:id="figure-buildapp-menu">
  <title xml:lang="en">A menu</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_menu.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step4">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPLICATION_H
#define GTKMM_EXAMPLEAPPLICATION_H

#include <gtkmm.h>

class ExampleAppWindow;

class ExampleApplication: public Gtk::Application
{
protected:
  ExampleApplication();

public:
  static Glib::RefPtr<ExampleApplication> create();

protected:
  // Override default signal handlers:
  void on_startup() override;
  void on_activate() override;
  void on_open(const Gio::Application::type_vec_files& files,
    const Glib::ustring& hint) override;

private:
  ExampleAppWindow* create_appwindow();
  void on_action_preferences();
  void on_action_quit();
};

#endif /* GTKMM_EXAMPLEAPPLICATION_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Gtk::Stack* m_stack {nullptr};
  Gtk::MenuButton* m_gears {nullptr};
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"
#include "exampleappwindow.h"
#include <iostream>
#include <exception>

ExampleApplication::ExampleApplication()
: Gtk::Application("org.gtkmm.examples.application", Gio::Application::Flags::HANDLES_OPEN)
{
}

Glib::RefPtr<ExampleApplication> ExampleApplication::create()
{
  return Glib::make_refptr_for_instance<ExampleApplication>(new ExampleApplication());
}

ExampleAppWindow* ExampleApplication::create_appwindow()
{
  auto appwindow = ExampleAppWindow::create();

  // Make sure that the application runs for as long this window is still open.
  add_window(*appwindow);

  // A window can be added to an application with Gtk::Application::add_window()
  // or Gtk::Window::set_application(). When all added windows have been hidden
  // or removed, the application stops running (Gtk::Application::run() returns()),
  // unless Gio::Application::hold() has been called.

  // Delete the window when it is hidden.
  appwindow->signal_hide().connect([appwindow](){ delete appwindow; });

  return appwindow;
}

void ExampleApplication::on_startup()
{
  // Call the base class's implementation.
  Gtk::Application::on_startup();

  // Add actions and keyboard accelerators for the menu.
  add_action("preferences", sigc::mem_fun(*this, &ExampleApplication::on_action_preferences));
  add_action("quit", sigc::mem_fun(*this, &ExampleApplication::on_action_quit));
  set_accel_for_action("app.quit", "<Ctrl>Q");
}

void ExampleApplication::on_activate()
{
  try
  {
    // The application has been started, so let's show a window.
    auto appwindow = create_appwindow();
    appwindow->present();
  }
  // If create_appwindow() throws an exception (perhaps from Gtk::Builder),
  // no window has been created, no window has been added to the application,
  // and therefore the application will stop running.
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_activate(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_activate(): " << ex.what() << std::endl;
  }
}

void ExampleApplication::on_open(const Gio::Application::type_vec_files& files,
  const Glib::ustring& /* hint */)
{
  // The application has been asked to open some files,
  // so let's open a new view for each one.
  ExampleAppWindow* appwindow = nullptr;
  auto windows = get_windows();
  if (windows.size() > 0)
    appwindow = dynamic_cast<ExampleAppWindow*>(windows[0]);

  try
  {
    if (!appwindow)
      appwindow = create_appwindow();

    for (const auto& file : files)
      appwindow->open_file_view(file);

    appwindow->present();
  }
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_open(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_open(): " << ex.what() << std::endl;
  }
}

void ExampleApplication::on_action_preferences()
{

}

void ExampleApplication::on_action_quit()
{
  // Gio::Application::quit() will make Gio::Application::run() return,
  // but it's a crude way of ending the program. The window is not removed
  // from the application. Neither the window's nor the application's
  // destructors will be called, because there will be remaining reference
  // counts in both of them. If we want the destructors to be called, we
  // must remove the window from the application. One way of doing this
  // is to hide the window. See comment in create_appwindow().
  auto windows = get_windows();
  for (auto window : windows)
    window->set_visible(false);

  // Not really necessary, when Gtk::Widget::set_visible(false) is called,
  // unless Gio::Application::hold() has been called without a corresponding
  // call to Gio::Application::release().
  quit();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  // Get widgets from the Gtk::Builder file.
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");

  m_gears = m_refBuilder->get_widget<Gtk::MenuButton>("gears");
  if (!m_gears)
    throw std::runtime_error("No \"gears\" object in window.ui");

  // Connect the menu to the MenuButton m_gears.
  // (The connection between action and menu item is specified in gears_menu.ui.)
  auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
  auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
  if (!menu)
    throw std::runtime_error("No \"menu\" object in gears_menu.ui");

  m_gears->set_menu_model(menu);
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    view->get_buffer()->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step1/main.cc"
// Equal to the corresponding file in step1
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapp.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gtkmm/exampleapp">
    <file preprocess="xml-stripblanks">window.ui</file>
    <file preprocess="xml-stripblanks">gears_menu.ui</file>
  </gresource>
</gresources>
]]></code></programlisting>
<para xml:lang="en">File: <filename>gears_menu.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <menu id="menu">
    <section>
      <item>
        <attribute name="label" translatable="yes">_Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
    <section>
      <item>
        <attribute name="label" translatable="yes">_Quit</attribute>
        <attribute name="action">app.quit</attribute>
      </item>
    </section>
  </menu>
</interface>
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header">
        <child type="title">
          <object class="GtkStackSwitcher" id="tabs">
            <property name="stack">stack</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkMenuButton" id="gears">
            <property name="direction">none</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkStack" id="stack"/>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-pref-dialog">
<title xml:lang="en">A preference dialog</title>

<para xml:lang="en">
A typical application will have some preferences that should be remembered from one run
to the next. Even for our simple example application, we may want to change the font
that is used for the content.
</para>

<para xml:lang="en">
We are going to use <classname>Gio::Settings</classname> to store our preferences.
<classname>Gio::Settings</classname> requires a schema that describes our settings,
in our case the <filename>org.gtkmm.exampleapp.gschema.xml</filename> file.
</para>

<para xml:lang="en">
Before we can make use of this schema in our application, we need to compile it into
the binary form that <classname>Gio::Settings</classname> expects. GIO provides macros
to do this in autotools-based projects. See the description of
<link xlink:href="https://docs.gtk.org/gio/class.Settings.html">GSettings</link>.
Meson provides the <function>compile_schemas()</function> function in the
<link xlink:href="https://mesonbuild.com/Gnome-module.html">GNOME module</link>.
</para>

<para xml:lang="en">
Next, we need to connect our settings to the widgets that they are supposed to control.
One convenient way to do this is to use <methodname>Gio::Settings::bind()</methodname>
to bind settings keys to object properties, as we do for the transition setting in
<classname>ExampleAppWindow</classname>'s constructor.
</para>
<programlisting xml:lang="en"><code>m_settings = Gio::Settings::create("org.gtkmm.exampleapp");
m_settings-&gt;bind("transition", m_stack-&gt;property_transition_type());
</code></programlisting>

<para xml:lang="en">
The code to connect the font setting is a little more involved, since it corresponds to
an object property in a <classname>Gtk::TextTag</classname> that we must first create.
The code is in <methodname>ExampleAppWindow::open_file_view()</methodname>.
</para>
<programlisting xml:lang="en"><code>auto tag = buffer-&gt;create_tag();
m_settings-&gt;bind("font", tag-&gt;property_font());
buffer-&gt;apply_tag(tag, buffer-&gt;begin(), buffer-&gt;end());
</code></programlisting>

<para xml:lang="en">
At this point, the application will already react if you change one of the settings,
e.g. using the <command>gsettings</command> commandline tool. Of course, we expect
the application to provide a preference dialog for these. So lets do that now.
Our preference dialog will be a subclass of <classname>Gtk::Window</classname>, and
we'll use the same techniques that we've already seen in <classname>ExampleAppWindow</classname>:
a <classname>Gtk::Builder</classname> ui file and settings bindings.
In this case the bindings are more involved, though. We use
<classname>Gtk::FontDialogButton</classname> and <classname>Gtk::DropDown</classname>
in the preference dialog. The types of the properties in these classes can't be
automatically converted to the string type that <classname>Gio::Settings</classname> requires.
</para>

<para xml:lang="en">
When we've created the <filename>prefs.ui</filename> file and the <classname>ExampleAppPrefs</classname>
class, we revisit the <methodname>ExampleApplication::on_action_preferences()</methodname>
method in our application class, and make it open a new preference dialog.
</para>
<programlisting xml:lang="en"><code>auto prefs_dialog = ExampleAppPrefs::create(*get_active_window());
prefs_dialog-&gt;present();
</code></programlisting>

<para xml:lang="en">
After all this work, our application can now show a preference dialog like this:
</para>

<figure xml:id="figure-buildapp-pref-dialog">
  <title xml:lang="en">A preference dialog</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_pref_dialog.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step5">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step4/exampleapplication.h"
// Equal to the corresponding file in step4
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPPREFS_H_
#define GTKMM_EXAMPLEAPPPREFS_H_

#include <gtkmm.h>

#ifdef GLIBMM_CHECK_VERSION
#define HAS_GIO_SETTINGS_BIND_WITH_MAPPING GLIBMM_CHECK_VERSION(2,75,0)
#else
#define HAS_GIO_SETTINGS_BIND_WITH_MAPPING 0
#endif

class ExampleAppPrefs : public Gtk::Window
{
public:
  ExampleAppPrefs(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppPrefs* create(Gtk::Window& parent);

protected:
#if HAS_GIO_SETTINGS_BIND_WITH_MAPPING
  // Mappings from Gio::Settings to properties
  static std::optional<unsigned int> map_from_ustring_to_int(const Glib::ustring& transition);
  static std::optional<Glib::ustring> map_from_int_to_ustring(const unsigned int& pos);
#else
  // Signal handlers
  void on_font_setting_changed(const Glib::ustring& key);
  void on_font_selection_changed();
  void on_transition_setting_changed(const Glib::ustring& key);
  void on_transition_selection_changed();
#endif
  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::Settings> m_settings;
  Gtk::FontDialogButton* m_font {nullptr};
  Gtk::DropDown* m_transition {nullptr};
};

#endif /* GTKMM_EXAMPLEAPPPREFS_H_ */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::Settings> m_settings;
  Gtk::Stack* m_stack {nullptr};
  Gtk::MenuButton* m_gears {nullptr};
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"
#include "exampleappwindow.h"
#include "exampleappprefs.h"
#include <iostream>
#include <exception>

ExampleApplication::ExampleApplication()
: Gtk::Application("org.gtkmm.examples.application", Gio::Application::Flags::HANDLES_OPEN)
{
}

Glib::RefPtr<ExampleApplication> ExampleApplication::create()
{
  return Glib::make_refptr_for_instance<ExampleApplication>(new ExampleApplication());
}

ExampleAppWindow* ExampleApplication::create_appwindow()
{
  auto appwindow = ExampleAppWindow::create();

  // Make sure that the application runs for as long this window is still open.
  add_window(*appwindow);

  // A window can be added to an application with Gtk::Application::add_window()
  // or Gtk::Window::set_application(). When all added windows have been hidden
  // or removed, the application stops running (Gtk::Application::run() returns()),
  // unless Gio::Application::hold() has been called.

  // Delete the window when it is hidden.
  appwindow->signal_hide().connect([appwindow](){ delete appwindow; });

  return appwindow;
}

void ExampleApplication::on_startup()
{
  // Call the base class's implementation.
  Gtk::Application::on_startup();

  // Add actions and keyboard accelerators for the menu.
  add_action("preferences", sigc::mem_fun(*this, &ExampleApplication::on_action_preferences));
  add_action("quit", sigc::mem_fun(*this, &ExampleApplication::on_action_quit));
  set_accel_for_action("app.quit", "<Ctrl>Q");
}

void ExampleApplication::on_activate()
{
  try
  {
    // The application has been started, so let's show a window.
    auto appwindow = create_appwindow();
    appwindow->present();
  }
  // If create_appwindow() throws an exception (perhaps from Gtk::Builder),
  // no window has been created, no window has been added to the application,
  // and therefore the application will stop running.
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_activate(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_activate(): " << ex.what() << std::endl;
  }
}

void ExampleApplication::on_open(const Gio::Application::type_vec_files& files,
  const Glib::ustring& /* hint */)
{
  // The application has been asked to open some files,
  // so let's open a new view for each one.
  ExampleAppWindow* appwindow = nullptr;
  auto windows = get_windows();
  if (windows.size() > 0)
    appwindow = dynamic_cast<ExampleAppWindow*>(windows[0]);

  try
  {
    if (!appwindow)
      appwindow = create_appwindow();

    for (const auto& file : files)
      appwindow->open_file_view(file);

    appwindow->present();
  }
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_open(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_open(): " << ex.what() << std::endl;
  }
}

void ExampleApplication::on_action_preferences()
{
  try
  {
    auto prefs_dialog = ExampleAppPrefs::create(*get_active_window());
    prefs_dialog->present();

    // Delete the dialog when it is hidden.
    prefs_dialog->signal_hide().connect([prefs_dialog](){ delete prefs_dialog; });
  }
  catch (const Glib::Error& ex)
  {
    std::cerr << "ExampleApplication::on_action_preferences(): " << ex.what() << std::endl;
  }
  catch (const std::exception& ex)
  {
    std::cerr << "ExampleApplication::on_action_preferences(): " << ex.what() << std::endl;
  }
}

void ExampleApplication::on_action_quit()
{
  // Gio::Application::quit() will make Gio::Application::run() return,
  // but it's a crude way of ending the program. The window is not removed
  // from the application. Neither the window's nor the application's
  // destructors will be called, because there will be remaining reference
  // counts in both of them. If we want the destructors to be called, we
  // must remove the window from the application. One way of doing this
  // is to hide the window. See comment in create_appwindow().
  auto windows = get_windows();
  for (auto window : windows)
    window->set_visible(false);

  // Not really necessary, when Gtk::Widget::set_visible(false) is called,
  // unless Gio::Application::hold() has been called without a corresponding
  // call to Gio::Application::release().
  quit();
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappprefs.h"
#include "exampleappwindow.h"
#include <array>
#include <stdexcept>

namespace
{
struct TransitionTypeStruct
{
  Glib::ustring id;   // Value of "transition" key in Gio::Settings
  Glib::ustring text; // Text in the DropDown list
};

const std::array<TransitionTypeStruct, 3> transitionTypes =
{
  TransitionTypeStruct{"none",             "None"},
  TransitionTypeStruct{"crossfade",        "Fade"},
  TransitionTypeStruct{"slide-left-right", "Slide"}
};

} // anonymous namespace

ExampleAppPrefs::ExampleAppPrefs(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::Window(cobject),
  m_refBuilder(refBuilder)
{
  m_font = m_refBuilder->get_widget<Gtk::FontDialogButton>("font");
  if (!m_font)
    throw std::runtime_error("No \"font\" object in prefs.ui");

  m_transition = m_refBuilder->get_widget<Gtk::DropDown>("transition");
  if (!m_transition)
    throw std::runtime_error("No \"transition\" object in prefs.ui");

  // DropDown for transition type.
  auto string_list = Gtk::StringList::create();
  for (const auto& transitionType : transitionTypes)
    string_list->append(transitionType.text);

  m_transition->set_model(string_list);

  m_settings = Gio::Settings::create("org.gtkmm.exampleapp");

  // Connect preference properties to the Gio::Settings.
#if HAS_GIO_SETTINGS_BIND_WITH_MAPPING
  m_settings->bind<Glib::ustring, Pango::FontDescription>("font",
    m_font->property_font_desc(), Gio::Settings::BindFlags::DEFAULT,
    [](const auto& font) { return Pango::FontDescription(font); },
    [](const auto& fontdesc) { return fontdesc.to_string(); }
  );
  m_settings->bind<Glib::ustring, unsigned int>("transition",
    m_transition->property_selected(), Gio::Settings::BindFlags::DEFAULT,
    [](const auto& transition) { return map_from_ustring_to_int(transition); },
    [](const auto& pos) { return map_from_int_to_ustring(pos); }
  );
#else
  // This is easier when g_settings_bind_with_mapping() is
  // wrapped in a Gio::Settings method.
  m_settings->signal_changed("font").connect(
    sigc::mem_fun(*this, &ExampleAppPrefs::on_font_setting_changed));
  m_font->property_font_desc().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppPrefs::on_font_selection_changed));

  m_settings->signal_changed("transition").connect(
    sigc::mem_fun(*this, &ExampleAppPrefs::on_transition_setting_changed));
  m_transition->property_selected().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppPrefs::on_transition_selection_changed));

  // Synchronize the preferences dialog with m_settings.
  on_font_setting_changed("font");
  on_transition_setting_changed("transition");
#endif
}

//static
ExampleAppPrefs* ExampleAppPrefs::create(Gtk::Window& parent)
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/prefs.ui");

  auto dialog = Gtk::Builder::get_widget_derived<ExampleAppPrefs>(refBuilder, "prefs_dialog");
  if (!dialog)
    throw std::runtime_error("No \"prefs_dialog\" object in prefs.ui");

  dialog->set_transient_for(parent);

  return dialog;
}

#if HAS_GIO_SETTINGS_BIND_WITH_MAPPING
std::optional<unsigned int> ExampleAppPrefs::map_from_ustring_to_int(const Glib::ustring& transition)
{
  for (std::size_t i = 0; i < transitionTypes.size(); ++i)
  {
    if (transitionTypes[i].id == transition)
      return i;
  }
  return std::nullopt;
}

std::optional<Glib::ustring> ExampleAppPrefs::map_from_int_to_ustring(const unsigned int& pos)
{
  if (pos >= transitionTypes.size())
    return std::nullopt;
  return transitionTypes[pos].id;
}
#else
void ExampleAppPrefs::on_font_setting_changed(const Glib::ustring& /* key */)
{
  const auto font_setting = m_settings->get_string("font");
  const auto font_button = m_font->get_font_desc().to_string();
  if (font_setting != font_button)
    m_font->set_font_desc(Pango::FontDescription(font_setting));
}

void ExampleAppPrefs::on_font_selection_changed()
{
  const auto font_setting = m_settings->get_string("font");
  const auto font_button = m_font->get_font_desc().to_string();
  if (font_setting != font_button)
    m_settings->set_string("font", font_button);
}

void ExampleAppPrefs::on_transition_setting_changed(const Glib::ustring& /* key */)
{
  const auto transition_setting = m_settings->get_string("transition");
  const auto transition_button = transitionTypes[m_transition->get_selected()].id;
  if (transition_setting != transition_button)
  {
    for (std::size_t i = 0; i < transitionTypes.size(); ++i)
    {
      if (transitionTypes[i].id == transition_setting)
      {
        m_transition->set_selected(i);
        break;
      }
    }
  }
}

void ExampleAppPrefs::on_transition_selection_changed()
{
  const auto pos = m_transition->get_selected();
  if (pos >= transitionTypes.size())
    return;
  const auto transition_setting = m_settings->get_string("transition");
  const auto transition_button = transitionTypes[pos].id;
  if (transition_setting != transition_button)
    m_settings->set_string("transition", transition_button);
}
#endif
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  // Get widgets from the Gtk::Builder file.
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");

  m_gears = m_refBuilder->get_widget<Gtk::MenuButton>("gears");
  if (!m_gears)
    throw std::runtime_error("No \"gears\" object in window.ui");

  // Bind settings.
  m_settings = Gio::Settings::create("org.gtkmm.exampleapp");
  m_settings->bind("transition", m_stack->property_transition_type());

  // Connect the menu to the MenuButton m_gears.
  // (The connection between action and menu item is specified in gears_menu.ui.)
  auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
  auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
  if (!menu)
    throw std::runtime_error("No \"menu\" object in gears_menu.ui");

  m_gears->set_menu_model(menu);
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  auto buffer = view->get_buffer();
  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    buffer->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
  }

  auto tag = buffer->create_tag();
  m_settings->bind("font", tag->property_font());
  buffer->apply_tag(tag, buffer->begin(), buffer->end());
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"

int main(int argc, char* argv[])
{
  // Since this example is running uninstalled, we have to help it find its
  // schema. This is *not* necessary in a properly installed application.
  Glib::setenv ("GSETTINGS_SCHEMA_DIR", ".", false);

  auto application = ExampleApplication::create();

  // Start the application, showing the initial window,
  // and opening extra views for any files that it is asked to open,
  // for instance as a command-line parameter.
  // run() will return when the last window has been closed.
  return application->run(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapp.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gtkmm/exampleapp">
    <file preprocess="xml-stripblanks">window.ui</file>
    <file preprocess="xml-stripblanks">gears_menu.ui</file>
    <file preprocess="xml-stripblanks">prefs.ui</file>
  </gresource>
</gresources>
]]></code></programlisting>
<para xml:lang="en">File: <filename>prefs.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkWindow" id="prefs_dialog">
    <property name="title" translatable="yes">Preferences</property>
    <property name="resizable">False</property>
    <property name="modal">True</property>
    <property name="hide_on_close">True</property>
    <child>
      <object class="GtkGrid" id="grid">
        <property name="margin-start">12</property>
        <property name="margin-end">12</property>
        <property name="margin-top">12</property>
        <property name="margin-bottom">12</property>
        <property name="row-spacing">12</property>
        <property name="column-spacing">12</property>
        <child>
          <object class="GtkLabel" id="fontlabel">
            <property name="label">_Font:</property>
            <property name="use-underline">True</property>
            <property name="mnemonic-widget">font</property>
            <property name="xalign">1</property>
            <layout>
              <property name="column">0</property>
              <property name="row">0</property>
            </layout>
          </object>
        </child>
        <child>
          <object class="GtkFontDialogButton" id="font">
            <property name="dialog">
              <object class="GtkFontDialog"/>
            </property>
            <layout>
              <property name="column">1</property>
              <property name="row">0</property>
            </layout>
          </object>
        </child>
        <child>
          <object class="GtkLabel" id="transitionlabel">
            <property name="label">_Transition:</property>
            <property name="use-underline">True</property>
            <property name="mnemonic-widget">transition</property>
            <property name="xalign">1</property>
            <layout>
              <property name="column">0</property>
              <property name="row">1</property>
            </layout>
          </object>
        </child>
        <child>
          <object class="GtkDropDown" id="transition">
            <layout>
              <property name="column">1</property>
              <property name="row">1</property>
            </layout>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<para xml:lang="en">File: <filename>org.gtkmm.exampleapp.gschema.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
  <schema path="/org/gtkmm/exampleapp/" id="org.gtkmm.exampleapp">
    <key name="font" type="s">
      <default>'Monospace 12'</default>
      <summary>Font</summary>
      <description>The font to be used for content.</description>
    </key>
    <key name="transition" type="s">
      <choices>
        <choice value='none'/>
        <choice value='crossfade'/>
        <choice value='slide-left-right'/>
      </choices>
      <default>'none'</default>
      <summary>Transition</summary>
      <description>The transition to use when switching tabs.</description>
    </key>
  </schema>
</schemalist>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-search-bar">
<title xml:lang="en">Adding a search bar</title>

<para xml:lang="en">
We continue to flesh out the functionality of our application. For now, we add search.
<application>gtkmm</application> supports this with <classname>Gtk::SearchEntry</classname> and <classname>Gtk::SearchBar</classname>.
The search bar is a widget that can slide in from the top to present a search entry.
</para>

<para xml:lang="en">
We add a toggle button to the header bar, which can be used to slide out the search bar
below the header bar. The new widgets are added in the <filename>window.ui</filename> file.
</para>

<para xml:lang="en">
Implementing the search needs quite a few code changes that we are not going to completely
go over here. The central piece of the search implementation is a signal handler that
listens for text changes in the search entry, shown here without error handling.
</para>
<programlisting xml:lang="en"><code>void ExampleAppWindow::on_search_text_changed()
{
  const auto text = m_searchentry-&gt;get_text();
  auto tab = dynamic_cast&lt;Gtk::ScrolledWindow*&gt;(m_stack-&gt;get_visible_child());
  auto view = dynamic_cast&lt;Gtk::TextView*&gt;(tab-&gt;get_child());

  // Very simple-minded search implementation.
  auto buffer = view-&gt;get_buffer();
  Gtk::TextIter match_start;
  Gtk::TextIter match_end;
  if (buffer-&gt;begin().forward_search(text, Gtk::TextSearchFlags::CASE_INSENSITIVE,
      match_start, match_end))
  {
    buffer-&gt;select_range(match_start, match_end);
    view-&gt;scroll_to(match_start);
  }
}
</code></programlisting>

<para xml:lang="en">
With the search bar, our application now looks like this:
</para>

<figure xml:id="figure-buildapp-search-bar">
  <title xml:lang="en">Adding a search bar</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_search_bar.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step6">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step4/exampleapplication.h"
// Equal to the corresponding file in step4
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.h"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

#define HAS_SEARCH_ENTRY2 GTKMM_CHECK_VERSION(4,13,2)

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  // Signal handlers
  void on_search_text_changed();
  void on_visible_child_changed();

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::Settings> m_settings;
  Gtk::Stack* m_stack {nullptr};
  Gtk::ToggleButton* m_search {nullptr};
  Gtk::SearchBar* m_searchbar {nullptr};
#if HAS_SEARCH_ENTRY2
  Gtk::SearchEntry2* m_searchentry {nullptr};
#else
  Gtk::SearchEntry* m_searchentry {nullptr};
#endif
  Gtk::MenuButton* m_gears {nullptr};
  Glib::RefPtr<Glib::Binding> m_prop_binding;
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleapplication.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  // Get widgets from the Gtk::Builder file.
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");

  m_search = m_refBuilder->get_widget<Gtk::ToggleButton>("search");
  if (!m_search)
    throw std::runtime_error("No \"search\" object in window.ui");

  m_searchbar = m_refBuilder->get_widget<Gtk::SearchBar>("searchbar");
  if (!m_searchbar)
    throw std::runtime_error("No \"searchbar\" object in window.ui");

#if HAS_SEARCH_ENTRY2
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry2>("searchentry");
#else
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry>("searchentry");
#endif
  if (!m_searchentry)
    throw std::runtime_error("No \"searchentry\" object in window.ui");

  m_gears = m_refBuilder->get_widget<Gtk::MenuButton>("gears");
  if (!m_gears)
    throw std::runtime_error("No \"gears\" object in window.ui");

  // Bind settings.
  m_settings = Gio::Settings::create("org.gtkmm.exampleapp");
  m_settings->bind("transition", m_stack->property_transition_type());

  // Bind properties.
  m_prop_binding = Glib::Binding::bind_property(m_search->property_active(),
    m_searchbar->property_search_mode_enabled(), Glib::Binding::Flags::BIDIRECTIONAL);

  // Connect signal handlers.
  m_searchentry->signal_search_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_search_text_changed));
  m_stack->property_visible_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_visible_child_changed));

  // Connect the menu to the MenuButton m_gears.
  // (The connection between action and menu item is specified in gears_menu.ui.)
  auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
  auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
  if (!menu)
    throw std::runtime_error("No \"menu\" object in gears_menu.ui");

  m_gears->set_menu_model(menu);
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  auto buffer = view->get_buffer();
  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    buffer->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
    return;
  }

  auto tag = buffer->create_tag();
  m_settings->bind("font", tag->property_font());
  buffer->apply_tag(tag, buffer->begin(), buffer->end());

  m_search->set_sensitive(true);
}

void ExampleAppWindow::on_search_text_changed()
{
  const auto text = m_searchentry->get_text();
  if (text.empty())
    return;

  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible child." << std::endl;
    return;
  }

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible text view." << std::endl;
    return;
  }

  // Very simple-minded search implementation.
  auto buffer = view->get_buffer();
  Gtk::TextIter match_start;
  Gtk::TextIter match_end;
  if (buffer->begin().forward_search(text, Gtk::TextSearchFlags::CASE_INSENSITIVE,
      match_start, match_end))
  {
    buffer->select_range(match_start, match_end);
    view->scroll_to(match_start);
  }
}

void ExampleAppWindow::on_visible_child_changed()
{
  m_searchbar->set_search_mode(false);
}

]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleapplication.h"
#include "exampleappwindow.h"

int main(int argc, char* argv[])
{
#if HAS_SEARCH_ENTRY2
  // A GtkSearchEntry (e.g. from window.ui) shall be wrapped in
  // a Gtk::SearhcEntry2 and not in a deprecated Gtk::SearchEntry.
  Gtk::Application::wrap_in_search_entry2(true);
#endif

  // Since this example is running uninstalled, we have to help it find its
  // schema. This is *not* necessary in a properly installed application.
  Glib::setenv ("GSETTINGS_SCHEMA_DIR", ".", false);

  auto application = ExampleApplication::create();

  // Start the application, showing the initial window,
  // and opening extra views for any files that it is asked to open,
  // for instance as a command-line parameter.
  // run() will return when the last window has been closed.
  return application->run(argc, argv);
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header">
        <child type="title">
          <object class="GtkStackSwitcher" id="tabs">
            <property name="stack">stack</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkMenuButton" id="gears">
            <property name="direction">none</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkToggleButton" id="search">
            <property name="sensitive">False</property>
            <property name="icon-name">edit-find-symbolic</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkSearchBar" id="searchbar">
            <child>
              <object class="GtkSearchEntry" id="searchentry">
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkStack" id="stack">
            <property name="transition-duration">500</property>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-side-bar">
<title xml:lang="en">Adding a side bar</title>

<para xml:lang="en">
As another piece of functionality, we are adding a sidebar, which demonstrates
<classname>Gtk::Revealer</classname> and <classname>Gtk::ListBox</classname>.
The new widgets are added in the <filename>window.ui</filename> file.
</para>

<para xml:lang="en">
The code to populate the sidebar with buttons for the words found in each
file is a little too involved to go into here. But we'll look at the code
to add a checkbutton for the new feature to the menu. A menu item is added to
the ui file <filename>gears_menu.ui</filename>.
</para>

<para xml:lang="en">
To connect the menu item to the new <literal>show-words</literal> setting, we use a
<classname>Gio::Action</classname> corresponding to the given <classname>Gio::Settings</classname>
key. In <classname>ExampleAppWindow</classname>'s constructor:
</para>
<programlisting xml:lang="en"><code>// Connect the menu to the MenuButton m_gears, and bind the show-words setting
// to the win.show-words action and the "Words" menu item.
// (The connection between action and menu item is specified in gears_menu.ui.)
auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
auto menu = menu_builder-&gt;get_object&lt;Gio::MenuModel&gt;("menu");
m_gears-&gt;set_menu_model(menu);
add_action(m_settings-&gt;create_action("show-words"));
</code></programlisting>

<para xml:lang="en">
What our application looks like now:
</para>

<figure xml:id="figure-buildapp-side-bar">
  <title xml:lang="en">Adding a side bar</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_side_bar.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step7">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step4/exampleapplication.h"
// Equal to the corresponding file in step4
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.h"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

#define HAS_SEARCH_ENTRY2 GTKMM_CHECK_VERSION(4,13,2)

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  // Signal handlers
  void on_search_text_changed();
  void on_visible_child_changed();
  void on_find_word(const Gtk::Button* button);
  void on_reveal_child_changed();

  void update_words();

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::Settings> m_settings;
  Gtk::Stack* m_stack {nullptr};
  Gtk::ToggleButton* m_search {nullptr};
  Gtk::SearchBar* m_searchbar {nullptr};
#if HAS_SEARCH_ENTRY2
  Gtk::SearchEntry2* m_searchentry {nullptr};
#else
  Gtk::SearchEntry* m_searchentry {nullptr};
#endif
  Gtk::MenuButton* m_gears {nullptr};
  Gtk::Revealer* m_sidebar {nullptr};
  Gtk::ListBox* m_words {nullptr};
  Glib::RefPtr<Glib::Binding> m_prop_binding;
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleapplication.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>
#include <set>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  // Get widgets from the Gtk::Builder file.
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");

  m_search = m_refBuilder->get_widget<Gtk::ToggleButton>("search");
  if (!m_search)
    throw std::runtime_error("No \"search\" object in window.ui");

  m_searchbar = m_refBuilder->get_widget<Gtk::SearchBar>("searchbar");
  if (!m_searchbar)
    throw std::runtime_error("No \"searchbar\" object in window.ui");

#if HAS_SEARCH_ENTRY2
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry2>("searchentry");
#else
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry>("searchentry");
#endif
  if (!m_searchentry)
    throw std::runtime_error("No \"searchentry\" object in window.ui");

  m_gears = m_refBuilder->get_widget<Gtk::MenuButton>("gears");
  if (!m_gears)
    throw std::runtime_error("No \"gears\" object in window.ui");

  m_sidebar = m_refBuilder->get_widget<Gtk::Revealer>("sidebar");
  if (!m_sidebar)
    throw std::runtime_error("No \"sidebar\" object in window.ui");

  m_words = m_refBuilder->get_widget<Gtk::ListBox>("words");
  if (!m_words)
    throw std::runtime_error("No \"words\" object in window.ui");

  // Bind settings.
  m_settings = Gio::Settings::create("org.gtkmm.exampleapp");
  m_settings->bind("transition", m_stack->property_transition_type());
  m_settings->bind("show-words", m_sidebar->property_reveal_child());

  // Bind properties.
  m_prop_binding = Glib::Binding::bind_property(m_search->property_active(),
    m_searchbar->property_search_mode_enabled(), Glib::Binding::Flags::BIDIRECTIONAL);

  // Connect signal handlers.
  m_searchentry->signal_search_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_search_text_changed));
  m_stack->property_visible_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_visible_child_changed));
  m_sidebar->property_reveal_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_reveal_child_changed));

  // Connect the menu to the MenuButton m_gears, and bind the show-words setting
  // to the win.show-words action and the "Words" menu item.
  // (The connection between action and menu item is specified in gears_menu.ui.)
  auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
  auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
  if (!menu)
    throw std::runtime_error("No \"menu\" object in gears_menu.ui");

  m_gears->set_menu_model(menu);
  add_action(m_settings->create_action("show-words"));
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  auto buffer = view->get_buffer();
  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    buffer->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
    return;
  }

  auto tag = buffer->create_tag();
  m_settings->bind("font", tag->property_font());
  buffer->apply_tag(tag, buffer->begin(), buffer->end());

  m_search->set_sensitive(true);
  update_words();
}

void ExampleAppWindow::on_search_text_changed()
{
  const auto text = m_searchentry->get_text();
  if (text.empty())
    return;

  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible child." << std::endl;
    return;
  }

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible text view." << std::endl;
    return;
  }

  // Very simple-minded search implementation.
  auto buffer = view->get_buffer();
  Gtk::TextIter match_start;
  Gtk::TextIter match_end;
  if (buffer->begin().forward_search(text, Gtk::TextSearchFlags::CASE_INSENSITIVE,
      match_start, match_end))
  {
    buffer->select_range(match_start, match_end);
    view->scroll_to(match_start);
  }
}

void ExampleAppWindow::on_visible_child_changed()
{
  m_searchbar->set_search_mode(false);
  update_words();
}

void ExampleAppWindow::on_find_word(const Gtk::Button* button)
{
  m_searchentry->set_text(button->get_label());
}

void ExampleAppWindow::on_reveal_child_changed()
{
  update_words();
}

void ExampleAppWindow::update_words()
{
  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
    return;

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::update_words(): No visible text view." << std::endl;
    return;
  }
  auto buffer = view->get_buffer();

  // Find all words in the text buffer.
  std::set<Glib::ustring> words;
  auto start = buffer->begin();
  Gtk::TextIter end;
  while (start)
  {
    while (start && !start.starts_word())
      ++start;

    if (!start)
      break;

    end = start;
    end.forward_word_end();
    if (start == end)
      break;

    auto word = buffer->get_text(start, end, false);
    words.insert(word.lowercase());
    start = end;
  }

  // Remove old children from the ListBox.
  while (auto child = m_words->get_first_child())
    m_words->remove(*child);

  // Add new child buttons, one per unique word.
  for (const auto& word : words)
  {
    auto row = Gtk::make_managed<Gtk::Button>(word);
    row->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
      &ExampleAppWindow::on_find_word), row));
    m_words->append(*row);
  }
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step6/main.cc"
// Equal to the corresponding file in step6
]]></code></programlisting>
<para xml:lang="en">File: <filename>gears_menu.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <menu id="menu">
    <section>
      <item>
        <attribute name="label" translatable="yes">_Words</attribute>
        <attribute name="action">win.show-words</attribute>
      </item>
      <item>
        <attribute name="label" translatable="yes">_Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
    <section>
      <item>
        <attribute name="label" translatable="yes">_Quit</attribute>
        <attribute name="action">app.quit</attribute>
      </item>
    </section>
  </menu>
</interface>
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header">
        <child type="title">
          <object class="GtkStackSwitcher" id="tabs">
            <property name="stack">stack</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkToggleButton" id="search">
            <property name="sensitive">False</property>
            <property name="icon-name">edit-find-symbolic</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkMenuButton" id="gears">
            <property name="direction">none</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkSearchBar" id="searchbar">
            <child>
              <object class="GtkSearchEntry" id="searchentry">
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkBox" id="hbox">
            <child>
              <object class="GtkRevealer" id="sidebar">
                <property name="transition-type">slide-right</property>
                <child>
                 <object class="GtkScrolledWindow" id="sidebar-sw">
                   <property name="hscrollbar-policy">never</property>
                   <child>
                     <object class="GtkListBox" id="words">
                       <property name="selection-mode">none</property>
                     </object>
                   </child>
                 </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkStack" id="stack">
                <property name="transition-duration">500</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<para xml:lang="en">File: <filename>org.gtkmm.exampleapp.gschema.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
  <schema path="/org/gtkmm/exampleapp/" id="org.gtkmm.exampleapp">
    <key name="font" type="s">
      <default>'Monospace 12'</default>
      <summary>Font</summary>
      <description>The font to be used for content.</description>
    </key>
    <key name="transition" type="s">
      <choices>
        <choice value='none'/>
        <choice value='crossfade'/>
        <choice value='slide-left-right'/>
      </choices>
      <default>'none'</default>
      <summary>Transition</summary>
      <description>The transition to use when switching tabs.</description>
    </key>
    <key name="show-words" type="b">
      <default>false</default>
      <summary>Show words</summary>
      <description>Whether to show a word list in the sidebar.</description>
    </key>
  </schema>
</schemalist>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-properties">
<title xml:lang="en">Properties</title>

<para xml:lang="en">
Widgets and other objects have many useful properties. Here we show some ways to use
them in new and flexible ways, by wrapping them in actions with <classname>Gio::PropertyAction</classname>
or by binding them with <classname>Glib::Binding</classname>.
</para>

<para xml:lang="en">
To set this up, we add two labels to the header bar in our <filename>window.ui</filename> file,
named <literal>lines_label</literal> and <literal>lines</literal>, and get pointers to them
in the application window's constructor, as we've seen a couple of times by now.
We add a new "Lines" menu item to the gears menu, which triggers the
<literal>show-lines</literal> action.
</para>

<para xml:lang="en">
To make this menu item do something, we create a property action for the <literal>visible</literal>
property of the <literal>lines</literal> label, and add it to the actions of the window.
The effect of this is that the visibility of the label gets toggled every time the action
is activated.
Since we want both labels to appear and disappear together, we bind the <literal>visible</literal>
property of the <literal>lines_label</literal> widget to the same property of the
<literal>lines</literal> widget.
In <classname>ExampleAppWindow</classname>'s constructor:
</para>
<programlisting xml:lang="en"><code>add_action(Gio::PropertyAction::create("show-lines", m_lines-&gt;property_visible()));
m_binding_lines_visible = Glib::Binding::bind_property(m_lines-&gt;property_visible(),
  m_lines_label-&gt;property_visible());

</code></programlisting>

<para xml:lang="en">
We also need a function that counts the lines of the currently active tab, and updates
the <literal>lines</literal> label. See the full source if you are interested in the details.
</para>

<para xml:lang="en">
This brings our example application to this appearance:
</para>

<figure xml:id="figure-buildapp-properties">
  <title xml:lang="en">Properties</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_properties.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step8">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step4/exampleapplication.h"
// Equal to the corresponding file in step4
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.h"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLEAPPWINDOW_H_
#define GTKMM_EXAMPLEAPPWINDOW_H_

#include <gtkmm.h>

#define HAS_SEARCH_ENTRY2 GTKMM_CHECK_VERSION(4,13,2)

class ExampleAppWindow : public Gtk::ApplicationWindow
{
public:
  ExampleAppWindow(BaseObjectType* cobject,
    const Glib::RefPtr<Gtk::Builder>& refBuilder);

  static ExampleAppWindow* create();

  void open_file_view(const Glib::RefPtr<Gio::File>& file);

protected:
  // Signal handlers
  void on_search_text_changed();
  void on_visible_child_changed();
  void on_find_word(const Gtk::Button* button);
  void on_reveal_child_changed();

  void update_words();
  void update_lines();

  Glib::RefPtr<Gtk::Builder> m_refBuilder;
  Glib::RefPtr<Gio::Settings> m_settings;
  Gtk::Stack* m_stack {nullptr};
  Gtk::ToggleButton* m_search {nullptr};
  Gtk::SearchBar* m_searchbar {nullptr};
#if HAS_SEARCH_ENTRY2
  Gtk::SearchEntry2* m_searchentry {nullptr};
#else
  Gtk::SearchEntry* m_searchentry {nullptr};
#endif
  Gtk::MenuButton* m_gears {nullptr};
  Gtk::Revealer* m_sidebar {nullptr};
  Gtk::ListBox* m_words {nullptr};
  Gtk::Label* m_lines {nullptr};
  Gtk::Label* m_lines_label {nullptr};
  Glib::RefPtr<Glib::Binding> m_binding_search_enabled;
  Glib::RefPtr<Glib::Binding> m_binding_lines_visible;
};

#endif /* GTKMM_EXAMPLEAPPWINDOW_H */
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleapplication.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>
#include <set>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  // Get widgets from the Gtk::Builder file.
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");

  m_search = m_refBuilder->get_widget<Gtk::ToggleButton>("search");
  if (!m_search)
    throw std::runtime_error("No \"search\" object in window.ui");

  m_searchbar = m_refBuilder->get_widget<Gtk::SearchBar>("searchbar");
  if (!m_searchbar)
    throw std::runtime_error("No \"searchbar\" object in window.ui");

#if HAS_SEARCH_ENTRY2
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry2>("searchentry");
#else
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry>("searchentry");
#endif
  if (!m_searchentry)
    throw std::runtime_error("No \"searchentry\" object in window.ui");

  m_gears = m_refBuilder->get_widget<Gtk::MenuButton>("gears");
  if (!m_gears)
    throw std::runtime_error("No \"gears\" object in window.ui");

  m_sidebar = m_refBuilder->get_widget<Gtk::Revealer>("sidebar");
  if (!m_sidebar)
    throw std::runtime_error("No \"sidebar\" object in window.ui");

  m_words = m_refBuilder->get_widget<Gtk::ListBox>("words");
  if (!m_words)
    throw std::runtime_error("No \"words\" object in window.ui");

  m_lines = m_refBuilder->get_widget<Gtk::Label>("lines");
  if (!m_lines)
    throw std::runtime_error("No \"lines\" object in window.ui");

  m_lines_label = m_refBuilder->get_widget<Gtk::Label>("lines_label");
  if (!m_lines_label)
    throw std::runtime_error("No \"lines_label\" object in window.ui");

  // Bind settings.
  m_settings = Gio::Settings::create("org.gtkmm.exampleapp");
  m_settings->bind("transition", m_stack->property_transition_type());
  m_settings->bind("show-words", m_sidebar->property_reveal_child());

  // Bind properties of the search button to the search bar.
  m_binding_search_enabled = Glib::Binding::bind_property(m_search->property_active(),
    m_searchbar->property_search_mode_enabled(), Glib::Binding::Flags::BIDIRECTIONAL);

  // Connect signal handlers.
  m_searchentry->signal_search_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_search_text_changed));
  m_stack->property_visible_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_visible_child_changed));
  m_sidebar->property_reveal_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_reveal_child_changed));

  // Connect the menu to the MenuButton m_gears, and bind the show-words setting
  // to the win.show-words action and the "Words" menu item.
  // (The connection between action and menu item is specified in gears_menu.ui.)
  auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
  auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
  if (!menu)
    throw std::runtime_error("No \"menu\" object in gears_menu.ui");

  m_gears->set_menu_model(menu);
  add_action(m_settings->create_action("show-words"));

  // Bind the "visible" property of m_lines to the win.show-lines action, to
  // the "Lines" menu item and to the "visible" property of m_lines_label.
  add_action(Gio::PropertyAction::create("show-lines", m_lines->property_visible()));
  m_binding_lines_visible = Glib::Binding::bind_property(m_lines->property_visible(),
    m_lines_label->property_visible());
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  auto buffer = view->get_buffer();
  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    buffer->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
    return;
  }

  auto tag = buffer->create_tag();
  m_settings->bind("font", tag->property_font());
  buffer->apply_tag(tag, buffer->begin(), buffer->end());

  m_search->set_sensitive(true);
  update_words();
  update_lines();
}

void ExampleAppWindow::on_search_text_changed()
{
  const auto text = m_searchentry->get_text();
  if (text.empty())
    return;

  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible child." << std::endl;
    return;
  }

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible text view." << std::endl;
    return;
  }

  // Very simple-minded search implementation.
  auto buffer = view->get_buffer();
  Gtk::TextIter match_start;
  Gtk::TextIter match_end;
  if (buffer->begin().forward_search(text, Gtk::TextSearchFlags::CASE_INSENSITIVE,
      match_start, match_end))
  {
    buffer->select_range(match_start, match_end);
    view->scroll_to(match_start);
  }
}

void ExampleAppWindow::on_visible_child_changed()
{
  m_searchbar->set_search_mode(false);
  update_words();
  update_lines();  
}

void ExampleAppWindow::on_find_word(const Gtk::Button* button)
{
  m_searchentry->set_text(button->get_label());
}

void ExampleAppWindow::on_reveal_child_changed()
{
  update_words();
}

void ExampleAppWindow::update_words()
{
  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
    return;

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::update_words(): No visible text view." << std::endl;
    return;
  }
  auto buffer = view->get_buffer();

  // Find all words in the text buffer.
  std::set<Glib::ustring> words;
  auto start = buffer->begin();
  Gtk::TextIter end;
  while (start)
  {
    while (start && !start.starts_word())
      ++start;

    if (!start)
      break;

    end = start;
    end.forward_word_end();
    if (start == end)
      break;

    auto word = buffer->get_text(start, end, false);
    words.insert(word.lowercase());
    start = end;
  }

  // Remove old children from the ListBox.
  while (auto child = m_words->get_first_child())
    m_words->remove(*child);

  // Add new child buttons, one per unique word.
  for (const auto& word : words)
  {
    auto row = Gtk::make_managed<Gtk::Button>(word);
    row->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
      &ExampleAppWindow::on_find_word), row));
    m_words->append(*row);
  }
}

void ExampleAppWindow::update_lines()
{
  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
    return;

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::update_lines(): No visible text view." << std::endl;
    return;
  }
  auto buffer = view->get_buffer();

  int count = 0;
  auto iter = buffer->begin();
  while (iter)
  {
    ++count;
    if (!iter.forward_line())
      break;
  }
  m_lines->set_text(Glib::ustring::format(count));
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step6/main.cc"
// Equal to the corresponding file in step6
]]></code></programlisting>
<para xml:lang="en">File: <filename>gears_menu.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <menu id="menu">
    <section>
      <item>
        <attribute name="label" translatable="yes">_Words</attribute>
        <attribute name="action">win.show-words</attribute>
      </item>
      <item>
        <attribute name="label" translatable="yes">_Lines</attribute>
        <attribute name="action">win.show-lines</attribute>
      </item>
      <item>
        <attribute name="label" translatable="yes">_Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
    <section>
      <item>
        <attribute name="label" translatable="yes">_Quit</attribute>
        <attribute name="action">app.quit</attribute>
      </item>
    </section>
  </menu>
</interface>
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header">
        <child>
          <object class="GtkLabel" id="lines_label">
            <property name="visible">False</property>
            <property name="label" translatable="yes">Lines:</property>
          </object>
        </child>
        <child>
          <object class="GtkLabel" id="lines">
            <property name="visible">False</property>
          </object>
        </child>
        <child type="title">
          <object class="GtkStackSwitcher" id="tabs">
            <property name="stack">stack</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkToggleButton" id="search">
            <property name="sensitive">False</property>
            <property name="icon-name">edit-find-symbolic</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkMenuButton" id="gears">
            <property name="direction">none</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkSearchBar" id="searchbar">
            <child>
              <object class="GtkSearchEntry" id="searchentry">
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkBox" id="hbox">
            <child>
              <object class="GtkRevealer" id="sidebar">
                <property name="transition-type">slide-right</property>
                <child>
                  <object class="GtkScrolledWindow" id="sidebar-sw">
                    <property name="hscrollbar-policy">never</property>
                    <child>
                      <object class="GtkListBox" id="words">
                        <property name="selection-mode">none</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkStack" id="stack">
                <property name="transition-duration">500</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

<section xml:id="sec-buildapp-header-bar">
<title xml:lang="en">Header bar</title>

<para xml:lang="en">
Our application already uses a <classname>Gtk::HeaderBar</classname> instead of
a 'normal' window titlebar. The header bar is a direct child of the window,
and its type is <literal>titlebar</literal>. This is set in the
<filename>window.ui</filename> file.
</para>

<para xml:lang="en">
Here we'll just make two small changes to the header bar. The <literal>decoration-layout</literal>
property is set in the <filename>window.ui</filename> file, to show only the close
button, and hide the minimize and maximize buttons. We also include an icon in the
resource file, and set up this icon as the window icon.
In <classname>ExampleAppWindow</classname>'s constructor:
</para>
<programlisting xml:lang="en"><code>Gtk::IconTheme::get_for_display(get_display())-&gt;add_resource_path("/org/gtkmm/exampleapp");
set_icon_name("exampleapp");

</code></programlisting>

<para xml:lang="en">
Here is how the application now looks:
</para>

<figure xml:id="figure-buildapp-header-bar">
  <title xml:lang="en">Header bar</title>
  <screenshot>
    <mediaobject><imageobject><imagedata format="PNG" fileref="figures/buildapp_header_bar.png"/></imageobject></mediaobject>
  </screenshot>
</figure>

<para xml:lang="en">
The <filename>window.ui</filename> file sets a header bar title, but this title is not shown.
That's because the stack switcher is a child of type <literal>title</literal>. The stack
switcher becomes a custom title that hides the title label.
</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/buildapp/step9">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>exampleapplication.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step4/exampleapplication.h"
// Equal to the corresponding file in step4
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.h"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step8/exampleappwindow.h"
// Equal to the corresponding file in step8
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapplication.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleapplication.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappprefs.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step5/exampleappprefs.cc"
// Equal to the corresponding file in step5
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleappwindow.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "exampleappwindow.h"
#include <iostream>
#include <stdexcept>
#include <set>

ExampleAppWindow::ExampleAppWindow(BaseObjectType* cobject,
  const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::ApplicationWindow(cobject),
  m_refBuilder(refBuilder)
{
  // Get widgets from the Gtk::Builder file.
  m_stack = m_refBuilder->get_widget<Gtk::Stack>("stack");
  if (!m_stack)
    throw std::runtime_error("No \"stack\" object in window.ui");

  m_search = m_refBuilder->get_widget<Gtk::ToggleButton>("search");
  if (!m_search)
    throw std::runtime_error("No \"search\" object in window.ui");

  m_searchbar = m_refBuilder->get_widget<Gtk::SearchBar>("searchbar");
  if (!m_searchbar)
    throw std::runtime_error("No \"searchbar\" object in window.ui");

#if HAS_SEARCH_ENTRY2
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry2>("searchentry");
#else
  m_searchentry = m_refBuilder->get_widget<Gtk::SearchEntry>("searchentry");
#endif
  if (!m_searchentry)
    throw std::runtime_error("No \"searchentry\" object in window.ui");

  m_gears = m_refBuilder->get_widget<Gtk::MenuButton>("gears");
  if (!m_gears)
    throw std::runtime_error("No \"gears\" object in window.ui");

  m_sidebar = m_refBuilder->get_widget<Gtk::Revealer>("sidebar");
  if (!m_sidebar)
    throw std::runtime_error("No \"sidebar\" object in window.ui");

  m_words = m_refBuilder->get_widget<Gtk::ListBox>("words");
  if (!m_words)
    throw std::runtime_error("No \"words\" object in window.ui");

  m_lines = m_refBuilder->get_widget<Gtk::Label>("lines");
  if (!m_lines)
    throw std::runtime_error("No \"lines\" object in window.ui");

  m_lines_label = m_refBuilder->get_widget<Gtk::Label>("lines_label");
  if (!m_lines_label)
    throw std::runtime_error("No \"lines_label\" object in window.ui");

  // Bind settings.
  m_settings = Gio::Settings::create("org.gtkmm.exampleapp");
  m_settings->bind("transition", m_stack->property_transition_type());
  m_settings->bind("show-words", m_sidebar->property_reveal_child());

  // Bind properties of the search button to the search bar.
  m_binding_search_enabled = Glib::Binding::bind_property(m_search->property_active(),
    m_searchbar->property_search_mode_enabled(), Glib::Binding::Flags::BIDIRECTIONAL);

  // Connect signal handlers.
  m_searchentry->signal_search_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_search_text_changed));
  m_stack->property_visible_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_visible_child_changed));
  m_sidebar->property_reveal_child().signal_changed().connect(
    sigc::mem_fun(*this, &ExampleAppWindow::on_reveal_child_changed));

  // Connect the menu to the MenuButton m_gears, and bind the show-words setting
  // to the win.show-words action and the "Words" menu item.
  // (The connection between action and menu item is specified in gears_menu.ui.)
  auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
  auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
  if (!menu)
    throw std::runtime_error("No \"menu\" object in gears_menu.ui");

  m_gears->set_menu_model(menu);
  add_action(m_settings->create_action("show-words"));

  // Bind the "visible" property of m_lines to the win.show-lines action, to
  // the "Lines" menu item and to the "visible" property of m_lines_label.
  add_action(Gio::PropertyAction::create("show-lines", m_lines->property_visible()));
  m_binding_lines_visible = Glib::Binding::bind_property(m_lines->property_visible(),
    m_lines_label->property_visible());

  // Set the window icon.
  Gtk::IconTheme::get_for_display(get_display())->add_resource_path("/org/gtkmm/exampleapp");
  set_icon_name("exampleapp");
}

//static
ExampleAppWindow* ExampleAppWindow::create()
{
  // Load the Builder file and instantiate its widgets.
  auto refBuilder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/window.ui");

  auto window = Gtk::Builder::get_widget_derived<ExampleAppWindow>(refBuilder, "app_window");
  if (!window)
    throw std::runtime_error("No \"app_window\" object in window.ui");

  return window;
}

void ExampleAppWindow::open_file_view(const Glib::RefPtr<Gio::File>& file)
{
  const Glib::ustring basename = file->get_basename();

  auto scrolled = Gtk::make_managed<Gtk::ScrolledWindow>();
  scrolled->set_expand(true);
  auto view = Gtk::make_managed<Gtk::TextView>();
  view->set_editable(false);
  view->set_cursor_visible(false);
  scrolled->set_child(*view);
  m_stack->add(*scrolled, basename, basename);

  auto buffer = view->get_buffer();
  try
  {
    char* contents = nullptr;
    gsize length = 0;
    
    file->load_contents(contents, length);
    buffer->set_text(contents, contents+length);
    g_free(contents);
  }
  catch (const Glib::Error& ex)
  {
    std::cout << "ExampleAppWindow::open_file_view(\"" << file->get_parse_name()
      << "\"):\n  " << ex.what() << std::endl;
    return;
  }

  auto tag = buffer->create_tag();
  m_settings->bind("font", tag->property_font());
  buffer->apply_tag(tag, buffer->begin(), buffer->end());

  m_search->set_sensitive(true);
  update_words();
  update_lines();
}

void ExampleAppWindow::on_search_text_changed()
{
  const auto text = m_searchentry->get_text();
  if (text.empty())
    return;

  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible child." << std::endl;
    return;
  }

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::on_search_text_changed(): No visible text view." << std::endl;
    return;
  }

  // Very simple-minded search implementation.
  auto buffer = view->get_buffer();
  Gtk::TextIter match_start;
  Gtk::TextIter match_end;
  if (buffer->begin().forward_search(text, Gtk::TextSearchFlags::CASE_INSENSITIVE,
      match_start, match_end))
  {
    buffer->select_range(match_start, match_end);
    view->scroll_to(match_start);
  }
}

void ExampleAppWindow::on_visible_child_changed()
{
  m_searchbar->set_search_mode(false);
  update_words();
  update_lines();  
}

void ExampleAppWindow::on_find_word(const Gtk::Button* button)
{
  m_searchentry->set_text(button->get_label());
}

void ExampleAppWindow::on_reveal_child_changed()
{
  update_words();
}

void ExampleAppWindow::update_words()
{
  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
    return;

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::update_words(): No visible text view." << std::endl;
    return;
  }
  auto buffer = view->get_buffer();

  // Find all words in the text buffer.
  std::set<Glib::ustring> words;
  auto start = buffer->begin();
  Gtk::TextIter end;
  while (start)
  {
    while (start && !start.starts_word())
      ++start;

    if (!start)
      break;

    end = start;
    end.forward_word_end();
    if (start == end)
      break;

    auto word = buffer->get_text(start, end, false);
    words.insert(word.lowercase());
    start = end;
  }

  // Remove old children from the ListBox.
  while (auto child = m_words->get_first_child())
    m_words->remove(*child);

  // Add new child buttons, one per unique word.
  for (const auto& word : words)
  {
    auto row = Gtk::make_managed<Gtk::Button>(word);
    row->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
      &ExampleAppWindow::on_find_word), row));
    m_words->append(*row);
  }
}

void ExampleAppWindow::update_lines()
{
  auto tab = dynamic_cast<Gtk::ScrolledWindow*>(m_stack->get_visible_child());
  if (!tab)
    return;

  auto view = dynamic_cast<Gtk::TextView*>(tab->get_child());
  if (!view)
  {
    std::cout << "ExampleAppWindow::update_lines(): No visible text view." << std::endl;
    return;
  }
  auto buffer = view->get_buffer();

  int count = 0;
  auto iter = buffer->begin();
  while (iter)
  {
    ++count;
    if (!iter.forward_line())
      break;
  }
  m_lines->set_text(Glib::ustring::format(count));
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "../step6/main.cc"
// Equal to the corresponding file in step6
]]></code></programlisting>
<para xml:lang="en">File: <filename>exampleapp.gresource.xml</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gtkmm/exampleapp">
    <file preprocess="xml-stripblanks">window.ui</file>
    <file preprocess="xml-stripblanks">gears_menu.ui</file>
    <file preprocess="xml-stripblanks">prefs.ui</file>
    <file>exampleapp.png</file>
  </gresource>
</gresources>
]]></code></programlisting>
<para xml:lang="en">File: <filename>window.ui</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <property name="hide-on-close">True</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header">
        <property name="decoration-layout">icon:close</property>
        <child>
          <object class="GtkLabel" id="lines_label">
            <property name="visible">False</property>
            <property name="label" translatable="yes">Lines:</property>
          </object>
        </child>
        <child>
          <object class="GtkLabel" id="lines">
            <property name="visible">False</property>
          </object>
        </child>
        <child type="title">
          <object class="GtkStackSwitcher" id="tabs">
            <property name="stack">stack</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkToggleButton" id="search">
            <property name="sensitive">False</property>
            <property name="icon-name">edit-find-symbolic</property>
          </object>
        </child>
        <child type="end">
          <object class="GtkMenuButton" id="gears">
            <property name="direction">none</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkBox" id="content_box">
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkSearchBar" id="searchbar">
            <child>
              <object class="GtkSearchEntry" id="searchentry">
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkBox" id="hbox">
            <child>
              <object class="GtkRevealer" id="sidebar">
                <property name="transition-type">slide-right</property>
                <child>
                  <object class="GtkScrolledWindow" id="sidebar-sw">
                    <property name="hscrollbar-policy">never</property>
                    <child>
                      <object class="GtkListBox" id="words">
                        <property name="selection-mode">none</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkStack" id="stack">
                <property name="transition-duration">500</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
]]></code></programlisting>
<!-- end inserted example code -->

</section>

</chapter>

<chapter xml:id="chapter-contributing">
<title>Přispívání</title>

<para>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.</para>
<para xml:lang="en">
Ideally, we would like you to <link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/merge_requests">
provide a merge request</link> to the <filename>docs/tutorial/C/index-in.docbook</filename> file.
This file is in the <literal>gtkmm-documentation</literal> module in GNOME git.
</para>

<para xml:lang="en">
If you do decide to contribute, please post your contribution as an issue or merge request
to <link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation">GitLab</link>.
You can also discuss your ideas on GNOME's <link xlink:href="https://discourse.gnome.org">Discourse</link>
instance, under the <link xlink:href="https://discourse.gnome.org/c/platform/language-bindings">
Platform/Language bindings</link> category with a <literal>cplusplus</literal> tag.
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.
</para>

</chapter>

<appendix xml:id="chapter-refptr">
<title>Chytrý ukazatel RefPtr</title>

<para xml:lang="en">
<classname>Glib::RefPtr</classname> is a smartpointer. Specifically, it is a
reference-counting smartpointer. You might be familiar with
<classname>std::unique_ptr&lt;&gt;</classname>
and <classname>std::shared_ptr&lt;&gt;</classname>, which are also smartpointers.
In <application>gtkmm</application>-4.0 <classname>Glib::RefPtr&lt;&gt;</classname> is an alias for
<classname>std::shared_ptr&lt;&gt;</classname>,
which is reference-counting. <classname>Glib::RefPtr&lt;&gt;</classname> was introduced
long before there was a reference-counting smartpointer in the C++ Standard Library.
</para>

<para xml:lang="en">
If you make your own <classname>Glib::ObjectBase</classname>-derived classes with
<methodname>create()</methodname> methods that return a <classname>Glib::RefPtr</classname>,
you must use <function>Glib::make_refptr_for_instance()</function> in your
<methodname>create()</methodname> methods. This function creates a <classname>std::shared_ptr</classname>
with a special deleter, which handles the reference-count for the wrapped C object.
</para>

<para xml:lang="en"><link xlink:href="https://gnome.pages.gitlab.gnome.org/glibmm/group__RefPtr.html">Reference</link></para>

<para>Chytré ukazatele fungují hodně podobně jako normální ukazatele.Zde je pár příkladů.</para>

<section xml:id="sec-refptr-copying">
<title>Kopírování</title>
<para><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.</para>
<programlisting xml:lang="en"><code>auto refPixbuf = Gdk::Pixbuf::create_from_file(filename);
auto refPixbuf2 = refPixbuf;
</code></programlisting>
<para>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>.</para>
<programlisting xml:lang="en"><code>std::list&lt;Glib::RefPtr&lt;Gdk::Pixbuf&gt;&gt; listPixbufs;
auto refPixbuf = Gdk::Pixbuf::create_from_file(filename);
listPixbufs.push_back(refPixbuf);
</code></programlisting>
</section>

<section xml:id="sec-refptr-dereferencing">
<title>Snižování referencí</title>
<para>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.</para>
<programlisting xml:lang="en"><code>auto refPixbuf = Gdk::Pixbuf::create_from_file(filename);
auto width = refPixbuf-&gt;get_width();
</code></programlisting>
<para xml:lang="en">You can also use the * operator and the <methodname>get()</methodname> method
to access the underlying instance, but it's usually a bad idea to do so. Unless
you are careful, you can end up with a pointer or a reference which is not included
in the reference count.
</para>
<programlisting xml:lang="en"><code>auto refPixbuf = Gdk::Pixbuf::create_from_file(filename);
auto&amp; underlying = *refPixbuf; // Possible, but not recommended
</code></programlisting>
</section>

<section xml:id="sec-refptr-casting">
<title>Přetypování</title>
<para><classname>RefPtr</classname> můžete přetypovat na základní typy, stejně jako normální ukazatele.</para>
<programlisting xml:lang="en"><code>auto refStore = Gtk::TreeStore::create(columns);
Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = refStore;
</code></programlisting>
<para xml:lang="en">This means that any method which takes a <type>const
Glib::RefPtr&lt;BaseType&gt;&amp;</type> argument can also take a
<type>const Glib::RefPtr&lt;DerivedType&gt;&amp;</type>. The cast is
implicit, just as it would be for a normal pointer.</para>
<para>Můžete také přetypovat na zděděné typy, ale syntax je trochu rozdílná, než s normálním ukazatelem.</para>
<programlisting xml:lang="en"><code>auto refStore = std::dynamic_pointer_cast&lt;Gtk::TreeStore&gt;(refModel);
auto refStore2 = std::static_pointer_cast&lt;Gtk::TreeStore&gt;(refModel);
</code></programlisting>
</section>

<section xml:id="sec-refptr-checking-for-null">
<title xml:lang="en">Checking for nullptr</title>
<para>Stejně jako u normálních ukazatelů můžete kontrolovat, jestli <classname>RefPtr</classname> neukazuje na nic.</para>
<programlisting xml:lang="en"><code>auto refModel = m_TreeView.get_model();
if (refModel)
{
  auto cols_count = refModel-&gt;get_n_columns();
  ...
}
</code></programlisting>
<para xml:lang="en">
But unlike normal pointers, <classname>RefPtr</classname>s are automatically
initialized to <literal>nullptr</literal> so you don't need to remember to do that yourself.
</para>
</section>

<section xml:id="sec-refptr-constness">
<title>Bezkonstantnost</title>
<para xml:lang="en">
The use of the <literal>const</literal> keyword in C++ is not always clear. You
might not realize 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.
</para>
<para>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>.</para>
<para><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í.</para>
</section>

</appendix>

<appendix xml:id="chapter-signals">
<title>Signály</title>

<section xml:id="sec-connecting-signal-handlers">
<title>Napojení obsluhy signálu</title>

<para xml:lang="en">
<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.
</para>

<para>Zde je příklad napojení obsluhy signálu na signál:</para>

<programlisting xml:lang="en"><code><![CDATA[
#include <gtkmm/button.h>

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

class some_class
{
public:
  some_class
  {
    button.signal_clicked().connect(sigc::ptr_fun(&on_button_clicked));
  }
private:
  Gtk::Button button {"Hello World"};
};
]]></code></programlisting>

<para>V tomto (nefunkčním) kódu je toho hodně k zamyšlení. Nejdříve pojďme pojmenovat zúčastněné věci:</para>

<itemizedlist>
<listitem>

<para>Obsluha signálu je <methodname>on_button_clicked()</methodname>.</para>
</listitem>
<listitem>

<para>Zaháčkovali jsme ji k objektu <classname>Gtk::Button</classname> nazvanému <varname>button</varname>.</para>
</listitem>
<listitem>

<para>Když <classname>Button</classname> vyšle svůj signál <literal>clicked</literal>, zavolá se <methodname>on_button_clicked()</methodname>.</para>
</listitem>

</itemizedlist>

<para>Nyní se pojďme znovu podívat na přípojení:</para>

<programlisting xml:lang="en"><code>    ...
    button.signal_clicked().connect(sigc::ptr_fun(&amp;on_button_clicked));
    ...
</code></programlisting>

<para>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.</para>

<para><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.</para>

<para xml:lang="en">
A C++ lambda expression is a functor which can be implicitly converted to a
<classname>sigc::slot</classname> in the call to <methodname>connect()</methodname>.
A lambda expression can be used instead of <function>sigc::ptr_fun()</function>.
It's also possible to use a lambda expression instead of <function>sigc::mem_fun()</function>,
but then you won't get automatic disconnection of the signal handler when a
<classname>sigc::trackable</classname>-derived object goes out of scope.
</para>

<para>Zde je trochu rozsáhlejší příklad slotů v činnosti:</para>

<programlisting xml:lang="en"><code><![CDATA[
#include <gtkmm/button.h>

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

class some_class
{
public:
  some_class
  {
    button.signal_clicked().connect(sigc::ptr_fun(&on_button_clicked));
    button.signal_clicked().connect(sigc::mem_fun(*this, &some_class::on_button_clicked));
  }
  void on_button_clicked();
private:
  Gtk::Button button {"Hello World"};
};
]]></code></programlisting>

<para>První volání <methodname>connect()</methodname> je stejné, jak jsme již viděli minule, nic nového.</para>
<para xml:lang="en">The next is more interesting.
<function>sigc::mem_fun()</function> is called with two arguments. The first
argument is <parameter>*this</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.
</para>

<para>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.</para>

<para>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í.</para>
</section>

<section xml:id="sec-writing-signal-handlers">
<title>Psaní obsluhy signálů</title>

<para>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>:</para>

<programlisting xml:lang="en"><code>Glib::SignalProxy&lt;bool(Gtk::DirectionType)&gt; signal_focus()
</code></programlisting>

<para xml:lang="en">
Other than the signal's name (<literal>focus</literal>), the template arguments are
important to note here. The first argument, <type>bool</type>, is the type that
the signal handler should return; and the type within parentheses,
<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.
</para>

<para>Stejné 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>):</para>

<programlisting xml:lang="en"><code>Glib::SignalProxy&lt;void(TextBuffer::iterator&amp;, const Glib::ustrin&amp;, int)&gt; signal_insert();
</code></programlisting>

<para xml:lang="en">
It follows the same form. The first type 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:
</para>

<programlisting xml:lang="en"><code>void on_insert(TextBuffer::iterator&amp; pos, const Glib::ustring&amp; text, int bytes)
</code></programlisting>
</section>

<section xml:id="sec-disconnecting-signal-handlers">
<title>Odpojení obsluhy signálu</title>

<para>Podívejme se ještě jednou na metodu <literal>connect()</literal> signálu:</para>

<programlisting xml:lang="en"><code>sigc::connection signal&lt;void(int)&gt;::connect(const sigc::slot&lt;void(int)&gt;&amp;);
</code></programlisting>

<para xml:lang="en">
The returned <classname>sigc::connection</classname> can be used to control the
connection. By keeping a connection object you can disconnect its associated signal
handler using the <methodname>sigc::connection::disconnect()</methodname> method.
</para>

</section>
<section xml:id="sec-overriding-default-signal-handlers">
<title>Přepisování výchozí obsluhy signálu</title>

<para>Doposud 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ý.</para>

<para>Namí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.</para>

<para>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ů.</para>

<para>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í.</para>

<para>Pojďme se podívat na příklad s přepsáním:</para>

<programlisting xml:lang="en"><code>#include &lt;gtkmm/button.h&gt;

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

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();
}
</code></programlisting>

<para>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.</para>

<para xml:lang="en">
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 connected signal handlers, 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.
</para>

</section>

<section xml:id="sec-binding-extra-arguments">
<title>Navázání dodatečných argumentů</title>

<para xml:lang="en">
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.
</para>
<programlisting xml:lang="en"><code>m_button1.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &amp;HelloWorld::on_button_clicked), "button 1"));
</code></programlisting>
<para xml:lang="en">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:
</para>
<programlisting xml:lang="en"><code>void on_button_clicked(const Glib::ustring&amp; data);
</code></programlisting>
<para xml:lang="en">Of course, a normal "clicked" signal handler would have no arguments.
</para>
<para xml:lang="en">
<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>.
</para>
</section>

<section xml:id="sec-eventsignals">
<title xml:lang="en">Event signals</title>

<para xml:lang="en">
Event signals are emitted as a result of some user input, for instance a key press
or a mouse motion. Usually you don't handle these events directly. Instead, you use
a subclass of <classname>Gtk::EventController</classname>, such as <classname>Gtk::EventControllerKey</classname>
or <classname>Gtk::GestureClick</classname>. Event controllers can be added to a
widget with <methodname>Gtk::Widget::add_controller()</methodname>.
</para>
<para xml:lang="en">
You might occasionally find it useful to handle 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
<methodname>Gtk::GestureClick::signal_pressed()</methodname> if you needed this
information. <methodname>Gtk::EventControllerKey::signal_key_pressed()</methodname>
is often used to handle key-presses.
</para>

<para xml:lang="en">
Some event controller 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.
</para>

<para xml:lang="en">
Handling an event doesn't affect the Widget's other signals. If you handle
<methodname>Gtk::GestureClick::signal_pressed()</methodname> 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.
</para>

<para xml:lang="en">
Here's a simple example:</para>
<programlisting xml:lang="en"><code>void on_button_press(int n_press, double x, double y);
Gtk::Button button("label");
auto controller = Gtk::GestureClick::create();
controller-&gt;set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
controller-&gt;signal_pressed().connect(sigc::ptr_fun(&amp;on_button_press));
button.add_controller(controller);
</code></programlisting>
<para>Když je ukazatel myši nad tlačítkem a zmáčknete tlačítko myši, je zavoláno <methodname>on_button_press()</methodname>.</para>
<para xml:lang="en">
The call to <methodname>set_propagation_phase()</methodname> is necessary in
this case because the <classname>GtkButton</classname> C class adds an event
controller, handling button clicks in the capture phase. <classname>GtkButton</classname>
claims the event, meaning that the event is not propagated in the bubble phase,
where event controllers handle events by default.
</para>

<section xml:id="signal-handler-sequence">
<title>Posloupnost obsluhy signálu</title>

<para xml:lang="en">By default, signal handlers that return <type>void</type> are called after
any previously-connected signal handlers. However, this can be a problem with
event signals that can stop event propagation by returning <literal>true</literal>.
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,
you can specify <literal>false</literal> for the <literal>after</literal> parameter.
This <methodname>connect()</methodname> parameter is optional, if the signal handler
returns <type>void</type>. For instance,
</para>
<programlisting xml:lang="en"><code>key_controller-&gt;signal_key_pressed().connect(sigc::ptr_fun(&amp;on_mywindow_key_pressed), false);
</code></programlisting>
<para xml:lang="en">The event is propagated between widgets in 3 phases.
<orderedlist inheritnum="ignore" continuation="restarts">
<listitem><simpara xml:lang="en">Capture phase - runs from the toplevel down to the event widget.</simpara></listitem>
<listitem><simpara xml:lang="en">Target phase - runs only on the event widget.</simpara></listitem>
<listitem><simpara xml:lang="en">Bubble phase - runs from the event widget up to the toplevel.</simpara></listitem>
</orderedlist>
</para>
<para xml:lang="en">
The <link xlink:href="https://docs.gtk.org/gtk4/input-handling.html">Input Handling</link>
chapter in the GTK documentation describes user input handling in more detail.
</para>
</section>

</section>

<section xml:id="sec-exceptions-in-signal-handlers">
<title>Výjimky v obsluze signálu</title>

<para>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.</para>
<para xml:lang="en">
This section describes primarily what you can expect on a Linux system, when you
use <link xlink:href="http://www.gnu.org/software/gdb/">the gdb debugger</link>.
</para>
<para xml:lang="en">
First, let's look at a simple example where an exception is thrown from a normal
function (no signal handler).
</para>
<programlisting xml:lang="en"><code>// without_signal.cc
#include &lt;gtkmm.h&gt;

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

int main(int argc, char** argv)
{
  throwSomething();
  auto app = Gtk::Application::create("org.gtkmm.without_signal");
  return app-&gt;run();
}
</code></programlisting>
<para xml:lang="en">
Here is an excerpt from a <application>gdb</application> session. Only the most
interesting parts of the output are shown.
</para>
<programlisting xml:lang="en"><code>&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
</code></programlisting>
<para xml:lang="en">You can see that the exception was thrown from <filename>without_signal.cc</filename>,
line 6 (<code>throw "Something";</code>).
</para>
<para xml:lang="en">
Now let's see what happens when an exception is thrown from a signal handler.
Here's the source code.
</para>
<programlisting xml:lang="en"><code>// 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);
  auto app = Gtk::Application::create("org.gtkmm.with_signal");
  app-&gt;hold();
  return app-&gt;run();
}
</code></programlisting>
<para xml:lang="en">
And here's an excerpt from a <application>gdb</application> session.
</para>
<programlisting xml:lang="en"><code>&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
</code></programlisting>
<para xml:lang="en">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 behavior, 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.
</para>
<para xml:lang="en">
To see where the exception is thrown, you can use the <application>gdb</application>
command <userinput>catch throw</userinput>.
</para>
<programlisting xml:lang="en"><code>&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.
</code></programlisting>
<para xml:lang="en">
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.
</para>
<programlisting xml:lang="en"><code>(gdb) catch throw
(gdb) commands
(gdb)   backtrace
(gdb)   continue
(gdb)   end
(gdb) set pagination off
(gdb) run
</code></programlisting>
<para xml:lang="en">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.
</para>
</section>

</appendix>

<appendix xml:id="chapter-custom-signals">
<title>Vytváření vlastních signálů</title>

<para>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>.</para>
<para xml:lang="en">
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.
</para>
<para xml:lang="en">
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:
</para>
<programlisting xml:lang="en"><code>sigc::signal&lt;void(bool, int)&gt; signal_something;
</code></programlisting>
<para xml:lang="en">
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:
</para>
<programlisting xml:lang="en"><code>class Server
{
public:
  //signal accessor:
  using type_signal_something = sigc::signal&lt;void(bool, int)&gt;;
  type_signal_something signal_something();

protected:
  type_signal_something m_signal_something;
};

Server::type_signal_something Server::signal_something()
{
  return m_signal_something;
}
</code></programlisting>

<para xml:lang="en">
You can then connect to the signal using the same syntax used when
connecting to <application>gtkmm</application> signals. For instance,
</para>
<programlisting xml:lang="en"><code>server.signal_something().connect(
  sigc::mem_fun(client, &amp;Client::on_server_something) );
</code></programlisting>

<section xml:id="chapter-custom-signals-example">
<title>Příklad</title>

<para>Jedná se o úplný funkční příklad, který definuje a používá vlastní signály.</para>

<para xml:lang="en"><link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/signals/custom/">Source Code</link></para>
<!-- start inserted example code -->
<para xml:lang="en">File: <filename>client.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_CLIENT_H
#define GTKMM_EXAMPLE_CLIENT_H

#include <sigc++/sigc++.h>

//Client must inherit from sigc::trackable.
//because libsigc++ needs to keep track of the lifetime of signal handlers.
class Client : public sigc::trackable
{
public:
  Client();
  virtual ~Client();

  //Signal handler:
  void on_server_something(bool a, int b);
};

#endif //GTKMM_EXAMPLE_CLIENT_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>server.h</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#ifndef GTKMM_EXAMPLE_SERVER_H
#define GTKMM_EXAMPLE_SERVER_H

#include <sigc++/sigc++.h>

class Server
{
public:
  Server();
  virtual ~Server();

  void do_something();

  //signal accessor:
  using type_signal_something = sigc::signal<void(bool, int)>;
  type_signal_something signal_something();

protected:
  type_signal_something m_signal_something;
};

#endif //GTKMM_EXAMPLE_SERVER_H
]]></code></programlisting>
<para xml:lang="en">File: <filename>client.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "client.h"
#include <iostream>

Client::Client()
{
}

Client::~Client()
{
}

void Client::on_server_something(bool a, int b)
{
  std::cout << "Client::on_server_something() called with these parameters: "
      << a << ", " << b << std::endl;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>main.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "server.h"
#include "client.h"
#include <iostream>

int main(int, char**)
{
  Server server;
  Client client;

  //Connect a Server signal to the signal handler in Client.
  server.signal_something().connect(sigc::mem_fun(client,
              &Client::on_server_something) );

  std::cout << "Before Server::do_something()" << std::endl;

  //Tell the server to do something that will eventually cause it to emit the
  //"something" signal.
  server.do_something();    // Client::on_server_something() will run before
                            // Server::do_something() has completed.

  std::cout << "After Server::do_something()" << std::endl;

  return 0;
}
]]></code></programlisting>
<para xml:lang="en">File: <filename>server.cc</filename> (For use with gtkmm 4)</para>
<programlisting xml:lang="en"><code><![CDATA[#include "server.h"
#include <iostream>

Server::Server()
{
}

Server::~Server()
{
}

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

void Server::do_something()
{
  m_signal_something.emit(false, 5);
}

]]></code></programlisting>
<!-- end inserted example code -->

</section>

</appendix>


<appendix xml:id="sec-signals-comparison">
<title>Srovnání s jinými signalizačními systémy</title>

<para xml:lang="en">
<!-- TODO: Rewrite this paragraph and talk about Qt's moc. -->
(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.)
</para>
<para xml:lang="en">
<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.</para>
<para xml:lang="en">
Re. 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.
</para>
<para xml:lang="en">
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.
</para>
</appendix>

<appendix xml:id="sec-windows-installation">
<title><application>gtkmm</application> a Win32</title>
    <para>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.</para>
    <para xml:lang="en">
      <application>gtkmm</application> currently works with the
      <link xlink:href="http://mingw.org/">MinGW/GCC compiler</link> with a compiler version
      that supports C++17, such as gcc 7 or 8. It also works with Microsoft
      Visual C++ 2017 15.7.x or later (including the freely available express/community
      editions) on the Windows platform. There is an
      <link xlink:href="ftp://ftp.gnome.org/pub/GNOME/binaries/win32/gtkmm">installer</link>
      available for <application>gtkmm</application> on Microsoft Windows, but as of this writing
      (October 2020) it has not been updated for a long time.
      Please be aware that although normally it is fine to mix builds done with
      Visual Studio 2017 and 2019, please do not do so when building
      <application>gtkmm</application> with its -mm dependencies.
    </para>
    <para xml:lang="en">Refer to the <link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm/tree/master/README.win32">README.win32</link>,
    as well as the <link xlink:href="https://gitlab.gnome.org/GNOME/gtkmm/tree/master/MSVC_NMake/README">README</link>
    files in the <application>gtkmm</application>, pangomm and glibmm for instructions on how to build <application>gtkmm</application> on Windows.
    </para>
</appendix>

<appendix xml:id="chapter-working-with-source">
<title>Práce se zdrojovým kódem gtkmm</title>
  <para>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.</para>
  <para xml:lang="en">
    The easiest way to do this is using <link xlink:href="https://wiki.gnome.org/Projects/Jhbuild">jhbuild</link>.
    <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 <link xlink:href="https://gnome.pages.gitlab.gnome.org/jhbuild/">jhbuild manual</link>.
  </para>
  <note>
    <para>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é.</para>
  </note>
  <para xml:lang="en">
    <application>gnome-build-meta</application> is an alternative to
    <application>jhbuild</application>. It is described at the
    <link xlink:href="https://wiki.gnome.org/Newcomers/BuildSystemComponent">Building system components</link>
    wiki page, but here we concentrate on <application>jhbuild</application>.
  </para>
  <section xml:id="sec-setting-up-jhbuild">
  <title>Nastavení systému jhbuild</title>

    <para xml:lang="en">
      To set up <application>jhbuild</application>, follow the basic
      installation instructions from the <link xlink:href="https://gnome.pages.gitlab.gnome.org/jhbuild/">jhbuild manual</link>.
      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 xml:lang="en">$ cp examples/sample.jhbuildrc ~/.config/jhbuildrc</screen>
    </para>
    <para xml:lang="en">
      The <application>gtkmm</application> module is defined in the
      <filename>gnome-suites-core-deps-latest.modules</filename> moduleset. So edit your
      <filename>jhbuildrc</filename> file and set your moduleset setting like so:
    </para>
    <programlisting xml:lang="en"><code>moduleset = 'gnome-suites-core-deps-latest'</code></programlisting>
    <para xml:lang="en">
      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:
    </para>
    <programlisting xml:lang="en"><code>modules = [ 'gtkmm' ]</code></programlisting>
    <para>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>).</para>
    <important>
      <title>Nastavení prefixu</title>
      <para xml:lang="en">
        By default, <application>jhbuild</application>'s configuration is
        configured to install all software built with
        <application>jhbuild</application> under the
        <filename>~/jhbuild/install</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>.
      </para>
    </important>
    <para xml:lang="en">
      You should also set <varname>buildroot</varname> in <filename>jhbuildrc</filename>.
      <application>jhbuild</application> builds <application>gtkmm</application> and many of its dependencies
      with Meson. Meson does not allow building in the source tree.
      <application>jhbuild</application>'s default action is to build in a
      <filename>build</filename> directory directly below the source root directory.
      Some modules have a <filename>build</filename> directory with files
      used when building with Autotools. Those files can be destroyed if you
      let <application>jhbuild</application> build in that directory.
    </para>
    <para xml:lang="en">
      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>.
    </para>
  </section>
  <section xml:id="sec-installing-jhbuild">
  <title>Instalace a používání vývojové verze <application>gtkmm</application> z repozitáře git</title>

    <para xml:lang="en">
      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 xml:lang="en">$ jhbuild bootstrap
$ jhbuild sanitycheck</screen>
    </para>
    <section xml:id="jhbuild-installing-gtkmm">
    <title>Instalace <application>gtkmm</application> pomocí programu <application>jhbuild</application></title>

      <para>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>).</para>
      <para>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>.</para>
    </section>
    <section xml:id="jhbuild-using-gtkmm">
    <title>Používání vývojové verze <application>gtkmm</application> z repozitáře git</title>

      <para xml:lang="en">
        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> or <filename>meson.build</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.
      </para>
      <para>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í.</para>

    </section>
  </section>
</appendix>

<appendix xml:id="chapter-wrapping-c-libraries">
<title>Obalení knihoven C pomocí gmmproc</title>

<para><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.</para>
<para>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.</para>

<section xml:id="sec-wrapping-build-structure">
<title>Struktura sestavení</title>

<para xml:lang="en">Generation 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>, which are included in
    <application>glibmm</application>. 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 <application>mm-common</application>
    module. To get started, it helps a lot to pick an existing binding module as an example
    to look at.</para>
<para>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>.</para>

<section xml:id="copying-skeleton-project">
<title>Kopírování kostry projektu</title>

<para xml:lang="en">Typically our wrapper library would be called libsomethingmm. We can start by
  copying the <link xlink:href="https://gitlab.gnome.org/GNOME/mm-common/tree/master/skeletonmm">
  skeleton source tree</link> from the <application>mm-common</application> module.
  Starting with <application>mm-common</application> 1.0.0 this skeleton application
  is built with the <link xlink:href="https://mesonbuild.com/">Meson build system</link>.
</para>
<programlisting xml:lang="en"><code>  $ git clone https://gitlab.gnome.org/GNOME/mm-common.git
  $ cp -a mm-common/skeletonmm libsomethingmm
</code></programlisting>
<para xml:lang="en">This provides a directory structure for the source .hg and .ccg files and the hand-written
  .h and .cc files, with <filename>meson.build</filename> files that can specify the
  various files in use, in terms of Meson variables. The directory structure usually
  looks like this, after we have renamed the directories appropriately:
<itemizedlist>
    <listitem><para xml:lang="en"><filename>libsomethingmm</filename>: The top-level directory.</para>
     <itemizedlist>
         <listitem><para xml:lang="en"><filename>libsomething</filename>: Contains the main include file and the pkg-config .pc file.</para>
         <itemizedlist>
             <listitem><para xml:lang="en"><filename>src</filename>: Contains .hg and .ccg source files.</para></listitem>
             <listitem><para xml:lang="en"><filename>libsomethingmm</filename>: Contains hand-written .h and .cc files.</para>
           </listitem>
         </itemizedlist>
       </listitem>
    </itemizedlist>
  </listitem>
</itemizedlist>
</para>

<para xml:lang="en">As well as renaming the directories, we should rename some of the source
    files. For instance:</para>
<programlisting xml:lang="en"><code>$ for f in $(find libsomethingmm -depth -name '*skeleton*'); do \
    d="${f%/*}"; b="${f##*/}"; mv "$f" "$d/${b//skeleton/libsomething}"; \
  done
</code></programlisting>
<para xml:lang="en">A number of the skeleton files must still be filled in with project-specific content later.
</para>
<para>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.</para>
<para xml:lang="en">Generated files are saved in the build tree, which is separated from the
    source tree when <command>meson</command> and <command>ninja</command> are used.</para>
</section>

<section xml:id="modifying-build-files">
<title>Úprava souborů řídících sestavení</title>

<para xml:lang="en">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 Meson files.</para>
<para>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“.</para>
<para>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>.</para>

<section xml:id="modifying-top-meson.build">
<title xml:lang="en">meson.build in the top-level directory</title>

<para>
  <itemizedlist>
    <listitem><para>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í.</para></listitem>
    <listitem><para xml:lang="en">In the <function>project()</function> function, change the
    license and the C++ version, if necessary.</para></listitem>
    <listitem><para xml:lang="en">You probably need to add more required modules than
    <application>glibmm</application> and <application>skeleton</application>
    (<application>libsomething</application>).</para></listitem>
  </itemizedlist>
</para>
</section>

<section xml:id="modifying-other-meson.build">
<title xml:lang="en">Other meson.build files</title>

<para xml:lang="en">Next we must adapt the other <filename>meson.build</filename> files:
  <itemizedlist>
    <listitem><para xml:lang="en"><filename>skeleton/meson.build</filename>: Perhaps not much
    to change here more than the global name substitutions.</para>
    </listitem>
    <listitem><para xml:lang="en"><filename>skeleton/skeletonmm/meson.build</filename></para>
      <variablelist>
        <varlistentry>
          <term xml:lang="en"><varname>defs_basefiles</varname></term>
          <listitem><para xml:lang="en">If we have more .defs and docs.xml files,
          we add them here.</para></listitem>
        </varlistentry>
        <varlistentry>
          <term xml:lang="en"><varname>hg_ccg_basenames</varname></term>
          <listitem><para xml:lang="en">We must mention all of our <filename>.hg</filename> and
          <filename>.ccg</filename> files here.</para></listitem>
        </varlistentry>
        <varlistentry>
          <term xml:lang="en"><varname>extra_cc_files, extra_h_files</varname></term>
          <listitem><para xml:lang="en">Any additional hand-written <filename>.h</filename> and
          <filename>.cc</filename> source files go here.</para></listitem>
        </varlistentry>
      </variablelist>
    </listitem>
  </itemizedlist>
</para>
</section>

<section xml:id="creating-hg-ccg">
<title>Vytváření souborů .hg a .ccg</title>

<para>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ů.</para>
<para>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.</para>
</section>
</section>
</section>

<section xml:id="sec-wrapping-defs-files">
<title>Generování souborů .defs</title>

<para xml:lang="en">The <filename>.defs</filename> files are text files, in a lisp format, that describe the API
  of a C library, including its
<itemizedlist>
  <listitem><para xml:lang="en">objects (GObjects, widgets, interfaces, boxed-types and plain structs)</para></listitem>
  <listitem><para xml:lang="en">functions</para></listitem>
  <listitem><para xml:lang="en">enums</para></listitem>
  <listitem><para xml:lang="en">signals</para></listitem>
  <listitem><para xml:lang="en">properties</para></listitem>
  <listitem><para xml:lang="en">vfuncs</para></listitem>
</itemizedlist>
</para>
<para xml:lang="en">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:
    <variablelist>
        <varlistentry>
            <term xml:lang="en"><filename>gtk.defs</filename></term>
            <listitem><para xml:lang="en">Includes the other files.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term xml:lang="en"><filename>gtk_methods.defs</filename></term>
            <listitem><para xml:lang="en">Objects and functions.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term xml:lang="en"><filename>gtk_enums.defs</filename></term>
            <listitem><para xml:lang="en">Enumerations.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term xml:lang="en"><filename>gtk_signals.defs</filename></term>
            <listitem><para xml:lang="en">Signals and properties.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term xml:lang="en"><filename>gtk_vfuncs.defs</filename></term>
            <listitem><para xml:lang="en">vfuncs (function pointer member fields in structs), written by hand.</para></listitem>
        </varlistentry>
    </variablelist>
</para>
<para xml:lang="en">The <filename>skeletonmm/tools/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.
</para>

<section xml:id="generating-defs-methods">
<title>Generování .defs  pro metody</title>

<para xml:lang="en">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,
</para>
<programlisting xml:lang="en"><code>$ ./h2def.py /usr/include/gtk-4.0/gtk/*.h &gt; gtk_methods.defs
</code></programlisting>
</section>

<section xml:id="generating-defs-enums">
<title>Generování .defs  pro výčty</title>

<para xml:lang="en">This <filename>.defs</filename> file describes enum types and their possible
  values. It is generated by the <filename>enumextract.py</filename> script which you can
  also find in glibmm's <filename>tools/defs_gen</filename> directory. For instance,
</para>
<programlisting xml:lang="en"><code>$ ./enumextract.py /usr/include/gtk-4.0/gtk/*.h &gt; gtk_enums.defs
</code></programlisting>
</section>

<section xml:id="generating-defs-signals-properties">
<title>Generování .defs  pro signály a vlastnosti</title>

<para xml:lang="en">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
</para>
<programlisting xml:lang="en"><code>$ cd tools/extra_defs_gen
$ ./generate_extra_defs &gt; gtk_signals.defs
</code></programlisting>
<para xml:lang="en">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>tools/extra_defs_gen/generate_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>tools/extra_defs_gen/meson.build</filename>
  file should also mention the new source filename.</para>
<para xml:lang="en">Then edit the <filename>.cc</filename> file to specify the correct types.
  For instance, your <function>main()</function> function might look like this:
</para>
<programlisting xml:lang="en"><code>#include &lt;glibmm_generate_extra_defs/generate_extra_defs.h&gt;
#include &lt;libsomething.h&gt;
#include &lt;iostream&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;
}
</code></programlisting>
</section>

<section xml:id="writing-defs-vfuncs">
<title>Psaní .defs pro virtuální funkce</title>

<para>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>.</para>
</section>

</section>

<section xml:id="sec-wrapping-hg-files">
<title>Soubory .hg a .ccg</title>
    <para>Zdrojové 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>.</para>
    <para xml:lang="en">A .hg file will typically include some headers
        and then declare a class, using some macros to add API or behavior to
        this class. For instance, <application>gtkmm</application>'s <filename>button.hg</filename> looks
        roughly like this:</para>

<programlisting xml:lang="en"><code>#include &lt;gtkmm/widget.h&gt;
#include &lt;gtkmm/actionable.h&gt;
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/widget_p.h)

namespace Gtk
{

class Button
  : public Widget,
    public Actionable
{
  _CLASS_GTKOBJECT(Button, GtkButton, GTK_BUTTON, Gtk::Widget, GtkWidget)
  _IMPLEMENTS_INTERFACE(Actionable)
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
</code></programlisting>
<para xml:lang="en">The macros in this example do the following:
<variablelist>
    <varlistentry>
        <term xml:lang="en"><function>_DEFS()</function></term>
        <listitem><para xml:lang="en">Specifies the destination directory for generated sources, and the name of the main .defs file that <command>gmmproc</command> should parse.</para></listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en"><function>_PINCLUDE()</function></term>
        <listitem><para xml:lang="en">Tells <command>gmmproc</command> to include a header in the generated <filename>private/button_p.h</filename> file.</para></listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en"><function>_CLASS_GTKOBJECT()</function></term>
        <listitem><para xml:lang="en">Tells <command>gmmproc</command> to add some typedefs, constructors, and standard methods to this class, as appropriate when wrapping a widget.</para></listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en"><function>_IMPLEMENTS_INTERFACE()</function></term>
        <listitem><para xml:lang="en">Tells <command>gmmproc</command> to add initialization code for the interface.</para></listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en"><function>_CTOR_DEFAULT</function></term>
        <listitem><para xml:lang="en">Adds a default constructor.</para></listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en"><function>_WRAP_METHOD()</function>,
            <function>_WRAP_SIGNAL()</function>, and
            <function>_WRAP_PROPERTY()</function></term>
        <listitem><para xml:lang="en">Add methods to wrap parts of the C API.</para></listitem>
    </varlistentry>
</variablelist>
</para>
<para xml:lang="en">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:
</para>
<programlisting xml:lang="en"><code>$ cd gtk/src
$ /usr/lib/glibmm-2.68/proc/gmmproc -I ../../tools/m4 --defs . button . ./../gtkmm
</code></programlisting>
<para>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.</para>
<para>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>.</para>

<para>V následujících oddílech jsou podrobně rozebrána makra.</para>

<section xml:id="gmmproc-m4-conversions">
<title>Konverze m4</title>

<para xml:lang="en">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. <command>gmmproc</command> takes this information
from an .m4 file in your <literal>tools/m4/</literal> or <literal>codegen/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 function. For instance, this
tells <command>gmmproc</command> how to convert a <classname>GtkTreeView</classname>
pointer to a <classname>Gtk::TreeView</classname> pointer:
</para>
<programlisting xml:lang="en"><code>_CONVERSION(`GtkTreeView*',`TreeView*',`Glib::wrap($3)')
</code></programlisting>

<para xml:lang="en"><literal>$3</literal> will be replaced by the parameter name when this
conversion is used by <command>gmmproc</command>.
</para>

<para xml:lang="en">
Some extra macros make this easier and consistent. Look in <application>gtkmm</application>'s .m4 files
for examples. For instance:
</para>
<programlisting xml:lang="en"><code>_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))
</code></programlisting>
</section>

<section xml:id="gmmproc-m4-initializations">
<title>Inicializace m4</title>

<para xml:lang="en">
  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.
  <command>gmmproc</command> allows such functionality, but appropriate initialization macros must
  be included to tell <command>gmmproc</command> how to initialize the C++ parameter from the
  return of the C function.
</para>
<para xml:lang="en">
  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:
</para>
<programlisting xml:lang="en"><code>_INITIALIZATION(`Gtk::Widget&amp;',`GtkWidget*',`$3 = Glib::wrap($4)')
</code></programlisting>

<para xml:lang="en">
  <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 <command>gmmproc</command>.  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.
</para>
</section>

<section xml:id="gmmproc-class-macros">
<title>Makra pro třídy</title>

<para>Makro 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.</para>
<para>Ostatní 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>.</para>

<section xml:id="gmmproc-class-gobject">
<title>_CLASS_GOBJECT</title>

<para>Toto makro deklaruje obalení pro typ, který je odvozený z <classname>GObject</classname>, ale jeho obalení není odvozené z <classname>Gtk::Object</classname>.</para>
<para xml:lang="en"><function>_CLASS_GOBJECT( C++ class, C class, C casting macro, C++ base class, C base class )</function></para>
<para xml:lang="en">For instance, from <filename>adjustment.hg</filename>:</para>
<programlisting xml:lang="en"><code>_CLASS_GOBJECT(Adjustment, GtkAdjustment, GTK_ADJUSTMENT, Glib::Object, GObject)
</code></programlisting>
</section>

<section xml:id="gmmproc-class-gtkobject">
<title>_CLASS_GTKOBJECT</title>

<para>Toto makro deklaruje obalení pro typ, jehož obalení je odvozené z <classname>Gtk::Object</classname>, jako je widget nebo dialog.</para>
<para xml:lang="en"><function>_CLASS_GTKOBJECT( C++ class, C class, C casting macro, C++ base class, C base class )</function></para>
<para xml:lang="en">For instance, from <filename>button.hg</filename>:</para>
<programlisting xml:lang="en"><code>_CLASS_GTKOBJECT(Button, GtkButton, GTK_BUTTON, Gtk::Widget, GtkWidget)
</code></programlisting>
<para xml:lang="en">You will typically use this macro when the class already derives from
    <classname>Gtk::Object</classname>. For instance, you will use it when wrapping
    a GTK Widget, because <classname>Gtk::Widget</classname> derives from
    <classname>Gtk::Object</classname>.</para>
<para xml:lang="en">You might also derive non-widget classes from
    <classname>Gtk::Object</classname> so they can be used without
    <classname>Glib::RefPtr</classname>. For instance, they could then be
    instantiated with <function>Gtk::make_managed()</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.</para>
</section>

<section xml:id="gmmproc-class-boxedtype">
<title>_CLASS_BOXEDTYPE</title>

<para>Toto makro deklaruje obalení pro jinou strukturu než <classname>GObject</classname> registrovanou pomocí <function>g_boxed_type_register_static()</function>.</para>
<para xml:lang="en"><function>_CLASS_BOXEDTYPE( C++ class, C class, new function, copy function, free function )</function></para>
<para xml:lang="en">For instance, from <classname>Gdk::RGBA</classname>:</para>
<programlisting xml:lang="en"><code>_CLASS_BOXEDTYPE(RGBA, GdkRGBA, NONE, gdk_rgba_copy, gdk_rgba_free)
</code></programlisting>
</section>

<section xml:id="gmmproc-class-boxedtype-static">
<title>_CLASS_BOXEDTYPE_STATIC</title>

<para>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.</para>
<para xml:lang="en"><function>_CLASS_BOXEDTYPE_STATIC( C++ class, C class )</function></para>
<para xml:lang="en">For instance, for <classname>Gdk::Rectangle</classname>:</para>
<programlisting xml:lang="en"><code>_CLASS_BOXEDTYPE_STATIC(Rectangle, GdkRectangle)
</code></programlisting>
</section>

<section xml:id="gmmproc-class-opaque-copyable">
<title>_CLASS_OPAQUE_COPYABLE</title>

<para>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.</para>
<para xml:lang="en"><function>_CLASS_OPAQUE_COPYABLE( C++ class, C class, new function, copy function, free function )</function></para>
<para xml:lang="en">For instance, from <classname>Glib::VariantType</classname>:</para>
<programlisting xml:lang="en"><code>_CLASS_OPAQUE_COPYABLE(VariantType, GVariantType, NONE, g_variant_type_copy, g_variant_type_free)
</code></programlisting>
</section>

<section xml:id="gmmproc-class-opaque-refcounted">
<title>_CLASS_OPAQUE_REFCOUNTED</title>

<para>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>.</para>
<para xml:lang="en"><function>_CLASS_OPAQUE_REFCOUNTED( C++ class, C class, new function, ref function, unref function )</function></para>
<para xml:lang="en">For instance, for <classname>Gtk::CssSection</classname>:</para>
<programlisting xml:lang="en"><code>_CLASS_OPAQUE_REFCOUNTED(CssSection, GtkCssSection, NONE, gtk_css_section_ref, gtk_css_section_unref)
</code></programlisting>
</section>

<section xml:id="gmmproc-class-generic">
<title>_CLASS_GENERIC</title>

<para>Toto makro se dá použít k obalení struktur, které nezapadají do žádné speciální kategorie.</para>
<para xml:lang="en"><function>_CLASS_GENERIC( C++ class, C class )</function></para>
<para xml:lang="en">For instance, for <classname>Gdk::TimeCoord</classname>:</para>
<programlisting xml:lang="en"><code>_CLASS_GENERIC(TimeCoord, GdkTimeCoord)
</code></programlisting>
</section>

<section xml:id="gmmproc-class-interface">
<title>_CLASS_INTERFACE</title>

<para>Toto makro deklaruje obalení pro typ, který je odvozený z <classname>GTypeInterface</classname>.</para>
<para xml:lang="en"><function>_CLASS_INTERFACE( C++ class, C class, C casting macro, C interface struct, Base C++ class (optional), Base C class (optional) )</function></para>
<para xml:lang="en">
For instance, from <filename>celleditable.hg</filename>:</para>
<programlisting xml:lang="en"><code>_CLASS_INTERFACE(CellEditable, GtkCellEditable, GTK_CELL_EDITABLE, GtkCellEditableIface)
</code></programlisting>
<para xml:lang="en">Two extra optional parameters were once added, for the case that the interface derives
from another interface, which was believed to be the case when the GInterface has another
GInterface as a prerequisite. This is a misunderstanding, though.
When GInterface A has GInterface B as a prerequisite, it means that every class
that implements A shall also implement B.
For instance, from <filename>loadableicon.hg</filename> in glibmm-2.4:</para>
<programlisting xml:lang="en"><code>_CLASS_INTERFACE(LoadableIcon, GLoadableIcon, G_LOADABLE_ICON, GLoadableIconIface, Icon, GIcon)
</code></programlisting>
</section>

</section>

<section xml:id="gmmproc-constructor-macros">
<title>Makra pro konstruktory</title>

<para xml:lang="en">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 <application>gtkmm</application> must actually instantiate derived GTypes, and the
    <function>*_new()</function> C functions are meant only as convenience
    functions for C programmers.</para>
<para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>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)
</code></programlisting>

<section xml:id="gmmproc-ctor-default">
<title>_CTOR_DEFAULT</title>

<para>Toto makro vytváří výchozí konstruktor bez argumentů.</para>
</section>

<section xml:id="gmmproc-wrap-ctor">
<title>_WRAP_CTOR</title>

<para>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.</para>

<para xml:lang="en">It also takes an optional extra argument:
  <variablelist>
    <varlistentry>
        <term xml:lang="en">errthrow</term>
        <listitem>
          <para xml:lang="en">This tells <command>gmmproc</command> that the C <function>*_new()</function> has
            a final <type>GError**</type> parameter which should be ignored.</para>
        </listitem>
    </varlistentry>
  </variablelist>
</para>
</section>

<section xml:id="gmmproc-ctor-manual">
<title>Ruční psaní konstruktorů</title>

<para xml:lang="en">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>:</para>
<programlisting xml:lang="en"><code>Button::Button(const Glib::ustring&amp; label, bool mnemonic)
:
  _CONSTRUCT("label", label.c_str(), "use_underline", gboolean(mnemonic))
{}
</code></programlisting>
</section>

</section>

<section xml:id="gmmproc-suppressing-macros">
<title xml:lang="en">Macros that suppress generation of some code</title>

<para xml:lang="en">Some macros suppress the generation of some code when they are used after
a <function>_CLASS_*</function> macro. Some suppress the definition in the
generated .cc file, others suppress both the declaration in the .h file and
the definition in the .cc file.
</para>

<section xml:id="gmmproc-custom-default-ctor">
<title xml:lang="en">_CUSTOM_DEFAULT_CTOR</title>

<para xml:lang="en">Suppresses declaration and definition of default constructor in
<function>_CLASS_BOXEDTYPE</function>, <function>_CLASS_BOXEDTYPE_STATIC</function>
and <function>_CLASS_OPAQUE_COPYABLE</function>.
</para>
</section>

<section xml:id="gmmproc-custom-ctor-cast">
<title xml:lang="en">_CUSTOM_CTOR_CAST</title>

<para xml:lang="en">Suppresses declaration and definition of the constructor that takes a pointer
to the wrapped C object in <function>_CLASS_BOXEDTYPE</function> and
<function>_CLASS_BOXEDTYPE_STATIC</function>.
</para>
<para xml:lang="en">Suppresses definition of the constructor that takes a pointer to the
wrapped C object in <function>_CLASS_INTERFACE</function> and
<function>_CLASS_OPAQUE_COPYABLE</function>.
</para>
<para xml:lang="en">Suppresses definition of the constructor that takes a pointer to the
wrapped C object and the constructor that takes construct_params in
<function>_CLASS_GOBJECT</function> and <function>_CLASS_GTKOBJECT</function>.
</para>
</section>

<section xml:id="gmmproc-custom-dtor">
<title xml:lang="en">_CUSTOM_DTOR</title>

<para xml:lang="en">Suppresses definition of destructor in
<function>_CLASS_GOBJECT</function> and <function>_CLASS_GTKOBJECT</function>.
</para>
</section>

<section xml:id="gmmproc-custom-move-operations">
<title xml:lang="en">_CUSTOM_MOVE_OPERATIONS</title>

<para xml:lang="en">Suppresses declaration and definition of move constructor and move
assignment operator in <function>_CLASS_GOBJECT</function> and
<function>_CLASS_GTKOBJECT</function>.
</para>
<para xml:lang="en">For example:</para>
<programlisting xml:lang="en"><code>class Derived : public Glib::Object
{
  _CLASS_GOBJECT(Derived, GDerived, G_DERIVED, Glib::Object, GObject)

  _CUSTOM_MOVE_OPERATIONS

public:
  Derived(Derived&amp;&amp; src) noexcept;
  Derived&amp; operator=(Derived&amp;&amp; src) noexcept;
  // ...
};
</code></programlisting>
</section>

<section xml:id="gmmproc-custom-wrap-new">
<title xml:lang="en">_CUSTOM_WRAP_NEW</title>

<para xml:lang="en">Suppresses definition of <function>Glib::wrap_new()</function> function in
<function>_CLASS_GOBJECT</function>.
</para>
</section>

<section xml:id="gmmproc-custom-wrap-function">
<title xml:lang="en">_CUSTOM_WRAP_FUNCTION</title>

<para xml:lang="en">Suppresses definition of <function>Glib::wrap()</function> function in
<function>_CLASS_GOBJECT</function> and <function>_CLASS_GTKOBJECT</function>.
</para>
</section>

<section xml:id="gmmproc-no-wrap-function">
<title xml:lang="en">_NO_WRAP_FUNCTION</title>

<para xml:lang="en">Suppresses declaration and definition of <function>Glib::wrap()</function>
function in <function>_CLASS_GOBJECT</function>, <function>_CLASS_BOXEDTYPE</function>,
<function>_CLASS_BOXEDTYPE_STATIC</function>, <function>_CLASS_OPAQUE_COPYABLE</function>,
<function>_CLASS_INTERFACE</function> and <function>_CLASS_GTKOBJECT</function>.
</para>
</section>

</section>

<section xml:id="gmmproc-method-macros">
<title>Makra pro metody</title>

<section xml:id="gmmproc-wrap-method">
<title>_WRAP_METHOD</title>

<para>Toto makro generuje metodu v C++ pro obalení funkce v C.</para>
<para xml:lang="en"><function>_WRAP_METHOD( C++ method signature, C function name)</function></para>
<para xml:lang="en">For instance, from <filename>entry.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_METHOD(void set_text(const Glib::ustring&amp; text), gtk_entry_set_text)
</code></programlisting>
<para>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>.</para>
<para xml:lang="en">There are some optional extra arguments:
<variablelist>
    <varlistentry>
        <term xml:lang="en">refreturn</term>
        <listitem>
            <para xml:lang="en">Do an extra <function>reference()</function> on the return value,
                in case the C function does not provide a reference.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">errthrow ["&lt;exceptions&gt;"]</term>
        <listitem>
            <para xml:lang="en">Use the last GError** parameter of the C function to
                throw an exception.
                The optional "&lt;exceptions&gt;" is a comma-separated list
                of exceptions that can be thrown. It determines which @throws
                Doxygen commands are added to the documentation. Default value
                is <classname>Glib::Error</classname>. If you want a comma in
                the description of an exception, precede it by a backslash. Example:
                <code>errthrow "Glib::OptionError Hello\, world, Glib::ConvertError"</code></para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">deprecated ["&lt;text&gt;"]</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks. Text about the
                deprecation can be specified as an optional
                parameter.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">ignore_deprecations</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in the .cc file in a
                G_GNUC_BEGIN_IGNORE_DEPRECATIONS / G_GNUC_END_IGNORE_DEPRECATIONS
                block. (Only in glibmm &gt;= 2.70.1)</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">constversion</term>
        <listitem>
            <para xml:lang="en">Just call the non-const version of the same function,
                instead of generating almost duplicate code.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">newin "&lt;version&gt;"</term>
        <listitem>
            <para xml:lang="en">Adds a @newin Doxygen command to the documentation, or replaces
                the @newin command generated from the C documentation.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">ifdef &lt;identifier&gt;</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">slot_name &lt;parameter_name&gt;</term>
        <listitem>
          <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">slot_callback &lt;function_name&gt;</term>
        <listitem>
          <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">no_slot_copy</term>
        <listitem>
          <para xml:lang="en">Tells <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_callback</literal> options respectively.</para>
        </listitem>
    </varlistentry>
</variablelist>
</para>
<para xml:lang="en">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:
<itemizedlist>
    <listitem><para xml:lang="en">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>.</para></listitem>
    <listitem><para xml:lang="en">Const 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>.</para></listitem>
<listitem><para xml:lang="en">Wrapping <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.</para></listitem>
<listitem><para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>#m4 _CONVERSION(`GSList*',`std::vector&lt;Widget*&gt;',`Glib::SListHandler&lt;Widget*&gt;::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)')</code></programlisting></listitem>
</itemizedlist>
</para>
</section>

<section xml:id="gmmproc-wrap-method-docs-only">
<title>_WRAP_METHOD_DOCS_ONLY</title>

<para>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.</para>
<para xml:lang="en"><function>_WRAP_METHOD_DOCS_ONLY(C function name)</function></para>
<para xml:lang="en">For instance, from <filename>recentinfo.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_applications)
</code></programlisting>
<para xml:lang="en">There are some optional extra arguments:
<variablelist>
    <varlistentry>
        <term xml:lang="en">errthrow ["&lt;exceptions&gt;"]</term>
        <listitem>
            <para xml:lang="en">Excludes documentation of the last GError** parameter of
                the C function.
                The optional "&lt;exceptions&gt;" is a comma-separated list
                of exceptions that can be thrown. It determines which @throws
                Doxygen commands are added to the documentation. Default value
                is <classname>Glib::Error</classname>. If you want a comma in
                the description of an exception, precede it by a backslash. Example:
                <code>errthrow "Glib::OptionError Hello\, world, Glib::ConvertError"</code></para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">newin "&lt;version&gt;"</term>
        <listitem>
            <para xml:lang="en">Adds a @newin Doxygen command to the documentation, or replaces
                the @newin command generated from the C documentation.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">voidreturn</term>
        <listitem>
            <para xml:lang="en">Don't include a @return Doxygen command in the documentation.
                Useful if the wrapped C function returns a value, but the corresponding
                C++ method returns <type>void</type>.</para>
        </listitem>
    </varlistentry>
</variablelist>
</para>
</section>

<section xml:id="gmmproc-ignore">
<title xml:lang="en">_IGNORE, _IGNORE_SIGNAL, _IGNORE_PROPERTY</title>

<para xml:lang="en"><command>gmmproc</command> will warn you on stdout about functions, signals,
    properties and child properties 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, signals, properties or child properties, or if you chose
    to hand-code some methods then you can use the _IGNORE(), _IGNORE_SIGNAL()
    or _IGNORE_PROPERTY() macro to make <command>gmmproc</command> stop complaining.
</para>
<para>
<literallayout class="normal" xml:lang="en"><function>_IGNORE(C function name 1, C function name 2, etc)
_IGNORE_SIGNAL(C signal name 1, C signal name 2, etc)
_IGNORE_PROPERTY(C property name 1, C property name 2, etc)</function></literallayout>
</para>
<para xml:lang="en">For instance, from <filename>flowbox.hg</filename>:</para>
<programlisting xml:lang="en"><code>_IGNORE(gtk_flow_box_set_filter_func, gtk_flow_box_set_sort_func)
_IGNORE_SIGNAL(activate-cursor-child, toggle-cursor-child, move-cursor)
</code></programlisting>
</section>

<section xml:id="gmmproc-wrap-signal">
<title>_WRAP_SIGNAL</title>

<para>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ů.</para>
<para xml:lang="en"><function>_WRAP_SIGNAL( C++ signal handler signature, C signal name)</function></para>
<para xml:lang="en">For instance, from <filename>button.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_SIGNAL(void clicked(),"clicked")
</code></programlisting>
<para>Signá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>.</para>
<para xml:lang="en">There are some optional extra arguments:
<variablelist>
    <varlistentry>
        <term xml:lang="en">no_default_handler</term>
        <listitem>
            <para xml:lang="en">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, and when adding a signal without a public
                C default handler.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">custom_default_handler</term>
        <listitem>
            <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">custom_c_callback</term>
        <listitem>
            <para xml:lang="en">Do not generate a C callback function for the signal.
                Use this when you must generate the callback function by hand.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">refreturn</term>
        <listitem>
            <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">deprecated ["&lt;text&gt;"]</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks. Text about the
                deprecation can be specified as an optional parameter.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">newin "&lt;version&gt;"</term>
        <listitem>
            <para xml:lang="en">Adds a @newin Doxygen command to the documentation, or replaces
                the @newin command generated from the C documentation.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">ifdef &lt;identifier&gt;</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">exception_handler &lt;method_name&gt;</term>
	      <listitem>
	        <para xml:lang="en">Allows to use custom exception handler instead of default one.
	            Exception might be rethrown by user-defined handler, and it will be
	            caught by default handler.</para>
	      </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">detail_name &lt;parameter_name&gt;</term>
	      <listitem>
	        <para xml:lang="en">Adds a <type>const Glib::ustring&amp;</type> parameter to the
	            <methodname>signal_something()</methodname> method. Use it, if the signal
	            accepts a detailed signal name, i.e. if the underlying C code registers
	            the signal with the <literal>G_SIGNAL_DETAILED</literal> flag.</para>
	      </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">two_signal_methods</term>
	      <listitem>
	        <para xml:lang="en">Used in conjunction with the <literal>detail_name</literal>
              option to generate two <methodname>signal_something()</methodname>
              methods, one without a parameter and one with a parameter without
              a default value. With only the <literal>detail_name</literal> option
              one method is generated, with a parameter with default value.
              Use the <literal>two_signal_methods</literal> option, if it's
              necessary in order to preserve ABI.</para>
	      </listitem>
    </varlistentry>
</variablelist>
</para>
</section>

<section xml:id="gmmproc-wrap-property">
<title>_WRAP_PROPERTY</title>

<para>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ů.</para>
<para xml:lang="en"><function>_WRAP_PROPERTY(C property name, C++ type)</function></para>
<para xml:lang="en">For instance, from <filename>button.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_PROPERTY("label", Glib::ustring)
</code></programlisting>
<para xml:lang="en">There are some optional extra arguments:
<variablelist>
    <varlistentry>
        <term xml:lang="en">deprecated ["&lt;text&gt;"]</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks. Text about the
                deprecation can be specified as an optional parameter.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">newin "&lt;version&gt;"</term>
        <listitem>
            <para xml:lang="en">Adds a @newin Doxygen command to the documentation, or replaces
                the @newin command generated from the C documentation.</para>
        </listitem>
    </varlistentry>
</variablelist>
</para>
</section>

<section xml:id="gmmproc-wrap-vfunc">
<title>_WRAP_VFUNC</title>

<para>Toto makro generuje metodu v C++ pro obalení virtuální funkce v C.</para>
<para xml:lang="en"><function>_WRAP_VFUNC( C++ method signature, C function name)</function></para>
<para xml:lang="en">For instance, from <filename>widget.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_VFUNC(SizeRequestMode get_request_mode() const, get_request_mode)
</code></programlisting>
<para xml:lang="en">The 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. Conversions can also be
    written in the .hg file. Virtual functions often require special conversions
    that are best kept local to the .hg file where they are used.</para>
<para xml:lang="en">There are some optional extra arguments:
<variablelist>
    <varlistentry>
        <term xml:lang="en">refreturn</term>
        <listitem>
            <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">refreturn_ctype</term>
        <listitem>
            <para xml:lang="en">Do 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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">keep_return</term>
        <listitem>
            <para xml:lang="en">Keep a copy of the return value in the C callback function,
                in case the calling C function does not expect to get its own
                reference.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">errthrow</term>
        <listitem>
            <para xml:lang="en">Use the last GError** parameter of the C virtual function (if
              there is one) to throw an exception.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">custom_vfunc</term>
        <listitem>
            <para xml:lang="en">Do not generate a definition of the vfunc in the
               <filename>.cc</filename> file. Use this when you must generate
               the vfunc by hand.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">custom_vfunc_callback</term>
        <listitem>
            <para xml:lang="en">Do not generate a C callback function for the vfunc.
                Use this when you must generate the callback function by hand.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">ifdef &lt;identifier&gt;</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">slot_name &lt;parameter_name&gt;</term>
        <listitem>
          <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">slot_callback &lt;function_name&gt;</term>
        <listitem>
          <para xml:lang="en">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.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">no_slot_copy</term>
        <listitem>
          <para xml:lang="en">Tells <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_callback</literal> options respectively.</para>
        </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">return_value &lt;value&gt;</term>
	      <listitem>
	        <para xml:lang="en">Defines a non-default return value.</para>
	      </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">err_return_value &lt;value&gt;</term>
	      <listitem>
	        <para xml:lang="en">Defines a non-default return value, used only if the C++
	          <function>something_vfunc()</function> function throws an exception
	          which is propagated to the C callback function. If return_value is
	          specified, but err_return_value is not, then return_value is used
	          also when an exception is propagated.</para>
	      </listitem>
    </varlistentry>
    <varlistentry>
        <term xml:lang="en">exception_handler &lt;method_name&gt;</term>
	      <listitem>
	        <para xml:lang="en">Allows to use custom exception handler instead of default one.
	            Exception might be rethrown by user-defined handler, and it will be
	            caught by default handler.</para>
	      </listitem>
    </varlistentry>
</variablelist>
</para>
<para>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>.</para>
</section>

</section>

<section xml:id="gmmproc-other-macros">
<title>Ostatní makra</title>

<section xml:id="gmmproc-implements-interface">
<title>_IMPLEMENTS_INTERFACE</title>

<para>Toto makro generuje inicializační kód pro rozhraní.</para>
<para xml:lang="en"><function>_IMPLEMENTS_INTERFACE(C++ interface name)</function></para>
<para xml:lang="en">For instance, from <filename>grid.hg</filename>:</para>
<programlisting xml:lang="en"><code>_IMPLEMENTS_INTERFACE(Orientable)
</code></programlisting>
<para xml:lang="en">There is one optional extra argument:
<variablelist>
    <varlistentry>
        <term xml:lang="en">ifdef &lt;identifier&gt;</term>
        <listitem>
            <para xml:lang="en">Puts the generated code in #ifdef blocks.</para>
        </listitem>
    </varlistentry>
</variablelist>
</para>
</section>

<section xml:id="gmmproc-wrap-enum">
<title>_WRAP_ENUM</title>

<para>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.</para>
<para xml:lang="en">For instance, from <filename>enums.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_ENUM(Orientation, GtkOrientation)
</code></programlisting>
<para xml:lang="en">There are some optional extra arguments:
<variablelist>
  <varlistentry>
    <term xml:lang="en">NO_GTYPE</term>
    <listitem>
      <para xml:lang="en">Use this option, if the enum is not a <classname>GType</classname>.
        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.</para>
      <para xml:lang="en">If you specify <literal>NO_GTYPE</literal>, don't use that enum as the
        type in _WRAP_PROPERTY. It would cause a runtime error, when the generated
        <methodname>property_*()</methodname> method is called.</para>
      <para xml:lang="en">For example, from <filename>icontheme.hg</filename>:</para>
      <programlisting xml:lang="en"><code>_WRAP_ENUM(IconLookupFlags, GtkIconLookupFlags, NO_GTYPE)
      </code></programlisting>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">gtype_func &lt;function_name&gt;</term>
    <listitem>
      <para xml:lang="en">Specifies the name of the <function>*_get_type()</function> function
        for the C enum. Use this parameter if <command>gmmproc</command> can't
        deduce the correct function name from the name of the C enum type.</para>
      <para xml:lang="en">For example, from <filename>dbusproxy.hg</filename> in glibmm:</para>
      <programlisting xml:lang="en"><code>_WRAP_ENUM(ProxyFlags, GDBusProxyFlags, gtype_func g_dbus_proxy_flags_get_type)
      </code></programlisting>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">CONV_TO_INT</term>
    <listitem>
      <para xml:lang="en">"Convertible to int." Generates a plain enum (not an enum class)
        within a class. Such an enum is scoped like an enum class, but unlike an
        enum class, it can be implicitly converted to <type>int</type>.</para>
      <para xml:lang="en">For example, from <filename>dialog.hg</filename>:</para>
      <programlisting xml:lang="en"><code>_WRAP_ENUM(ResponseType, GtkResponseType, CONV_TO_INT)
      </code></programlisting>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">s#&lt;from&gt;#&lt;to&gt;#</term>
    <listitem>
      <para xml:lang="en">Substitutes (part of) the name of one or more enum constants.
        You can add any number of substitutions.</para>
      <para xml:lang="en">For example, from <filename>iochannel.hg</filename> in glibmm:</para>
      <programlisting xml:lang="en"><code>_WRAP_ENUM(SeekType, GSeekType, NO_GTYPE, s#^SEEK_#SEEK_TYPE_#)
      </code></programlisting>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">deprecated ["&lt;text&gt;"]</term>
    <listitem>
      <para xml:lang="en">Puts the generated code in #ifdef blocks. Text about the
        deprecation can be specified as an optional parameter.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term xml:lang="en">newin "&lt;version&gt;"</term>
    <listitem>
      <para xml:lang="en">Adds a @newin Doxygen command to the documentation, or replaces
        the @newin command generated from the C documentation.</para>
    </listitem>
  </varlistentry>
</variablelist>
</para>
</section>

<section xml:id="gmmproc-wrap-enum-docs-only">
<title>_WRAP_ENUM_DOCS_ONLY</title>

<para xml:lang="en">This macro just generates a Doxygen documentation 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 processes the same options (though
  NO_GTYPE, gtype_func &lt;function_name&gt; and CONV_TO_INT are ignored because
  they make no difference when just generating the enum's documentation).
</para>
</section>

<section xml:id="gmmproc-wrap-gerror">
<title>_WRAP_GERROR</title>

<para xml:lang="en">This macro generates a C++ exception class, derived from <classname>Glib::Error</classname>, with
a <type>Code</type> enum and a <methodname>code()</methodname> method. You must specify the desired C++ name, the name
of the corresponding C enum, and the prefix for the C enum values.</para>
<para>Tato výjimka může být vyhozená metodou, která je vygenerovaná pomocí _WRAP_METOD() s volbou errthrow.</para>
<para xml:lang="en">For instance, from <filename>pixbuf.hg</filename>:</para>
<programlisting xml:lang="en"><code>_WRAP_GERROR(PixbufError, GdkPixbufError, GDK_PIXBUF_ERROR)
</code></programlisting>
<para xml:lang="en">_WRAP_GERROR() accepts the same optional arguments as _WRAP_ENUM() (though
CONV_TO_INT is ignored because all exception class enums are plain enums within a class).
</para>
</section>

<section xml:id="gmmproc-member-set-get">
<title>_MEMBER_GET / _MEMBER_SET</title>
  <para>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ů.</para>
  <para xml:lang="en"><function>_MEMBER_GET(C++ name, C name, C++ type, C type)</function></para>
  <para xml:lang="en"><function>_MEMBER_SET(C++ name, C name, C++ type, C type)</function></para>
  <para xml:lang="en">
    For example, in <filename>rectangle.hg</filename>:
  </para>
  <programlisting xml:lang="en"><code>_MEMBER_GET(x, x, int, int)</code></programlisting>
</section>

<section xml:id="gmmproc-member-get-set-ptr">
<title>_MEMBER_GET_PTR / _MEMBER_SET_PTR</title>
  <para>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í.</para>
  <para xml:lang="en"><function>_MEMBER_GET_PTR(C++ name, C name, C++ type, C type)</function></para>
  <para xml:lang="en"><function>_MEMBER_SET_PTR(C++ name, C name, C++ type, C type)</function></para>
  <para xml:lang="en">For example, for <classname>Pango::Analysis</classname> in <filename>item.hg</filename>:
  </para>
<programlisting xml:lang="en"><code>// _MEMBER_GET_PTR(engine_lang, lang_engine, EngineLang*, PangoEngineLang*)
// It's just a comment. It's difficult to find a real-world example.
</code></programlisting>
</section>

<section xml:id="gmmproc-member-get-set-gobject">
<title>_MEMBER_GET_GOBJECT / _MEMBER_SET_GOBJECT</title>
  <para>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í.</para>
  <para xml:lang="en"><function>_MEMBER_GET_GOBJECT(C++ name, C name, C++ type, C type)</function></para>
  <para xml:lang="en"><function>_MEMBER_SET_GOBJECT(C++ name, C name, C++ type, C type)</function></para>
  <para xml:lang="en">For example, in Pangomm, <filename>layoutline.hg</filename>:</para>
<programlisting xml:lang="en"><code>_MEMBER_GET_GOBJECT(layout, layout, Pango::Layout, PangoLayout*)
</code></programlisting>
</section>

</section>

<section xml:id="gmmproc-parameter-processing">
<title>Zpracování parametrů gmmproc</title>
  <para><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>):</para>

  <section xml:id="gmmproc-parameter-reordering">
  <title>Změna pořadí parametrů</title>

    <para xml:lang="en">
      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:</para>
<programlisting xml:lang="en"><code>void gtk_widget_set_device_events(GtkWidget* widget, GdkDevice* device,
  GdkEventMask events);
</code></programlisting>
    <para xml:lang="en">
      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:</para>
<programlisting xml:lang="en"><code>_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)
</code></programlisting>
      <para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>_WRAP_METHOD(void set_device_events(Gdk::EventMask events{.},
  const Glib::RefPtr&lt;const Gdk::Device&gt;&amp; device{.}),
  gtk_widget_set_device_events)
</code></programlisting>
    <warning>
      <para>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.</para>
    </warning>
  </section>

  <section xml:id="gmmproc-optional-parameter-processing">
  <title>Zpracování volitelných parametrů</title>

    <para xml:lang="en">
      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:</para>
<programlisting xml:lang="en"><code>GtkToolItem* gtk_tool_button_new(GtkWidget* icon_widget, const gchar* label);
</code></programlisting>
      <para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>_WRAP_CTOR(ToolButton(Widget&amp; icon_widget, const Glib::ustring&amp; label{?}),
  gtk_tool_button_new)
</code></programlisting>
      <para xml:lang="en">In this case, two constructors would be generated: One with the optional
      parameter and one without it.
    </para>
  </section>

  <section xml:id="gmmproc-output-parameter-processing">
  <title>Zpracování výstupních parametrů</title>

    <para xml:lang="en">
      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:</para>
<programlisting xml:lang="en"><code>GtkSizeRequestMode gtk_widget_get_request_mode(GtkWidget* widget);
</code></programlisting>
      <para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>_WRAP_METHOD(void get_request_mode(SizeRequestMode&amp; mode{OUT}) const,
  gtk_widget_get_request_mode)
</code></programlisting>
      <para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>_INITIALIZATION(`SizeRequestMode&amp;',`GtkSizeRequestMode',`$3 = (SizeRequestMode)($4)')
</code></programlisting>
      <para xml:lang="en">Which could also be written as:</para>
<programlisting xml:lang="en"><code>_INITIALIZATION(`SizeRequestMode&amp;',`GtkSizeRequestMode',`$3 = ($1)($4)')
</code></programlisting>
    <para xml:lang="en">
      <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>out_mime_type</parameter>:</para>
<programlisting xml:lang="en"><code>GInputStream* gdk_clipboard_read_finish(GdkClipboard* clipboard,
  GAsyncResult* result, const char** out_mime_type, GError** error)
</code></programlisting>
      <para xml:lang="en">To have <command>gmmproc</command> place the value returned in the C++
      <parameter>out_mime_type</parameter> output parameter, something like the
      following <function>_WRAP_METHOD()</function> macro could be used:
      </para>
<programlisting xml:lang="en"><code><![CDATA[
_WRAP_METHOD(Glib::RefPtr<Gio::InputStream> read_finish(
  const Glib::RefPtr<Gio::AsyncResult>& result,
  Glib::ustring& out_mime_type{>>}), gdk_clipboard_read_finish, errthrow)
]]></code></programlisting>
      <para xml:lang="en">The <literal>{&gt;&gt;}</literal> following the <parameter>out_mime_type</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>Glib::ustring&amp;</classname> from a
      <classname>const char**</classname> such as the following:</para>
<programlisting xml:lang="en"><code><![CDATA[
_INITIALIZATION(`Glib::ustring&',`const char*',`$3 = Glib::convert_const_gchar_ptr_to_ustring($4)')
]]></code></programlisting>
  </section>

  <section xml:id="gmmproc-string-parameter-processing">
  <title xml:lang="en">String Parameter Processing</title>

    <para xml:lang="en">
      A string-valued input parameter in a C++ method is usually a
      <type>const Glib::ustring&amp;</type> or a <type>const std::string&amp;</type>.
      In C code it's a <type>const gchar*</type>. When an empty string is converted
      to <type>const gchar*</type>, it can be converted either to <literal>nullptr</literal>
      or to a pointer to an empty string (with <methodname>c_str()</methodname>).
      Some parameters in some C functions accept a <literal>nullptr</literal>, and
      interpret it in a special way. Other parameters must not be <literal>nullptr</literal>.
    </para>
    <para xml:lang="en">
      The default conversion in <function>_WRAP_METHOD()</function> and similar
      macros is
      <itemizedlist>
        <listitem><para xml:lang="en">for mandatory parameters (with or without default values):
          empty string to empty string,</para></listitem>
        <listitem><para xml:lang="en">for optional parameters (with appended <literal>{?}</literal>):
          empty string to <literal>nullptr</literal>.</para></listitem>
      </itemizedlist>
      If the default conversion is not the best conversion, append <literal>{NULL}</literal>
      to a mandatory parameter or <literal>{?!NULL}</literal> to an optional
      parameter (<literal>!NULL</literal> = not <literal>NULL</literal>). If you
      append both a C parameter name and <literal>NULL</literal>, separate them
      with a space: <literal>{c_param_name NULL}</literal>.
    </para>
  </section>

</section>

<section xml:id="gmmproc-basic-types">
<title>Základní typy</title>
  <para>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++.</para>
  <segmentedlist>
    <?dbhtml list-presentation="table"?>
    <segtitle>Typ v C</segtitle>
    <segtitle>Typ v C++</segtitle>
    <seglistitem><seg xml:lang="en"><type>gboolean</type></seg><seg xml:lang="en"><type>bool</type></seg></seglistitem>
    <seglistitem><seg xml:lang="en"><type>gint</type></seg><seg xml:lang="en"><type>int</type></seg></seglistitem>
    <seglistitem><seg xml:lang="en"><type>guint</type></seg><seg xml:lang="en"><type>guint</type></seg></seglistitem>
    <seglistitem><seg xml:lang="en"><type>gdouble</type></seg><seg xml:lang="en"><type>double</type></seg></seglistitem>
    <seglistitem><seg xml:lang="en"><type>gunichar</type></seg><seg xml:lang="en"><type>gunichar</type></seg></seglistitem>
    <seglistitem><seg xml:lang="en"><type>gchar*</type></seg><seg xml:lang="en"><classname>Glib::ustring</classname> (or <classname>std::string</classname> for filenames)</seg></seglistitem>
  </segmentedlist>
</section>
</section>

<section xml:id="sec-wrapping-hand-coded-files">
<title>Ručně psané soubory se zdrojovými kódy</title>

<para xml:lang="en">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>meson.build</filename> in the
  <varname>extra_h_files</varname> and <varname>extra_cc_files</varname>
  variables.</para>
</section>

<section xml:id="sec-wrapping-initialization">
<title>Inicializace</title>

<para xml:lang="en">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:</para>
<programlisting xml:lang="en"><code>void init()
{
  Gtk::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.
}
</code></programlisting>
<para>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++.</para>
</section>

<section xml:id="sec-wrapping-problems">
<title>Problémy v API v C</title>

<para>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í.</para>
<section xml:id="wrapping-predeclare-structs">
<title>Nejde předeklarovat struktury</title>

<para xml:lang="en">By convention, structs are declared in glib/GTK-style headers like so:</para>
<programlisting xml:lang="en"><code>typedef struct _ExampleWidget ExampleWidget;

struct _ExampleWidget
{
  ...
};
</code></programlisting>
<para>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.</para>
<para xml:lang="en">
This compiler error might look like this:</para>
<programlisting xml:lang="en"><code>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
</code></programlisting>
<para xml:lang="en">or this:</para>
<programlisting xml:lang="en"><code>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'
</code></programlisting>
<para>Takovéto věci se v knihovně v jazyce C opravují snadno, tak neváhejte poslat příslušnému správci záplatu.</para>
</section>

<section xml:id="wrapping-no-properties">
<title>Chybějící vlastnosti</title>

<para xml:lang="en">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,</para>
<programlisting xml:lang="en"><code>GtkWidget* example_widget_new(int something, const char* thing)
{
        return g_object_new (EXAMPLE_TYPE_WIDGET, "something", something, "thing", thing, NULL);
}
</code></programlisting>
<para>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í.</para>
<para>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é.</para>
<para xml:lang="en">Another workaround is to add a <function>*_construct()</function> function
    that the C++ constructor can call after instantiating its own type. For
    instance,</para>
<programlisting xml:lang="en"><code>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);
}
</code></programlisting>
<para>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.</para>
</section>
</section>

<section xml:id="sec-wrapping-documentation">
<title>Dokumentace</title>

<para>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ů.</para>

<section xml:id="wrapping-reusing-c-documentation">
<title>Recyklace dokumentace ke knihovnám C</title>

<para xml:lang="en">You might wish to reuse documentation that exists for the C library that
  you are wrapping. GTK-style C libraries typically use gtk-doc or gi-docgen and therefore
  have source code comments formatted for gtk-doc or gi-docgen 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.</para>
<para>Například</para>
<programlisting xml:lang="en"><code>./docextract_to_xml.py -s ~/checkout/gnome/gtk/gtk/ &gt; gtk_docs.xml
</code></programlisting>
<para xml:lang="en">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. Alternatively you can write your own documentation in the
    <filename>.hg</filename> file.</para>
</section>

<section xml:id="wrapping-documentation-build-structure">
<title>Struktura pro sestavení dokumentace</title>

<para xml:lang="en">If you copied the skeleton source tree in <application>mm-common</application> and substituted the
  placeholder text, then you will already have suitable <filename>meson.build</filename>
  and <filename>Doxyfile.in</filename> files in the <filename>doc/reference/</filename>
  directory. You probably need to modify the <varname>tag_file_modules</varname>
  variable in <filename>meson.build</filename>, though.
  With the <application>mm-common</application> build setup, the list
  of Doxygen input files is not defined in the Doxygen configuration file, but passed
  along from <command>meson/ninja</command> to the standard input of <command>doxygen</command>.
</para>
</section>

</section>

</appendix>

</book>