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
|
/* gtkcellareabox.c
*
* Copyright (C) 2010 Openismus GmbH
*
* Authors:
* Tristan Van Berkom <tristanvb@openismus.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* SECTION:gtkcellareabox
* @Short_Description: A cell area that renders GtkCellRenderers
* into a row or a column
* @Title: GtkCellAreaBox
*
* The #GtkCellAreaBox renders cell renderers into a row or a column
* depending on its #GtkOrientation.
*
* GtkCellAreaBox uses a notion of packing. Packing
* refers to adding cell renderers with reference to a particular position
* in a #GtkCellAreaBox. There are two reference positions: the
* start and the end of the box.
* When the #GtkCellAreaBox is oriented in the %GTK_ORIENTATION_VERTICAL
* orientation, the start is defined as the top of the box and the end is
* defined as the bottom. In the %GTK_ORIENTATION_HORIZONTAL orientation
* start is defined as the left side and the end is defined as the right
* side.
*
* Alignments of #GtkCellRenderers rendered in adjacent rows can be
* configured by configuring the #GtkCellAreaBox align child cell property
* with gtk_cell_area_cell_set_property() or by specifying the "align"
* argument to gtk_cell_area_box_pack_start() and gtk_cell_area_box_pack_end().
*/
#include "config.h"
#include "gtkintl.h"
#include "gtkorientable.h"
#include "gtkcelllayout.h"
#include "gtkcellareabox.h"
#include "gtkcellareaboxcontextprivate.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
/* GObjectClass */
static void gtk_cell_area_box_finalize (GObject *object);
static void gtk_cell_area_box_dispose (GObject *object);
static void gtk_cell_area_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_cell_area_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
/* GtkCellAreaClass */
static void gtk_cell_area_box_add (GtkCellArea *area,
GtkCellRenderer *renderer);
static void gtk_cell_area_box_remove (GtkCellArea *area,
GtkCellRenderer *renderer);
static void gtk_cell_area_box_foreach (GtkCellArea *area,
GtkCellCallback callback,
gpointer callback_data);
static void gtk_cell_area_box_foreach_alloc (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
const GdkRectangle *cell_area,
const GdkRectangle *background_area,
GtkCellAllocCallback callback,
gpointer callback_data);
static void gtk_cell_area_box_apply_attributes (GtkCellArea *area,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gboolean is_expander,
gboolean is_expanded);
static void gtk_cell_area_box_set_cell_property (GtkCellArea *area,
GtkCellRenderer *renderer,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_cell_area_box_get_cell_property (GtkCellArea *area,
GtkCellRenderer *renderer,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static GtkCellAreaContext *gtk_cell_area_box_create_context (GtkCellArea *area);
static GtkCellAreaContext *gtk_cell_area_box_copy_context (GtkCellArea *area,
GtkCellAreaContext *context);
static GtkSizeRequestMode gtk_cell_area_box_get_request_mode (GtkCellArea *area);
static void gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint *minimum_width,
gint *natural_width);
static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint *minimum_height,
gint *natural_height);
static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint width,
gint *minimum_height,
gint *natural_height);
static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint height,
gint *minimum_width,
gint *natural_width);
static gboolean gtk_cell_area_box_focus (GtkCellArea *area,
GtkDirectionType direction);
/* GtkCellLayoutIface */
static void gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface);
static void gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
GtkCellRenderer *renderer,
gboolean expand);
static void gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
GtkCellRenderer *renderer,
gboolean expand);
static void gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
GtkCellRenderer *renderer,
gint position);
static void gtk_cell_area_box_focus_changed (GtkCellArea *area,
GParamSpec *pspec,
GtkCellAreaBox *box);
/* CellInfo/CellGroup metadata handling and convenience functions */
typedef struct {
GtkCellRenderer *renderer;
guint expand : 1; /* Whether the cell expands */
guint pack : 1; /* Whether it is packed from the start or end */
guint align : 1; /* Whether to align its position with adjacent rows */
guint fixed : 1; /* Whether to require the same size for all rows */
} CellInfo;
typedef struct {
GList *cells;
guint id : 8;
guint n_cells : 8;
guint expand_cells : 8;
guint align : 1;
guint visible : 1;
} CellGroup;
typedef struct {
GtkCellRenderer *renderer;
gint position;
gint size;
} AllocatedCell;
static CellInfo *cell_info_new (GtkCellRenderer *renderer,
GtkPackType pack,
gboolean expand,
gboolean align,
gboolean fixed);
static void cell_info_free (CellInfo *info);
static gint cell_info_find (CellInfo *info,
GtkCellRenderer *renderer);
static AllocatedCell *allocated_cell_new (GtkCellRenderer *renderer,
gint position,
gint size);
static void allocated_cell_free (AllocatedCell *cell);
static GList *list_consecutive_cells (GtkCellAreaBox *box);
static gint count_expand_groups (GtkCellAreaBox *box);
static void context_weak_notify (GtkCellAreaBox *box,
GtkCellAreaBoxContext *dead_context);
static void reset_contexts (GtkCellAreaBox *box);
static void init_context_groups (GtkCellAreaBox *box);
static void init_context_group (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context);
static GSList *get_allocated_cells (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context,
GtkWidget *widget,
gint width,
gint height);
struct _GtkCellAreaBoxPrivate
{
/* We hold on to the previously focused cell when navigating
* up and down in a horizontal box (or left and right on a vertical one)
* this way we always re-enter the last focused cell.
*/
GtkCellRenderer *last_focus_cell;
gulong focus_cell_id;
GList *cells;
GArray *groups;
GSList *contexts;
GtkOrientation orientation;
gint spacing;
/* We hold on to the rtl state from a widget we are requested for
* so that we can navigate focus correctly
*/
gboolean rtl;
};
enum {
PROP_0,
PROP_ORIENTATION,
PROP_SPACING
};
enum {
CELL_PROP_0,
CELL_PROP_EXPAND,
CELL_PROP_ALIGN,
CELL_PROP_FIXED_SIZE,
CELL_PROP_PACK_TYPE
};
G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
G_ADD_PRIVATE (GtkCellAreaBox)
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
gtk_cell_area_box_cell_layout_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
static void
gtk_cell_area_box_init (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv;
box->priv = gtk_cell_area_box_get_instance_private (box);
priv = box->priv;
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
priv->groups = g_array_new (FALSE, TRUE, sizeof (CellGroup));
priv->cells = NULL;
priv->contexts = NULL;
priv->spacing = 0;
priv->rtl = FALSE;
/* Watch whenever focus is given to a cell, even if it's not with keynav,
* this way we remember upon entry of the area where focus was last time
* around
*/
priv->focus_cell_id = g_signal_connect (box, "notify::focus-cell",
G_CALLBACK (gtk_cell_area_box_focus_changed), box);
}
static void
gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
/* GObjectClass */
object_class->finalize = gtk_cell_area_box_finalize;
object_class->dispose = gtk_cell_area_box_dispose;
object_class->set_property = gtk_cell_area_box_set_property;
object_class->get_property = gtk_cell_area_box_get_property;
/* GtkCellAreaClass */
area_class->add = gtk_cell_area_box_add;
area_class->remove = gtk_cell_area_box_remove;
area_class->foreach = gtk_cell_area_box_foreach;
area_class->foreach_alloc = gtk_cell_area_box_foreach_alloc;
area_class->apply_attributes = gtk_cell_area_box_apply_attributes;
area_class->set_cell_property = gtk_cell_area_box_set_cell_property;
area_class->get_cell_property = gtk_cell_area_box_get_cell_property;
area_class->create_context = gtk_cell_area_box_create_context;
area_class->copy_context = gtk_cell_area_box_copy_context;
area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
area_class->focus = gtk_cell_area_box_focus;
/* Properties */
g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
/**
* GtkCellAreaBox:spacing:
*
* The amount of space to reserve between cells.
*
* Since: 3.0
*/
g_object_class_install_property (object_class,
PROP_SPACING,
g_param_spec_int ("spacing",
P_("Spacing"),
P_("Space which is inserted between cells"),
0,
G_MAXINT,
0,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/* Cell Properties */
/**
* GtkCellAreaBox:expand:
*
* Whether the cell renderer should receive extra space
* when the area receives more than its natural size.
*
* Since: 3.0
*/
gtk_cell_area_class_install_cell_property (area_class,
CELL_PROP_EXPAND,
g_param_spec_boolean
("expand",
P_("Expand"),
P_("Whether the cell expands"),
FALSE,
GTK_PARAM_READWRITE));
/**
* GtkCellAreaBox:align:
*
* Whether the cell renderer should be aligned in adjacent rows.
*
* Since: 3.0
*/
gtk_cell_area_class_install_cell_property (area_class,
CELL_PROP_ALIGN,
g_param_spec_boolean
("align",
P_("Align"),
P_("Whether cell should align with adjacent rows"),
FALSE,
GTK_PARAM_READWRITE));
/**
* GtkCellAreaBox:fixed-size:
*
* Whether the cell renderer should require the same size
* for all rows for which it was requested.
*
* Since: 3.0
*/
gtk_cell_area_class_install_cell_property (area_class,
CELL_PROP_FIXED_SIZE,
g_param_spec_boolean
("fixed-size",
P_("Fixed Size"),
P_("Whether cells should be the same size in all rows"),
TRUE,
GTK_PARAM_READWRITE));
/**
* GtkCellAreaBox:pack-type:
*
* A GtkPackType indicating whether the cell renderer is packed
* with reference to the start or end of the area.
*
* Since: 3.0
*/
gtk_cell_area_class_install_cell_property (area_class,
CELL_PROP_PACK_TYPE,
g_param_spec_enum
("pack-type",
P_("Pack Type"),
P_("A GtkPackType indicating whether the cell is packed with "
"reference to the start or end of the cell area"),
GTK_TYPE_PACK_TYPE, GTK_PACK_START,
GTK_PARAM_READWRITE));
}
/*************************************************************
* CellInfo/CellGroup basics and convenience functions *
*************************************************************/
static CellInfo *
cell_info_new (GtkCellRenderer *renderer,
GtkPackType pack,
gboolean expand,
gboolean align,
gboolean fixed)
{
CellInfo *info = g_slice_new (CellInfo);
info->renderer = g_object_ref_sink (renderer);
info->pack = pack;
info->expand = expand;
info->align = align;
info->fixed = fixed;
return info;
}
static void
cell_info_free (CellInfo *info)
{
g_object_unref (info->renderer);
g_slice_free (CellInfo, info);
}
static gint
cell_info_find (CellInfo *info,
GtkCellRenderer *renderer)
{
return (info->renderer == renderer) ? 0 : -1;
}
static AllocatedCell *
allocated_cell_new (GtkCellRenderer *renderer,
gint position,
gint size)
{
AllocatedCell *cell = g_slice_new (AllocatedCell);
cell->renderer = renderer;
cell->position = position;
cell->size = size;
return cell;
}
static void
allocated_cell_free (AllocatedCell *cell)
{
g_slice_free (AllocatedCell, cell);
}
static GList *
list_consecutive_cells (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv = box->priv;
GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
CellInfo *info;
/* List cells in consecutive order taking their
* PACK_START/PACK_END options into account
*/
for (l = priv->cells; l; l = l->next)
{
info = l->data;
if (info->pack == GTK_PACK_START)
consecutive_cells = g_list_prepend (consecutive_cells, info);
}
for (l = priv->cells; l; l = l->next)
{
info = l->data;
if (info->pack == GTK_PACK_END)
pack_end_cells = g_list_prepend (pack_end_cells, info);
}
consecutive_cells = g_list_reverse (consecutive_cells);
consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
return consecutive_cells;
}
static void
cell_groups_clear (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv = box->priv;
gint i;
for (i = 0; i < priv->groups->len; i++)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
g_list_free (group->cells);
}
g_array_set_size (priv->groups, 0);
}
static void
cell_groups_rebuild (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv = box->priv;
CellGroup group = { 0, };
CellGroup *group_ptr;
GList *cells, *l;
guint id = 0;
gboolean last_cell_fixed = FALSE;
cell_groups_clear (box);
if (!priv->cells)
return;
cells = list_consecutive_cells (box);
/* First group is implied */
g_array_append_val (priv->groups, group);
group_ptr = &g_array_index (priv->groups, CellGroup, id);
for (l = cells; l; l = l->next)
{
CellInfo *info = l->data;
/* A new group starts with any aligned cell, or
* at the beginning and end of a fixed size cell.
* the first group is implied */
if ((info->align || info->fixed || last_cell_fixed) && l != cells)
{
memset (&group, 0x0, sizeof (CellGroup));
group.id = ++id;
g_array_append_val (priv->groups, group);
group_ptr = &g_array_index (priv->groups, CellGroup, id);
}
group_ptr->cells = g_list_prepend (group_ptr->cells, info);
group_ptr->n_cells++;
/* Not every group is aligned, some are floating
* fixed size cells */
if (info->align)
group_ptr->align = TRUE;
/* A group expands if it contains any expand cells */
if (info->expand)
group_ptr->expand_cells++;
last_cell_fixed = info->fixed;
}
g_list_free (cells);
for (id = 0; id < priv->groups->len; id++)
{
group_ptr = &g_array_index (priv->groups, CellGroup, id);
group_ptr->cells = g_list_reverse (group_ptr->cells);
}
/* Contexts need to be updated with the new grouping information */
init_context_groups (box);
}
static gint
count_visible_cells (CellGroup *group,
gint *expand_cells)
{
GList *l;
gint visible_cells = 0;
gint n_expand_cells = 0;
for (l = group->cells; l; l = l->next)
{
CellInfo *info = l->data;
if (gtk_cell_renderer_get_visible (info->renderer))
{
visible_cells++;
if (info->expand)
n_expand_cells++;
}
}
if (expand_cells)
*expand_cells = n_expand_cells;
return visible_cells;
}
static gint
count_expand_groups (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv = box->priv;
gint i;
gint expand_groups = 0;
for (i = 0; i < priv->groups->len; i++)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
if (group->expand_cells > 0)
expand_groups++;
}
return expand_groups;
}
static void
context_weak_notify (GtkCellAreaBox *box,
GtkCellAreaBoxContext *dead_context)
{
GtkCellAreaBoxPrivate *priv = box->priv;
priv->contexts = g_slist_remove (priv->contexts, dead_context);
}
static void
init_context_group (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context)
{
GtkCellAreaBoxPrivate *priv = box->priv;
gint *expand_groups, *align_groups, i;
expand_groups = g_new (gboolean, priv->groups->len);
align_groups = g_new (gboolean, priv->groups->len);
for (i = 0; i < priv->groups->len; i++)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
expand_groups[i] = (group->expand_cells > 0);
align_groups[i] = group->align;
}
/* This call implies resetting the request info */
_gtk_cell_area_box_init_groups (context, priv->groups->len, expand_groups, align_groups);
g_free (expand_groups);
g_free (align_groups);
}
static void
init_context_groups (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv = box->priv;
GSList *l;
/* When the box's groups are reconstructed,
* contexts need to be reinitialized.
*/
for (l = priv->contexts; l; l = l->next)
{
GtkCellAreaBoxContext *context = l->data;
init_context_group (box, context);
}
}
static void
reset_contexts (GtkCellAreaBox *box)
{
GtkCellAreaBoxPrivate *priv = box->priv;
GSList *l;
/* When the box layout changes, contexts need to
* be reset and sizes for the box get requested again
*/
for (l = priv->contexts; l; l = l->next)
{
GtkCellAreaContext *context = l->data;
gtk_cell_area_context_reset (context);
}
}
/* Fall back on a completely unaligned dynamic allocation of cells
* when not allocated for the said orientation, alignment of cells
* is not done when each area gets a different size in the orientation
* of the box.
*/
static GSList *
allocate_cells_manually (GtkCellAreaBox *box,
GtkWidget *widget,
gint width,
gint height)
{
GtkCellAreaBoxPrivate *priv = box->priv;
GList *cells, *l;
GSList *allocated_cells = NULL;
GtkRequestedSize *sizes;
gint i;
gint nvisible = 0, nexpand = 0, group_expand;
gint avail_size, extra_size, extra_extra, full_size;
gint position = 0, for_size;
gboolean rtl;
if (!priv->cells)
return NULL;
/* For vertical oriented boxes, we just let the cell renderers
* realign themselves for rtl
*/
rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
cells = list_consecutive_cells (box);
/* Count the visible and expand cells */
for (i = 0; i < priv->groups->len; i++)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
nvisible += count_visible_cells (group, &group_expand);
nexpand += group_expand;
}
if (nvisible <= 0)
{
g_list_free (cells);
return NULL;
}
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
full_size = avail_size = width;
for_size = height;
}
else
{
full_size = avail_size = height;
for_size = width;
}
/* Go ahead and collect the requests on the fly */
sizes = g_new0 (GtkRequestedSize, nvisible);
for (l = cells, i = 0; l; l = l->next)
{
CellInfo *info = l->data;
if (!gtk_cell_renderer_get_visible (info->renderer))
continue;
gtk_cell_area_request_renderer (GTK_CELL_AREA (box), info->renderer,
priv->orientation,
widget, for_size,
&sizes[i].minimum_size,
&sizes[i].natural_size);
avail_size -= sizes[i].minimum_size;
sizes[i].data = info;
i++;
}
/* Naturally distribute the allocation */
avail_size -= (nvisible - 1) * priv->spacing;
if (avail_size > 0)
avail_size = gtk_distribute_natural_allocation (avail_size, nvisible, sizes);
else
avail_size = 0;
/* Calculate/distribute expand for cells */
if (nexpand > 0)
{
extra_size = avail_size / nexpand;
extra_extra = avail_size % nexpand;
}
else
extra_size = extra_extra = 0;
/* Create the allocated cells */
for (i = 0; i < nvisible; i++)
{
CellInfo *info = sizes[i].data;
AllocatedCell *cell;
if (info->expand)
{
sizes[i].minimum_size += extra_size;
if (extra_extra)
{
sizes[i].minimum_size++;
extra_extra--;
}
}
if (rtl)
cell = allocated_cell_new (info->renderer,
full_size - (position + sizes[i].minimum_size),
sizes[i].minimum_size);
else
cell = allocated_cell_new (info->renderer, position, sizes[i].minimum_size);
allocated_cells = g_slist_prepend (allocated_cells, cell);
position += sizes[i].minimum_size;
position += priv->spacing;
}
g_free (sizes);
g_list_free (cells);
/* Note it might not be important to reverse the list here at all,
* we have the correct positions, no need to allocate from left to right
*/
return g_slist_reverse (allocated_cells);
}
/* Returns an allocation for each cell in the orientation of the box,
* used in ->render()/->event() implementations to get a straight-forward
* list of allocated cells to operate on.
*/
static GSList *
get_allocated_cells (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context,
GtkWidget *widget,
gint width,
gint height)
{
GtkCellAreaBoxAllocation *group_allocs;
GtkCellArea *area = GTK_CELL_AREA (box);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *cell_list;
GSList *allocated_cells = NULL;
gint i, j, n_allocs, position;
gint for_size, full_size;
gboolean rtl;
group_allocs = _gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
if (!group_allocs)
return allocate_cells_manually (box, widget, width, height);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
full_size = width;
for_size = height;
}
else
{
full_size = height;
for_size = width;
}
/* For vertical oriented boxes, we just let the cell renderers
* realign themselves for rtl
*/
rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
for (position = 0, i = 0; i < n_allocs; i++)
{
/* We dont always allocate all groups, sometimes the requested
* group has only invisible cells for every row, hence the usage
* of group_allocs[i].group_idx here
*/
CellGroup *group = &g_array_index (priv->groups, CellGroup, group_allocs[i].group_idx);
/* Exception for single cell groups */
if (group->n_cells == 1)
{
CellInfo *info = group->cells->data;
AllocatedCell *cell;
gint cell_position, cell_size;
if (!gtk_cell_renderer_get_visible (info->renderer))
continue;
/* If were not aligned, place the cell after the last cell */
if (info->align)
position = cell_position = group_allocs[i].position;
else
cell_position = position;
/* If not a fixed size, use only the requested size for this row */
if (info->fixed)
cell_size = group_allocs[i].size;
else
{
gint dummy;
gtk_cell_area_request_renderer (area, info->renderer,
priv->orientation,
widget, for_size,
&dummy,
&cell_size);
cell_size = MIN (cell_size, group_allocs[i].size);
}
if (rtl)
cell = allocated_cell_new (info->renderer,
full_size - (cell_position + cell_size), cell_size);
else
cell = allocated_cell_new (info->renderer, cell_position, cell_size);
position += cell_size;
position += priv->spacing;
allocated_cells = g_slist_prepend (allocated_cells, cell);
}
else
{
GtkRequestedSize *sizes;
gint avail_size, cell_position;
gint visible_cells, expand_cells;
gint extra_size, extra_extra;
visible_cells = count_visible_cells (group, &expand_cells);
/* If this row has no visible cells in this group, just
* skip the allocation
*/
if (visible_cells == 0)
continue;
/* If were not aligned, place the cell after the last cell
* and eat up the extra space
*/
if (group->align)
{
avail_size = group_allocs[i].size;
position = cell_position = group_allocs[i].position;
}
else
{
avail_size = group_allocs[i].size + (group_allocs[i].position - position);
cell_position = position;
}
sizes = g_new (GtkRequestedSize, visible_cells);
for (j = 0, cell_list = group->cells; cell_list; cell_list = cell_list->next)
{
CellInfo *info = cell_list->data;
if (!gtk_cell_renderer_get_visible (info->renderer))
continue;
gtk_cell_area_request_renderer (area, info->renderer,
priv->orientation,
widget, for_size,
&sizes[j].minimum_size,
&sizes[j].natural_size);
sizes[j].data = info;
avail_size -= sizes[j].minimum_size;
j++;
}
/* Distribute cells naturally within the group */
avail_size -= (visible_cells - 1) * priv->spacing;
if (avail_size > 0)
avail_size = gtk_distribute_natural_allocation (avail_size, visible_cells, sizes);
else
avail_size = 0;
/* Calculate/distribute expand for cells */
if (expand_cells > 0)
{
extra_size = avail_size / expand_cells;
extra_extra = avail_size % expand_cells;
}
else
extra_size = extra_extra = 0;
/* Create the allocated cells (loop only over visible cells here) */
for (j = 0; j < visible_cells; j++)
{
CellInfo *info = sizes[j].data;
AllocatedCell *cell;
if (info->expand)
{
sizes[j].minimum_size += extra_size;
if (extra_extra)
{
sizes[j].minimum_size++;
extra_extra--;
}
}
if (rtl)
cell = allocated_cell_new (info->renderer,
full_size - (cell_position + sizes[j].minimum_size),
sizes[j].minimum_size);
else
cell = allocated_cell_new (info->renderer, cell_position, sizes[j].minimum_size);
allocated_cells = g_slist_prepend (allocated_cells, cell);
cell_position += sizes[j].minimum_size;
cell_position += priv->spacing;
}
g_free (sizes);
position = cell_position;
}
}
g_free (group_allocs);
/* Note it might not be important to reverse the list here at all,
* we have the correct positions, no need to allocate from left to right
*/
return g_slist_reverse (allocated_cells);
}
static void
gtk_cell_area_box_focus_changed (GtkCellArea *area,
GParamSpec *pspec,
GtkCellAreaBox *box)
{
if (gtk_cell_area_get_focus_cell (area))
box->priv->last_focus_cell = gtk_cell_area_get_focus_cell (area);
}
/*************************************************************
* GObjectClass *
*************************************************************/
static void
gtk_cell_area_box_finalize (GObject *object)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
GtkCellAreaBoxPrivate *priv = box->priv;
GSList *l;
/* Unref/free the context list */
for (l = priv->contexts; l; l = l->next)
g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)context_weak_notify, box);
g_slist_free (priv->contexts);
priv->contexts = NULL;
/* Free the cell grouping info */
cell_groups_clear (box);
g_array_free (priv->groups, TRUE);
G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
}
static void
gtk_cell_area_box_dispose (GObject *object)
{
G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
}
static void
gtk_cell_area_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
switch (prop_id)
{
case PROP_ORIENTATION:
if (box->priv->orientation != g_value_get_enum (value))
{
box->priv->orientation = g_value_get_enum (value);
/* Notify that size needs to be requested again */
reset_contexts (box);
g_object_notify_by_pspec (object, pspec);
}
break;
case PROP_SPACING:
gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_cell_area_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
switch (prop_id)
{
case PROP_ORIENTATION:
g_value_set_enum (value, box->priv->orientation);
break;
case PROP_SPACING:
g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*************************************************************
* GtkCellAreaClass *
*************************************************************/
static void
gtk_cell_area_box_add (GtkCellArea *area,
GtkCellRenderer *renderer)
{
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
renderer, FALSE, FALSE, TRUE);
}
static void
gtk_cell_area_box_remove (GtkCellArea *area,
GtkCellRenderer *renderer)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *node;
if (priv->last_focus_cell == renderer)
priv->last_focus_cell = NULL;
node = g_list_find_custom (priv->cells, renderer,
(GCompareFunc)cell_info_find);
if (node)
{
CellInfo *info = node->data;
cell_info_free (info);
priv->cells = g_list_delete_link (priv->cells, node);
/* Reconstruct cell groups */
cell_groups_rebuild (box);
}
else
g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
}
static void
gtk_cell_area_box_foreach (GtkCellArea *area,
GtkCellCallback callback,
gpointer callback_data)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *list;
for (list = priv->cells; list; list = list->next)
{
CellInfo *info = list->data;
if (callback (info->renderer, callback_data))
break;
}
}
static void
gtk_cell_area_box_foreach_alloc (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
const GdkRectangle *cell_area,
const GdkRectangle *background_area,
GtkCellAllocCallback callback,
gpointer callback_data)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
GSList *allocated_cells, *l;
GdkRectangle cell_alloc, cell_background;
gboolean rtl;
rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
cell_alloc = *cell_area;
/* Get a list of cells with allocation sizes decided regardless
* of alignments and pack order etc.
*/
allocated_cells = get_allocated_cells (box, box_context, widget,
cell_area->width, cell_area->height);
for (l = allocated_cells; l; l = l->next)
{
AllocatedCell *cell = l->data;
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
cell_alloc.x = cell_area->x + cell->position;
cell_alloc.width = cell->size;
}
else
{
cell_alloc.y = cell_area->y + cell->position;
cell_alloc.height = cell->size;
}
/* Stop iterating over cells if they flow out of the render
* area, this can happen because the render area can actually
* be smaller than the requested area (treeview columns can
* be user resizable and can be resized to be smaller than
* the actual requested area).
*/
if (cell_alloc.x > cell_area->x + cell_area->width ||
cell_alloc.x + cell_alloc.width < cell_area->x ||
cell_alloc.y > cell_area->y + cell_area->height)
break;
/* Special case for the last cell (or first cell in rtl)...
* let the last cell consume the remaining space in the area
* (the last cell is allowed to consume the remaining space if
* the space given for rendering is actually larger than allocation,
* this can happen in the expander GtkTreeViewColumn where only the
* deepest depth column receives the allocation... shallow columns
* receive more width). */
if (!l->next)
{
if (rtl)
{
/* Fill the leading space for the first cell in the area
* (still last in the list)
*/
cell_alloc.width = (cell_alloc.x - cell_area->x) + cell_alloc.width;
cell_alloc.x = cell_area->x;
}
else
{
cell_alloc.width = cell_area->x + cell_area->width - cell_alloc.x;
cell_alloc.height = cell_area->y + cell_area->height - cell_alloc.y;
}
}
else
{
/* If the cell we are rendering doesnt fit into the remaining space,
* clip it so that the underlying renderer has a chance to deal with
* it (for instance text renderers get a chance to ellipsize).
*/
if (cell_alloc.x + cell_alloc.width > cell_area->x + cell_area->width)
cell_alloc.width = cell_area->x + cell_area->width - cell_alloc.x;
if (cell_alloc.y + cell_alloc.height > cell_area->y + cell_area->height)
cell_alloc.height = cell_area->y + cell_area->height - cell_alloc.y;
}
/* Add portions of the background_area to the cell_alloc
* to create the cell_background
*/
cell_background = cell_alloc;
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (l == allocated_cells)
{
/* Add the depth to the first cell */
if (rtl)
{
cell_background.width += background_area->width - cell_area->width;
cell_background.x = background_area->x + background_area->width - cell_background.width;
}
else
{
cell_background.width += cell_area->x - background_area->x;
cell_background.x = background_area->x;
}
}
if (l->next == NULL)
{
/* Grant this cell the remaining space */
int remain = cell_background.x - background_area->x;
if (rtl)
cell_background.x -= remain;
else
cell_background.width = background_area->width - remain;
}
cell_background.y = background_area->y;
cell_background.height = background_area->height;
}
else
{
if (l == allocated_cells)
{
cell_background.height += cell_background.y - background_area->y;
cell_background.y = background_area->y;
}
if (l->next == NULL)
cell_background.height =
background_area->height - (cell_background.y - background_area->y);
cell_background.x = background_area->x;
cell_background.width = background_area->width;
}
if (callback (cell->renderer, &cell_alloc, &cell_background, callback_data))
break;
}
g_slist_free_full (allocated_cells, (GDestroyNotify)allocated_cell_free);
}
static void
gtk_cell_area_box_apply_attributes (GtkCellArea *area,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gboolean is_expander,
gboolean is_expanded)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
gint i;
/* Call the parent class to apply the attributes */
GTK_CELL_AREA_CLASS
(gtk_cell_area_box_parent_class)->apply_attributes (area, tree_model, iter,
is_expander, is_expanded);
/* Update visible state for cell groups */
for (i = 0; i < priv->groups->len; i++)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
GList *list;
group->visible = FALSE;
for (list = group->cells; list && group->visible == FALSE; list = list->next)
{
CellInfo *info = list->data;
if (gtk_cell_renderer_get_visible (info->renderer))
group->visible = TRUE;
}
}
}
static void
gtk_cell_area_box_set_cell_property (GtkCellArea *area,
GtkCellRenderer *renderer,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *node;
CellInfo *info;
gboolean rebuild = FALSE;
gboolean val;
GtkPackType pack_type;
node = g_list_find_custom (priv->cells, renderer,
(GCompareFunc)cell_info_find);
if (!node)
return;
info = node->data;
switch (prop_id)
{
case CELL_PROP_EXPAND:
val = g_value_get_boolean (value);
if (info->expand != val)
{
info->expand = val;
rebuild = TRUE;
}
break;
case CELL_PROP_ALIGN:
val = g_value_get_boolean (value);
if (info->align != val)
{
info->align = val;
rebuild = TRUE;
}
break;
case CELL_PROP_FIXED_SIZE:
val = g_value_get_boolean (value);
if (info->fixed != val)
{
info->fixed = val;
rebuild = TRUE;
}
break;
case CELL_PROP_PACK_TYPE:
pack_type = g_value_get_enum (value);
if (info->pack != pack_type)
{
info->pack = pack_type;
rebuild = TRUE;
}
break;
default:
GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID (area, prop_id, pspec);
break;
}
/* Groups need to be rebuilt */
if (rebuild)
cell_groups_rebuild (box);
}
static void
gtk_cell_area_box_get_cell_property (GtkCellArea *area,
GtkCellRenderer *renderer,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *node;
CellInfo *info;
node = g_list_find_custom (priv->cells, renderer,
(GCompareFunc)cell_info_find);
if (!node)
return;
info = node->data;
switch (prop_id)
{
case CELL_PROP_EXPAND:
g_value_set_boolean (value, info->expand);
break;
case CELL_PROP_ALIGN:
g_value_set_boolean (value, info->align);
break;
case CELL_PROP_FIXED_SIZE:
g_value_set_boolean (value, info->fixed);
break;
case CELL_PROP_PACK_TYPE:
g_value_set_enum (value, info->pack);
break;
default:
GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID (area, prop_id, pspec);
break;
}
}
static GtkCellAreaContext *
gtk_cell_area_box_create_context (GtkCellArea *area)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GtkCellAreaContext *context =
(GtkCellAreaContext *)g_object_new (GTK_TYPE_CELL_AREA_BOX_CONTEXT,
"area", area, NULL);
priv->contexts = g_slist_prepend (priv->contexts, context);
g_object_weak_ref (G_OBJECT (context), (GWeakNotify)context_weak_notify, box);
/* Tell the new group about our cell layout */
init_context_group (box, GTK_CELL_AREA_BOX_CONTEXT (context));
return context;
}
static GtkCellAreaContext *
gtk_cell_area_box_copy_context (GtkCellArea *area,
GtkCellAreaContext *context)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
GtkCellAreaContext *copy =
(GtkCellAreaContext *)_gtk_cell_area_box_context_copy (GTK_CELL_AREA_BOX (area),
GTK_CELL_AREA_BOX_CONTEXT (context));
priv->contexts = g_slist_prepend (priv->contexts, copy);
g_object_weak_ref (G_OBJECT (copy), (GWeakNotify)context_weak_notify, box);
return copy;
}
static GtkSizeRequestMode
gtk_cell_area_box_get_request_mode (GtkCellArea *area)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
}
static void
compute_size (GtkCellAreaBox *box,
GtkOrientation orientation,
GtkCellAreaBoxContext *context,
GtkWidget *widget,
gint for_size,
gint *minimum_size,
gint *natural_size)
{
GtkCellAreaBoxPrivate *priv = box->priv;
GtkCellArea *area = GTK_CELL_AREA (box);
GList *list;
gint i;
gint min_size = 0;
gint nat_size = 0;
for (i = 0; i < priv->groups->len; i++)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
gint group_min_size = 0;
gint group_nat_size = 0;
for (list = group->cells; list; list = list->next)
{
CellInfo *info = list->data;
gint renderer_min_size, renderer_nat_size;
if (!gtk_cell_renderer_get_visible (info->renderer))
continue;
gtk_cell_area_request_renderer (area, info->renderer, orientation, widget, for_size,
&renderer_min_size, &renderer_nat_size);
if (orientation == priv->orientation)
{
if (min_size > 0)
{
min_size += priv->spacing;
nat_size += priv->spacing;
}
if (group_min_size > 0)
{
group_min_size += priv->spacing;
group_nat_size += priv->spacing;
}
min_size += renderer_min_size;
nat_size += renderer_nat_size;
group_min_size += renderer_min_size;
group_nat_size += renderer_nat_size;
}
else
{
min_size = MAX (min_size, renderer_min_size);
nat_size = MAX (nat_size, renderer_nat_size);
group_min_size = MAX (group_min_size, renderer_min_size);
group_nat_size = MAX (group_nat_size, renderer_nat_size);
}
}
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (for_size < 0)
_gtk_cell_area_box_context_push_group_width (context, group->id, group_min_size, group_nat_size);
else
_gtk_cell_area_box_context_push_group_width_for_height (context, group->id, for_size,
group_min_size, group_nat_size);
}
else
{
if (for_size < 0)
_gtk_cell_area_box_context_push_group_height (context, group->id, group_min_size, group_nat_size);
else
_gtk_cell_area_box_context_push_group_height_for_width (context, group->id, for_size,
group_min_size, group_nat_size);
}
}
*minimum_size = min_size;
*natural_size = nat_size;
/* Update rtl state for focus navigation to work */
priv->rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
}
static GtkRequestedSize *
get_group_sizes (GtkCellArea *area,
CellGroup *group,
GtkOrientation orientation,
GtkWidget *widget,
gint *n_sizes)
{
GtkRequestedSize *sizes;
GList *l;
gint i;
*n_sizes = count_visible_cells (group, NULL);
sizes = g_new (GtkRequestedSize, *n_sizes);
for (l = group->cells, i = 0; l; l = l->next)
{
CellInfo *info = l->data;
if (!gtk_cell_renderer_get_visible (info->renderer))
continue;
sizes[i].data = info;
gtk_cell_area_request_renderer (area, info->renderer,
orientation, widget, -1,
&sizes[i].minimum_size,
&sizes[i].natural_size);
i++;
}
return sizes;
}
static void
compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
CellGroup *group,
GtkWidget *widget,
gint for_size,
gint *minimum_size,
gint *natural_size)
{
GtkCellAreaBoxPrivate *priv = box->priv;
GtkCellArea *area = GTK_CELL_AREA (box);
/* Exception for single cell groups */
if (group->n_cells == 1)
{
CellInfo *info = group->cells->data;
gtk_cell_area_request_renderer (area, info->renderer,
OPPOSITE_ORIENTATION (priv->orientation),
widget, for_size, minimum_size, natural_size);
}
else
{
GtkRequestedSize *orientation_sizes;
CellInfo *info;
gint n_sizes, i;
gint avail_size = for_size;
gint extra_size, extra_extra;
gint min_size = 0, nat_size = 0;
orientation_sizes = get_group_sizes (area, group, priv->orientation, widget, &n_sizes);
/* First naturally allocate the cells in the group into the for_size */
avail_size -= (n_sizes - 1) * priv->spacing;
for (i = 0; i < n_sizes; i++)
avail_size -= orientation_sizes[i].minimum_size;
if (avail_size > 0)
avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
else
avail_size = 0;
/* Calculate/distribute expand for cells */
if (group->expand_cells > 0)
{
extra_size = avail_size / group->expand_cells;
extra_extra = avail_size % group->expand_cells;
}
else
extra_size = extra_extra = 0;
for (i = 0; i < n_sizes; i++)
{
gint cell_min, cell_nat;
info = orientation_sizes[i].data;
if (info->expand)
{
orientation_sizes[i].minimum_size += extra_size;
if (extra_extra)
{
orientation_sizes[i].minimum_size++;
extra_extra--;
}
}
gtk_cell_area_request_renderer (area, info->renderer,
OPPOSITE_ORIENTATION (priv->orientation),
widget,
orientation_sizes[i].minimum_size,
&cell_min, &cell_nat);
min_size = MAX (min_size, cell_min);
nat_size = MAX (nat_size, cell_nat);
}
*minimum_size = min_size;
*natural_size = nat_size;
g_free (orientation_sizes);
}
}
static void
compute_size_for_opposing_orientation (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context,
GtkWidget *widget,
gint for_size,
gint *minimum_size,
gint *natural_size)
{
GtkCellAreaBoxPrivate *priv = box->priv;
CellGroup *group;
GtkRequestedSize *orientation_sizes;
gint n_groups, n_expand_groups, i;
gint avail_size = for_size;
gint extra_size, extra_extra;
gint min_size = 0, nat_size = 0;
n_expand_groups = count_expand_groups (box);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
orientation_sizes = _gtk_cell_area_box_context_get_widths (context, &n_groups);
else
orientation_sizes = _gtk_cell_area_box_context_get_heights (context, &n_groups);
/* First start by naturally allocating space among groups of cells */
avail_size -= (n_groups - 1) * priv->spacing;
for (i = 0; i < n_groups; i++)
avail_size -= orientation_sizes[i].minimum_size;
if (avail_size > 0)
avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
else
avail_size = 0;
/* Calculate/distribute expand for groups */
if (n_expand_groups > 0)
{
extra_size = avail_size / n_expand_groups;
extra_extra = avail_size % n_expand_groups;
}
else
extra_size = extra_extra = 0;
/* Now we need to naturally allocate sizes for cells in each group
* and push the height-for-width for each group accordingly while
* accumulating the overall height-for-width for this row.
*/
for (i = 0; i < n_groups; i++)
{
gint group_min, group_nat;
gint group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
group = &g_array_index (priv->groups, CellGroup, group_idx);
if (group->expand_cells > 0)
{
orientation_sizes[i].minimum_size += extra_size;
if (extra_extra)
{
orientation_sizes[i].minimum_size++;
extra_extra--;
}
}
/* Now we have the allocation for the group,
* request its height-for-width
*/
compute_group_size_for_opposing_orientation (box, group, widget,
orientation_sizes[i].minimum_size,
&group_min, &group_nat);
min_size = MAX (min_size, group_min);
nat_size = MAX (nat_size, group_nat);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
_gtk_cell_area_box_context_push_group_height_for_width (context, group_idx, for_size,
group_min, group_nat);
}
else
{
_gtk_cell_area_box_context_push_group_width_for_height (context, group_idx, for_size,
group_min, group_nat);
}
}
*minimum_size = min_size;
*natural_size = nat_size;
g_free (orientation_sizes);
/* Update rtl state for focus navigation to work */
priv->rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
}
static void
gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint *minimum_width,
gint *natural_width)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxContext *box_context;
gint min_width, nat_width;
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
/* Compute the size of all renderers for current row data,
* bumping cell alignments in the context along the way
*/
compute_size (box, GTK_ORIENTATION_HORIZONTAL,
box_context, widget, -1, &min_width, &nat_width);
if (minimum_width)
*minimum_width = min_width;
if (natural_width)
*natural_width = nat_width;
}
static void
gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint *minimum_height,
gint *natural_height)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxContext *box_context;
gint min_height, nat_height;
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
/* Compute the size of all renderers for current row data,
* bumping cell alignments in the context along the way
*/
compute_size (box, GTK_ORIENTATION_VERTICAL,
box_context, widget, -1, &min_height, &nat_height);
if (minimum_height)
*minimum_height = min_height;
if (natural_height)
*natural_height = nat_height;
}
static void
gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint width,
gint *minimum_height,
gint *natural_height)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxContext *box_context;
GtkCellAreaBoxPrivate *priv;
gint min_height, nat_height;
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
priv = box->priv;
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
{
/* Add up vertical requests of height for width and push
* the overall cached sizes for alignments
*/
compute_size (box, priv->orientation, box_context, widget, width, &min_height, &nat_height);
}
else
{
/* Juice: virtually allocate cells into the for_width using the
* alignments and then return the overall height for that width,
* and cache it
*/
compute_size_for_opposing_orientation (box, box_context, widget, width, &min_height, &nat_height);
}
if (minimum_height)
*minimum_height = min_height;
if (natural_height)
*natural_height = nat_height;
}
static void
gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
GtkCellAreaContext *context,
GtkWidget *widget,
gint height,
gint *minimum_width,
gint *natural_width)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxContext *box_context;
GtkCellAreaBoxPrivate *priv;
gint min_width, nat_width;
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
priv = box->priv;
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
/* Add up horizontal requests of width for height and push
* the overall cached sizes for alignments
*/
compute_size (box, priv->orientation, box_context, widget, height, &min_width, &nat_width);
}
else
{
/* Juice: horizontally allocate cells into the for_height using the
* alignments and then return the overall width for that height,
* and cache it
*/
compute_size_for_opposing_orientation (box, box_context, widget, height, &min_width, &nat_width);
}
if (minimum_width)
*minimum_width = min_width;
if (natural_width)
*natural_width = nat_width;
}
enum {
FOCUS_NONE,
FOCUS_PREV,
FOCUS_NEXT,
FOCUS_LAST_CELL
};
static gboolean
gtk_cell_area_box_focus (GtkCellArea *area,
GtkDirectionType direction)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
GtkCellAreaBoxPrivate *priv = box->priv;
gint cycle = FOCUS_NONE;
gboolean cycled_focus = FALSE;
GtkCellRenderer *focus_cell;
focus_cell = gtk_cell_area_get_focus_cell (area);
/* Special case, when there is no activatable cell, focus
* is painted around the entire area... in this case we
* let focus leave the area directly.
*/
if (focus_cell && !gtk_cell_area_is_activatable (area))
{
gtk_cell_area_set_focus_cell (area, NULL);
return FALSE;
}
switch (direction)
{
case GTK_DIR_TAB_FORWARD:
cycle = priv->rtl ? FOCUS_PREV : FOCUS_NEXT;
break;
case GTK_DIR_TAB_BACKWARD:
cycle = priv->rtl ? FOCUS_NEXT : FOCUS_PREV;
break;
case GTK_DIR_UP:
if (priv->orientation == GTK_ORIENTATION_VERTICAL || !priv->last_focus_cell)
cycle = FOCUS_PREV;
else if (!focus_cell)
cycle = FOCUS_LAST_CELL;
break;
case GTK_DIR_DOWN:
if (priv->orientation == GTK_ORIENTATION_VERTICAL || !priv->last_focus_cell)
cycle = FOCUS_NEXT;
else if (!focus_cell)
cycle = FOCUS_LAST_CELL;
break;
case GTK_DIR_LEFT:
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !priv->last_focus_cell)
cycle = priv->rtl ? FOCUS_NEXT : FOCUS_PREV;
else if (!focus_cell)
cycle = FOCUS_LAST_CELL;
break;
case GTK_DIR_RIGHT:
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !priv->last_focus_cell)
cycle = priv->rtl ? FOCUS_PREV : FOCUS_NEXT;
else if (!focus_cell)
cycle = FOCUS_LAST_CELL;
break;
default:
break;
}
if (cycle == FOCUS_LAST_CELL)
{
gtk_cell_area_set_focus_cell (area, priv->last_focus_cell);
cycled_focus = TRUE;
}
else if (cycle != FOCUS_NONE)
{
gboolean found_cell = FALSE;
GList *list;
gint i;
/* If there is no focused cell, focus on the first (or last) one */
if (!focus_cell)
found_cell = TRUE;
for (i = (cycle == FOCUS_NEXT) ? 0 : priv->groups->len -1;
cycled_focus == FALSE && i >= 0 && i < priv->groups->len;
i = (cycle == FOCUS_NEXT) ? i + 1 : i - 1)
{
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
for (list = (cycle == FOCUS_NEXT) ? g_list_first (group->cells) : g_list_last (group->cells);
cycled_focus == FALSE && list; list = (cycle == FOCUS_NEXT) ? list->next : list->prev)
{
CellInfo *info = list->data;
if (info->renderer == focus_cell)
found_cell = TRUE;
else if (found_cell && /* Dont give focus to cells that are siblings to a focus cell */
gtk_cell_area_get_focus_from_sibling (area, info->renderer) == NULL)
{
gtk_cell_area_set_focus_cell (area, info->renderer);
cycled_focus = TRUE;
}
}
}
}
if (!cycled_focus)
gtk_cell_area_set_focus_cell (area, NULL);
return cycled_focus;
}
/*************************************************************
* GtkCellLayoutIface *
*************************************************************/
static void
gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
{
iface->pack_start = gtk_cell_area_box_layout_pack_start;
iface->pack_end = gtk_cell_area_box_layout_pack_end;
iface->reorder = gtk_cell_area_box_layout_reorder;
}
static void
gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
GtkCellRenderer *renderer,
gboolean expand)
{
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, FALSE, TRUE);
}
static void
gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
GtkCellRenderer *renderer,
gboolean expand)
{
gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, FALSE, TRUE);
}
static void
gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
GtkCellRenderer *renderer,
gint position)
{
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *node;
CellInfo *info;
node = g_list_find_custom (priv->cells, renderer,
(GCompareFunc)cell_info_find);
if (node)
{
info = node->data;
priv->cells = g_list_delete_link (priv->cells, node);
priv->cells = g_list_insert (priv->cells, info, position);
cell_groups_rebuild (box);
}
}
/*************************************************************
* Private interaction with GtkCellAreaBoxContext *
*************************************************************/
gboolean
_gtk_cell_area_box_group_visible (GtkCellAreaBox *box,
gint group_idx)
{
GtkCellAreaBoxPrivate *priv = box->priv;
CellGroup *group;
g_assert (group_idx >= 0 && group_idx < priv->groups->len);
group = &g_array_index (priv->groups, CellGroup, group_idx);
return group->visible;
}
/*************************************************************
* API *
*************************************************************/
/**
* gtk_cell_area_box_new:
*
* Creates a new #GtkCellAreaBox.
*
* Returns: a newly created #GtkCellAreaBox
*
* Since: 3.0
*/
GtkCellArea *
gtk_cell_area_box_new (void)
{
return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
}
/**
* gtk_cell_area_box_pack_start:
* @box: a #GtkCellAreaBox
* @renderer: the #GtkCellRenderer to add
* @expand: whether @renderer should receive extra space when the area receives
* more than its natural size
* @align: whether @renderer should be aligned in adjacent rows
* @fixed: whether @renderer should have the same size in all rows
*
* Adds @renderer to @box, packed with reference to the start of @box.
*
* The @renderer is packed after any other #GtkCellRenderer packed
* with reference to the start of @box.
*
* Since: 3.0
*/
void
gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
GtkCellRenderer *renderer,
gboolean expand,
gboolean align,
gboolean fixed)
{
GtkCellAreaBoxPrivate *priv;
CellInfo *info;
g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
priv = box->priv;
if (g_list_find_custom (priv->cells, renderer,
(GCompareFunc)cell_info_find))
{
g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
return;
}
info = cell_info_new (renderer, GTK_PACK_START, expand, align, fixed);
priv->cells = g_list_append (priv->cells, info);
cell_groups_rebuild (box);
}
/**
* gtk_cell_area_box_pack_end:
* @box: a #GtkCellAreaBox
* @renderer: the #GtkCellRenderer to add
* @expand: whether @renderer should receive extra space when the area receives
* more than its natural size
* @align: whether @renderer should be aligned in adjacent rows
* @fixed: whether @renderer should have the same size in all rows
*
* Adds @renderer to @box, packed with reference to the end of @box.
*
* The @renderer is packed after (away from end of) any other
* #GtkCellRenderer packed with reference to the end of @box.
*
* Since: 3.0
*/
void
gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
GtkCellRenderer *renderer,
gboolean expand,
gboolean align,
gboolean fixed)
{
GtkCellAreaBoxPrivate *priv;
CellInfo *info;
g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
priv = box->priv;
if (g_list_find_custom (priv->cells, renderer,
(GCompareFunc)cell_info_find))
{
g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
return;
}
info = cell_info_new (renderer, GTK_PACK_END, expand, align, fixed);
priv->cells = g_list_append (priv->cells, info);
cell_groups_rebuild (box);
}
/**
* gtk_cell_area_box_get_spacing:
* @box: a #GtkCellAreaBox
*
* Gets the spacing added between cell renderers.
*
* Returns: the space added between cell renderers in @box.
*
* Since: 3.0
*/
gint
gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
{
g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
return box->priv->spacing;
}
/**
* gtk_cell_area_box_set_spacing:
* @box: a #GtkCellAreaBox
* @spacing: the space to add between #GtkCellRenderers
*
* Sets the spacing to add between cell renderers in @box.
*
* Since: 3.0
*/
void
gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
gint spacing)
{
GtkCellAreaBoxPrivate *priv;
g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
priv = box->priv;
if (priv->spacing != spacing)
{
priv->spacing = spacing;
g_object_notify (G_OBJECT (box), "spacing");
/* Notify that size needs to be requested again */
reset_contexts (box);
}
}
|