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
|
{%MainUnit gtk2wscomctrls.pp}
{
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
type
TLVHack = class(TCustomListView)
end;
TLVItemHack = class(TListItem)
end;
////////////////////////////////////////
//// Event Code /////////////////////
////////////////////////////////////////
function IsOldGtk2: Boolean;
begin
Result := (gtk_major_version = 2) and (gtk_minor_version < 10);
end;
procedure Gtk2_PixBufFromBitmap(const BitImage:TBitmap; out pixbuf:PGdkPixbuf);
var
GDIObj: PGDIObject;
bitmap:PGdkBitmap;
Width, Height:gint;
pixmap: PGdkPixmap;
begin
GDIObj := {%H-}PGDIObject(BitImage.Handle);
case GDIObj^.GDIBitmapType of
gbBitmap:
begin
bitmap := GDIObj^.GDIBitmapObject;
gdk_drawable_get_size(bitmap, @Width, @Height);
pixbuf := CreatePixbufFromDrawable(bitmap, nil, False, 0, 0, 0, 0, Width, Height);
end;
gbPixmap:
begin
pixmap := GDIObj^.GDIPixmapObject.Image;
if pixmap <> nil then
begin
gdk_drawable_get_size(pixmap, @Width, @Height);
bitmap := CreateGdkMaskBitmap(BitImage.Handle, 0);
pixbuf := CreatePixbufFromImageAndMask(pixmap, 0, 0, Width, Height, nil, Bitmap);
end;
end;
gbPixbuf:
begin
pixbuf := gdk_pixbuf_copy(GDIObj^.GDIPixbufObject);
end;
end;
end;
procedure Gtk2_ItemCheckedChanged(renderer: PGtkCellRendererToggle; PathStr: Pgchar; WidgetInfo: PWidgetInfo);cdecl;
var
LV: TLVHack;
Index: Integer;
ListItem: TLVItemHack;
ARect: TGdkRectangle;
R: TRect;
x, y, cellw, cellh: gint;
begin
LV := TLVHack(WidgetInfo^.LCLObject);
Index := StrToInt(PathStr);
ListItem := TLVItemHack(LV.Items.Item[Index]);
if ListItem <> nil then
begin
ListItem.Checked := not ListItem.GetCheckedInternal;
if Assigned(LV.OnItemChecked) then
LV.OnItemChecked(TListView(WidgetInfo^.LCLObject), LV.Items.Item[Index]);
// we must update renderer row, otherwise visually it looks different
// if we change toggle state by keyboard (eg. pressing Space key)
R := ListItem.DisplayRect(drBounds);
ARect := GdkRectFromRect(R);
gtk_cell_renderer_get_size(PGtkCellRenderer(renderer),
WidgetInfo^.CoreWidget, @ARect, @x,@y, @cellw, @cellh);
with R do
gtk_widget_queue_draw_area(WidgetInfo^.CoreWidget, Left, Top, cellW, cellH);
end;
end;
procedure Gtk2_ItemFocusChanged(Widget: PGtkWidget; WidgetInfo: PWidgetInfo);cdecl;
var
msg: TLMNotify;
NM: TNMListView;
path: PGtkTreePath;
pstr: PChar;
column: PGtkTreeViewColumn;
cell: PGtkCellRenderer;
begin
// DebugLn('Gtk2_ItemFocusChanged');
// the defocus of the oldrow isn't send
if GTK_IS_TREE_VIEW(Widget) then begin
path:=nil;
column:=nil;
gtk_tree_view_get_cursor(PGtkTreeView(Widget), path, column);
end
else
if GTK_IS_ICON_VIEW(Widget) then begin
path:=nil;
cell:=nil;
gtk_icon_view_get_cursor(PGtkIconView(Widget), path, cell);
end
else
path := nil;
if path = nil then
Exit;
gtk_tree_path_free(path);
msg.Msg := CN_NOTIFY;
FillChar(NM{%H-}, SizeOf(NM), 0);
NM.hdr.hwndfrom := {%H-}PtrUInt(WidgetInfo^.CoreWidget);
NM.hdr.code := LVN_ITEMCHANGED;
pstr:=gtk_tree_path_to_string(path);
NM.iItem := StrToInt(pstr);
g_free(pstr);
NM.iSubItem := 0;
NM.uNewState := LVIS_FOCUSED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
DeliverMessage(WidgetInfo^.LCLObject, msg);
end;
procedure Gtk2_ItemDeleted({%H-}model: PGtkTreeModel; path: PGtkTreePath; WidgetInfo: PWidgetInfo); cdecl;
var
msg: TLMNotify;
NM: TNMListView;
pstr:PChar;
begin
//DebugLn('Gtk2_ItemDeleted');
msg.Msg := CN_NOTIFY;
FillChar(NM{%H-}, SizeOf(NM), 0);
NM.hdr.hwndfrom := {%H-}PtrUInt(WidgetInfo^.CoreWidget);
NM.hdr.code := LVN_DELETEITEM;
pstr := gtk_tree_path_to_string(path);
NM.iItem := StrToInt(pstr);
g_free(pstr);
msg.NMHdr := @NM.hdr;
DeliverMessage(WidgetInfo^.LCLObject, msg);
end;
procedure Gtk2_ItemInserted({%H-}model: PGtkTreeModel; path: PGtkTreePAth; {%H-}Iter: PGtkTreeIter; WidgetInfo: PWidgetInfo); cdecl;
var
msg: TLMNotify;
NM: TNMListView;
begin
//DebugLn('Gtk2_ItemInserted');
msg.Msg := CN_NOTIFY;
FillChar(NM{%H-}, SizeOf(NM), 0);
NM.hdr.hwndfrom := {%H-}PtrUInt(WidgetInfo^.CoreWidget);
NM.hdr.code := LVN_INSERTITEM;
NM.iItem := gtk_tree_path_get_indices(path)^;
msg.NMHdr := @NM.hdr;
DeliverMessage(WidgetInfo^.LCLObject, msg);
end;
//This is only for when the tree view sorts itself. Not needed since the LCL does the sorting.
//procedure Gtk2_ItemMoved(model: PGtkTreeModel; path: PGtkTreePAth; Iter: PGtkTreeIter; WidgetInfo: PWidgetInfo); cdecl;
//begin
//end;
procedure Gtk2_ItemChanged({%H-}model: PGtkTreeModel; {%H-}path: PGtkTreePAth; {%H-}Iter: PGtkTreeIter; {%H-}WidgetInfo: PWidgetInfo); cdecl;
begin
// OnChange Occurs immediately after an item in the list changes.
// The Item parameter is the list item that just changed. The Change parameter
// indicates the type of change that just occurred. Change is ctText if the
// Caption property of the item changed. Change is ctImage if the ImageIndex
// property of the item changed or the appropriate image list changed in the
// list view. Change is ctState if the Cut, Focused, or Selected property of
// the item changed.
// DebugLn('Gtk2_ItemChanged');
end;
procedure Gtk2_ColumnClicked(column: PGtkTreeViewColumn; WidgetInfo: PWidgetInfo); cdecl;
var
AColumn: TListColumn;
msg: TLMNotify;
NM: TNMListView;
begin
AColumn := TListColumn(g_object_get_data(G_OBJECT(column), 'TListColumn'));
msg.Msg := CN_NOTIFY;
FillChar(NM{%H-}, SizeOf(NM), 0);
NM.hdr.hwndfrom := {%H-}PtrUInt(WidgetInfo^.CoreWidget);
NM.hdr.code := LVN_COLUMNCLICK;
NM.iItem := -1;
NM.iSubItem := AColumn.Index;
msg.NMHdr := @NM.hdr;
DeliverMessage(WidgetInfo^.LCLObject, msg);
end;
procedure BroadcastListSelection(Target : Pointer; AHandle : HWND; AIndex : Integer;
AState : Boolean);
var
msg: TLMNotify;
NM: TNMListView;
begin
msg.Msg := CN_NOTIFY;
FillChar(NM{%H-}, SizeOf(NM), 0);
NM.hdr.hwndfrom := AHandle;
NM.hdr.code := LVN_ITEMCHANGED;
NM.iItem := AIndex;
NM.iSubItem := 0;
if AState then
NM.uOldState := LVIS_SELECTED
else
NM.uNewState := LVIS_SELECTED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
if g_object_get_data({%H-}PGObject(TWinControl(Target).Handle),'lcl_gtkwidget_in_update') = nil then
begin
DeliverMessage(Target, msg);
if TLVHack(Target).Selected = TLVHack(Target).Items[AIndex] then
begin
NM.uOldState := 0;
NM.uNewState := LVIS_FOCUSED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
DeliverMessage(Target, msg);
end else
if TLVHack(Target).Selected = nil then
begin
NM.uOldState := LVIS_FOCUSED;
NM.uNewState := 0;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
DeliverMessage(Target, msg);
end;
end;
end;
procedure ChangeItemCache(const AWidgets: PTVWidgets; const AItem: Integer; const AState: TTVItemState);
begin
if Length(AWidgets^.ItemCache) <= AItem then
SetLength(AWidgets^.ItemCache, AItem + TVItemCachePart);
if AWidgets^.ItemCacheCount <= AItem then
AWidgets^.ItemCacheCount := AItem + 1;
AWidgets^.ItemCache[AItem] := AState;
end;
procedure BroadcastItemCache(const AWidgets: PTVWidgets; const AWidgetInfo: PWidgetInfo);
var
i: Integer;
begin
for i := 0 to AWidgets^.ItemCacheCount -1 do
if AWidgets^.ItemCache[i] = tvisSelected then
BroadcastListSelection(AWidgetInfo^.LCLObject, {%H-}PtrUInt(AWidgets^.MainView),
i, True);
for i := 0 to AWidgets^.ItemCacheCount -1 do
if AWidgets^.ItemCache[i] = tvisUnselected then
BroadcastListSelection(AWidgetInfo^.LCLObject, {%H-}PtrUInt(AWidgets^.MainView),
i, False);
if Length(AWidgets^.ItemCache) > TVItemCachePart then
SetLength(AWidgets^.ItemCache, TVItemCachePart);
FillByte(AWidgets^.ItemCache[0], Length(AWidgets^.ItemCache), Ord(tvisUndefined));
AWidgets^.ItemCacheCount := 0;
end;
procedure Gtk2_ItemSelectionChanged(selection: PGtkTreeSelection; WidgetInfo: PWidgetInfo); cdecl;
var
Widgets: PTVWidgets;
AIndex: String;
i: Integer;
Indices: Integer;
ListIndex: Integer;
List: PgList;
Path: PGtkTreePath;
begin
// DebugLn('Gtk2_ItemSelectionChanged');
Widgets := PTVWidgets(WidgetInfo^.UserData);
if Widgets = nil then
Exit;
if wwiInvalidEvent in Widgets^.WidgetInfo^.Flags then
exit;
if Length(Widgets^.ItemCache)=0 then
begin
// debugln(' Gtk2_ItemSelectionChanged ItemCache=nil ',tComponent(widgetInfo^.lclObject).name);
if IsOldGtk2 and (Widgets <> nil) then
begin
// debugLn('ItemsCache is valid ! count ',dbgs(Widgets^.ItemCache.Count));
List := gtk_tree_selection_get_selected_rows(Selection, nil);
if (List <> nil) then
begin
if Assigned(Widgets^.OldTreeSelection) then
begin
// we must iterate because of multiselections
for i := 0 to g_list_length(Widgets^.OldTreeSelection) - 1 do
begin
Path := g_list_nth_data(Widgets^.OldTreeSelection, i);
if Path <> nil then
begin
Indices := gtk_tree_path_get_indices(Path)^;
ChangeItemCache(Widgets, Indices, tvisSelected);
end;
end;
g_list_free(Widgets^.OldTreeSelection);
Widgets^.OldTreeSelection := g_list_alloc;
// we must iterate because of multiselections
for i := 0 to g_list_length(List) - 1 do
g_list_append(Widgets^.OldTreeSelection, g_list_nth_data(List, i));
end;
// now compare new selection (add or set as selected)
for i := 0 to g_list_length(List) - 1 do
begin
Path := g_list_nth_data(List, i);
if Path <> nil then
begin
Indices := gtk_tree_path_get_indices(Path)^;
ChangeItemCache(Widgets, Indices, tvisUnselected);
end;
end;
g_list_free(List);
end else
begin
// complete selection is clear !
if Assigned(Widgets^.OldTreeSelection) then
begin
for i := 0 to g_list_length(Widgets^.OldTreeSelection) - 1 do
begin
Path := g_list_nth_data(Widgets^.OldTreeSelection, i);
if Path <> nil then
begin
Indices := gtk_tree_path_get_indices(Path)^;
ChangeItemCache(Widgets, Indices, tvisSelected);
end;
end;
g_list_free(Widgets^.OldTreeSelection);
Widgets^.OldTreeSelection := g_list_alloc;
end;
end;
end else
Exit;
end;
// DebugLn('Gtk2_ItemSelectionChanged Trigger OnSelectItem ? ', dbgs(not (wwiInvalidEvent in Widgets^.WidgetInfo^.Flags)));
// LCL sent selection !
BroadcastItemCache(Widgets,WidgetInfo);
end;
procedure Gtk2_IconViewSelectionChanged(AIconView: PGtkIconView; WidgetInfo: PWidgetInfo); cdecl;
var
Widgets: PTVWidgets;
AIndex: String;
i: Integer;
List: PGList;
Path: PGtkTreePath;
pstr: PChar;
Indices: integer;
begin
Widgets := PTVWidgets(WidgetInfo^.UserData);
List := gtk_icon_view_get_selected_items(AIconView);
if (List <> nil) then
begin
Path := PGtkTreePath(g_list_first(List)^.data);
Indices := gtk_tree_path_get_indices(path)^;
ChangeItemCache(Widgets, Indices, tvisUnselected);
g_list_free(List);
end else
exit;
// LCL already sent selection !
if wwiInvalidEvent in Widgets^.WidgetInfo^.Flags then
exit;
BroadcastItemCache(Widgets,WidgetInfo);
end;
function Gtk2WSLV_ItemSelected({%H-}selection: PGtkTreeSelection; {%H-}model: PGtkTreeModel;
path: PGtkTreePath; path_is_currently_selected: GBoolean; WidgetInfo: PWidgetInfo): GBoolean; cdecl;
var
Widgets: PTVWidgets;
Indices: integer;
begin
// DebugLn('Gtk2_ItemSelected ');
// this function is called *before* the item is selected
// The result should be True to allow the Item to change selection
Result := True;
Widgets := PTVWidgets(WidgetInfo^.UserData);
if wwiInvalidEvent in Widgets^.WidgetInfo^.Flags then
exit;
if Widgets <> nil then
begin
Indices := gtk_tree_path_get_indices(path)^;
if path_is_currently_selected then
ChangeItemCache(Widgets, Indices, tvisSelected)
else
ChangeItemCache(Widgets, Indices, tvisUnselected);
end;
end;
procedure Gtk2WSLV_ListViewGetCheckedDataFunc({%H-}tree_column: PGtkTreeViewColumn;
cell: PGtkCellRenderer; tree_model: PGtkTreeModel; iter: PGtkTreeIter; WidgetInfo: PWidgetInfo); cdecl;
var
APath: PGtkTreePath;
ListItem: TLVItemHack;
begin
gtk_tree_model_get(tree_model, iter, [0, @ListItem, -1]);
if (ListItem = nil) and TCustomListView(WidgetInfo^.LCLObject).OwnerData then
begin
APath := gtk_tree_model_get_path(tree_model,iter);
ListItem := TLVItemHack(TCustomListView(WidgetInfo^.LCLObject).Items[gtk_tree_path_get_indices(APath)^]);
gtk_tree_path_free(APath);
end;
if ListItem = nil then
Exit;
gtk_cell_renderer_toggle_set_active(PGtkCellRendererToggle(cell), ListItem.GetCheckedInternal);
end;
procedure Gtk2WSLV_ListViewGetPixbufDataFuncForColumn(tree_column: PGtkTreeViewColumn;
cell: PGtkCellRenderer; tree_model: PGtkTreeModel; iter: PGtkTreeIter; WidgetInfo: PWidgetInfo); cdecl;
var
ListItem: TListItem;
Images: TList;
Widgets: PTVWidgets;
ListColumn: TListColumn;
ImageIndex: Integer;
ColumnIndex: Integer;
APath: PGtkTreePath;
ImageList: TCustomImageList;
Bmp: TBitmap;
pixbuf: PGdkPixbuf;
PixbufValue: TGValue;
begin
PixbufValue:=Default(TGValue);
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
g_value_unset(@PixbufValue);
Widgets := PTVWidgets(WidgetInfo^.UserData);
gtk_tree_model_get(tree_model, iter, [0, @ListItem, -1]);
ListColumn := TListColumn(g_object_get_data(G_OBJECT(tree_column), 'TListColumn'));
if ListColumn = nil then
Exit;
ColumnIndex := ListColumn.Index;
ImageList := nil;
Images := Widgets^.Images;
if TCustomListView(WidgetInfo^.LCLObject).OwnerData then
ImageList := TLVHack(WidgetInfo^.LCLObject).SmallImages;
if (Images = nil) and (ImageList = nil) then
begin
Exit;
end;
ImageIndex := -1;
if (ListItem = nil) and TCustomListView(WidgetInfo^.LCLObject).OwnerData then
begin
APath := gtk_tree_model_get_path(tree_model,iter);
ListItem := TCustomListView(WidgetInfo^.LCLObject).Items[gtk_tree_path_get_indices(APath)^];
gtk_tree_path_free(APath);
end;
if ListItem = nil then
Exit;
if ColumnIndex = 0 then
ImageIndex := ListItem.ImageIndex
else
if ColumnIndex -1 <= ListItem.SubItems.Count-1 then
ImageIndex := ListItem.SubItemImages[ColumnIndex-1];
if (ImageList <> nil) and
(ImageIndex > -1) and (ImageIndex <= ImageList.Count-1) then
begin
Bmp := TBitmap.create;
try
pixbuf := nil;
ImageList.GetBitmap(ImageIndex, Bmp);
Gtk2_PixBufFromBitmap(Bmp,pixbuf);
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
g_value_set_object(@PixbufValue, pixbuf);
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
g_value_unset(@PixbufValue);
finally
Bmp.Free;
end;
end else
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
if (ImageIndex > -1) and (ImageIndex <= Images.Count-1) and (Images.Items[ImageIndex] <> nil) then
g_value_set_object(@PixbufValue, PGdkPixbuf(Images.Items[ImageIndex]));
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
g_value_unset(@PixbufValue);
end;
procedure Gtk2WSLV_ListViewGetPixbufDataFuncForIconView({%H-}cell_layout:PGtkCellLayout;
cell: PGtkCellRenderer; tree_model: PGtkTreeModel; iter: PGtkTreeIter; WidgetInfo: PWidgetInfo); cdecl;
var
ListItem: TListItem;
Images: TList;
Widgets: PTVWidgets;
ImageIndex: Integer;
APath: PGtkTreePath;
PixbufValue: TGValue;
begin
PixbufValue:=Default(TGValue);
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
g_object_set_property(G_OBJECT(cell), 'pixbuf', @PixbufValue);
g_value_unset(@PixbufValue);
Widgets := PTVWidgets(WidgetInfo^.UserData);
gtk_tree_model_get(tree_model, iter, [0, @ListItem, -1]);
Images := Widgets^.Images;
if Images = nil then
Exit;
ImageIndex := -1;
if (ListItem = nil) and TCustomListView(WidgetInfo^.LCLObject).OwnerData then
begin
APath := gtk_tree_model_get_path(tree_model,iter);
ListItem := TCustomListView(WidgetInfo^.LCLObject).Items[gtk_tree_path_get_indices(APath)^];
gtk_tree_path_free(APath);
end;
if ListItem = nil then
Exit;
ImageIndex := ListItem.ImageIndex;
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
if (ImageIndex > -1) and (ImageIndex <= Images.Count-1) then
g_value_set_object(@PixbufValue, PGdkPixbuf(Images.Items[ImageIndex]));
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
g_value_unset(@PixbufValue);
end;
{ TGtk2WSCustomListView }
class procedure TGtk2WSCustomListView.SetPropertyInternal(const ALV: TCustomListView;
const Widgets: PTVWidgets; const AProp: TListViewProperty;
const AIsSet: Boolean);
const
BoolToSelectionMode: array[Boolean] of TGtkSelectionMode = (
GTK_SELECTION_SINGLE,
GTK_SELECTION_MULTIPLE
);
begin
with Widgets^ do begin
case AProp of
lvpAutoArrange: begin
// TODO: implement ??
end;
lvpCheckboxes:
begin
if TLVHack(ALV).ViewStyle in [vsReport,vsList] then
AddRemoveCheckboxRenderer(ALV, GetWidgetInfo(Widgets^.MainView), AIsSet);
end;
lvpColumnClick: begin
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
gtk_tree_view_set_headers_clickable(PGtkTreeView(MainView), AIsSet);
end;
lvpFlatScrollBars: begin
// TODO: implement ??
end;
lvpFullDrag: begin
// TODO: implement ??
end;
lvpGridLines: begin
// TODO: better implementation
// maybe possible with some cellwidget hacking
// this create rows with alternating colors
if GTK_IS_TREE_VIEW(MainView) then
begin
if gtk_tree_view_set_grid_lines <> nil then
begin
if AIsSet then
gtk_tree_view_set_grid_lines(PGtkTreeView(MainView), GTK_TREE_VIEW_GRID_LINES_BOTH)
else
gtk_tree_view_set_grid_lines(PGtkTreeView(MainView), GTK_TREE_VIEW_GRID_LINES_NONE);
end else
gtk_tree_view_set_rules_hint(PGtkTreeView(MainView), AIsSet);
end;
end;
lvpHideSelection: begin
// TODO: implement
// should be possible with some focus in/out events
end;
lvpHotTrack: begin
// TODO: implement
// should be possible with some mouse tracking
end;
lvpMultiSelect: begin
if GTK_IS_TREE_VIEW(MainView) then
gtk_tree_selection_set_mode(TreeSelection, BoolToSelectionMode[AIsSet])
else
if GTK_IS_ICON_VIEW(MainView) then
gtk_icon_view_set_selection_mode(PGtkIconView(MainView), BoolToSelectionMode[AIsSet]);
end;
lvpOwnerDraw:
begin
// It must send CN_DRAWITEM with ItemID and proper rect of item
// then LCL does all other stuff. Note that OwnerDraw should work only
// in case of vsReport, according to embarcadero docs.
// http://docwiki.embarcadero.com/Libraries/XE4/en/Vcl.ComCtrls.TCustomListView.OnDrawItem
// NOTE: this is automatically handled by cell renderer (Gtk2CellRenderer).
end;
lvpReadOnly: begin
// TODO: implement inline editor ?
end;
lvpRowSelect: begin
// TODO: implement ???
// how to do cell select
end;
lvpShowColumnHeaders: begin
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (MainView), AIsSet);
end;
lvpShowWorkAreas: begin
// TODO: implement ???
end;
lvpWrapText: begin
// TODO: implement ???
end;
end;
end;
end;
class procedure TGtk2WSCustomListView.SetNeedDefaultColumn(const ALV: TCustomListView; const AValue: Boolean);
var
Widgets: PTVWidgets;
WidgetInfo: PWidgetInfo;
GtkColumn: PGtkTreeViewColumn;
pixrenderer,
textrenderer: PGtkCellRenderer;
begin
if not WSCheckHandleAllocated(ALV, 'SetNeedDefaultColumn')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
WidgetInfo := GetWidgetInfo({%H-}PGtkWidget(ALV.Handle));
GtkColumn := g_object_get_data(G_OBJECT(Widgets^.MainView), 'LCL_DEFAULT_COLUMN');
if AValue then
begin
if GtkColumn = nil then
begin
GtkColumn := gtk_tree_view_column_new();
gtk_widget_unset_flags(PGtkWidget(GtkColumn), GTK_CAN_FOCUS);
// add renderers
pixrenderer := gtk_cell_renderer_pixbuf_new();
textrenderer := LCLIntfCellRenderer_New;
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
begin
gtk_tree_view_column_pack_start(GtkColumn, pixrenderer, FALSE);
//gtk_tree_view_column_set_attributes(GtkColumn, pixrenderer,['pixbuf', 0, nil]);
gtk_tree_view_column_pack_start(GtkColumn, textrenderer, True);
//gtk_tree_view_column_set_attributes(GtkColumn, textrenderer, ['text',0, nil]);
gtk_tree_view_column_set_cell_data_func(GtkColumn, pixrenderer, TGtkTreeCellDataFunc(@Gtk2WSLV_ListViewGetPixbufDataFuncForColumn), WidgetInfo, nil);
gtk_tree_view_column_set_cell_data_func(GtkColumn, textrenderer, TGtkTreeCellDataFunc(@LCLIntfCellRenderer_CellDataFunc), WidgetInfo, nil);
// insert column
gtk_tree_view_insert_column(GTK_TREE_VIEW(Widgets^.MainView), GtkColumn, 0);
end
else
if GTK_IS_ICON_VIEW(Widgets^.MainView) then
begin
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(Widgets^.MainView), pixrenderer, False);
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(Widgets^.MainView), textrenderer, True);
gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(Widgets^.MainView), pixrenderer, TGtkCellLayoutDataFunc(@Gtk2WSLV_ListViewGetPixbufDataFuncForIconView), WidgetInfo, nil);
gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(Widgets^.MainView), textrenderer, TGtkCellLayoutDataFunc(@LCLIntfCellRenderer_CellDataFunc), WidgetInfo, nil);
end;
g_object_set_data(G_OBJECT(Widgets^.MainView), 'LCL_DEFAULT_COLUMN', GtkColumn);
end;
end
else begin // No Column Needed
if GtkColumn <> nil then
begin
if GTK_IS_TREE_VIEW(Widgets^.MainView) and GTK_IS_TREE_VIEW_COLUMN(GtkColumn) then
gtk_tree_view_remove_column(PGtkTreeView(Widgets^.MainView), GtkColumn)
else
if GTK_IS_TREE_VIEW_COLUMN(GtkColumn) and G_IS_OBJECT(GtkColumn) then
g_object_unref(GtkColumn);
g_object_set_data(G_OBJECT(Widgets^.MainView), 'LCL_DEFAULT_COLUMN', nil);
end;
end;
end;
class procedure TGtk2WSCustomListView.AddRemoveCheckboxRenderer(
const ALV: TCustomListView; const WidgetInfo: PWidgetInfo; const Add: Boolean);
var
togglerenderer,
pixrenderer,
textrenderer: PGtkCellRenderer;
column: PGtkTreeViewColumn;
renderers: PGList;
begin
column := gtk_tree_view_get_column(PGtkTreeView(WidgetInfo^.CoreWidget), 0);
if column = nil then
Exit;
renderers := gtk_tree_view_column_get_cell_renderers(column);
textrenderer := PGtkCellRenderer(g_list_last(renderers)^.data);
pixrenderer := PGtkCellRenderer(g_list_last(renderers)^.prev^.data);
g_list_free(renderers);
g_object_ref(G_OBJECT(pixrenderer));
g_object_ref(G_OBJECT(textrenderer));
if Add then
begin
gtk_cell_layout_clear(GTK_CELL_LAYOUT(column));
togglerenderer := gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(column, togglerenderer, FALSE);
gtk_tree_view_column_pack_start(column, pixrenderer, FALSE);
gtk_tree_view_column_pack_start(column, textrenderer, True);
gtk_tree_view_column_set_cell_data_func(column, togglerenderer, TGtkTreeCellDataFunc(@Gtk2WSLV_ListViewGetCheckedDataFunc), WidgetInfo, nil);
gtk_tree_view_column_set_cell_data_func(column, pixrenderer, TGtkTreeCellDataFunc(@Gtk2WSLV_ListViewGetPixbufDataFuncForColumn), WidgetInfo, nil);
gtk_tree_view_column_set_cell_data_func(column, textrenderer, TGtkTreeCellDataFunc(@LCLIntfCellRenderer_CellDataFunc), WidgetInfo, nil);
// connect toggled signal
g_signal_connect(togglerenderer, 'toggled', TGTKSignalFunc(@Gtk2_ItemCheckedChanged), GetWidgetInfo({%H-}PGtkWidget(ALV.Handle)));
end
else
begin
gtk_cell_layout_clear(GTK_CELL_LAYOUT(column));
gtk_tree_view_column_pack_start(column, pixrenderer, FALSE);
gtk_tree_view_column_pack_start(column, textrenderer, True);
gtk_tree_view_column_set_cell_data_func(column, pixrenderer, TGtkTreeCellDataFunc(@Gtk2WSLV_ListViewGetPixbufDataFuncForColumn), WidgetInfo, nil);
gtk_tree_view_column_set_cell_data_func(column, textrenderer, TGtkTreeCellDataFunc(@LCLIntfCellRenderer_CellDataFunc), WidgetInfo, nil);
end;
if G_IS_OBJECT(pixrenderer) then
g_object_unref(G_OBJECT(pixrenderer));
if G_IS_OBJECT(textrenderer) then
g_object_unref(G_OBJECT(textrenderer));
end;
class function TGtk2WSCustomListView.GetViewModel(const AView: PGtkWidget): PGtkTreeModel;
begin
if GTK_IS_TREE_VIEW(AView) then
Result := gtk_tree_view_get_model(PGtkTreeView(AView))
else
if GTK_IS_ICON_VIEW(AView) then
Result := gtk_icon_view_get_model(PGtkIconView(AView))
else
Result := nil;
end;
class procedure TGtk2WSCustomListView.SetListCallbacks(const AScrollWidget: PGtkWidget;
const Widgets: PTVWidgets; const AWidgetInfo: PWidgetInfo);
begin
TGtk2WSBaseScrollingWinControl.SetCallbacks(AScrollWidget, AWidgetInfo);
TGtk2WSWinControl.SetCallbacks(PGtkObject(Widgets^.MainView), TComponent(AWidgetInfo^.LCLObject));
// the callbacks for OnColumnClick are set when the column is created in ColumnInsert
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
begin
if IsOldGtk2 then
// bug in 2.8, issue #19820
else
gtk_tree_selection_set_select_function(Widgets^.TreeSelection,TGtkTreeSelectionFunc(@Gtk2WSLV_ItemSelected), gpointer(AWidgetInfo),nil);
SignalConnect(PGtkWidget(Widgets^.TreeSelection), 'changed', @Gtk2_ItemSelectionChanged, AWidgetInfo);
SignalConnect(PGtkWidget(Widgets^.MainView), 'toggle-cursor-row', @Gtk2_ItemFocusChanged, AWidgetInfo);
end
else
if GTK_IS_ICON_VIEW(Widgets^.MainView) then
begin
SignalConnect(Widgets^.MainView, 'selection-changed', @Gtk2_IconViewSelectionChanged, AWidgetInfo);
SignalConnect(Widgets^.MainView, 'toggle-cursor-item', @Gtk2_ItemFocusChanged, AWidgetInfo);
end;
SignalConnect(PGtkWidget(Widgets^.TreeModel), 'row-changed', @Gtk2_ItemChanged, AWidgetInfo);
SignalConnect(PGtkWidget(Widgets^.TreeModel), 'row-inserted', @Gtk2_ItemInserted, AWidgetInfo);
SignalConnect(PGtkWidget(Widgets^.TreeModel), 'row-deleted', @Gtk2_ItemDeleted, AWidgetInfo);
end;
class procedure TGtk2WSCustomListView.ColumnDelete(const ALV: TCustomListView;
const AIndex: Integer);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnDelete')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if (GtkColumn<>nil) and GTK_IS_TREE_VIEW_COLUMN(GtkColumn) then
gtk_tree_view_remove_column(PGtkTreeView(Widgets^.MainView), GtkColumn);
end;
class function TGtk2WSCustomListView.ColumnGetWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn): Integer;
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'ColumnGetWidth')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
begin
Result := gtk_tree_view_column_get_width(GtkColumn);
if Result = 0 then
Result := gtk_tree_view_column_get_fixed_width(GtkColumn);
end;
end;
class procedure TGtk2WSCustomListView.ColumnInsert(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn);
var
Widgets: PTVWidgets;
column: PGtkTreeViewColumn;
pixrenderer,
textrenderer: PGtkCellRenderer;
WidgetInfo: PWidgetInfo;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnInsert')
then Exit;
WidgetInfo := GetWidgetInfo({%H-}PGtkWidget(ALV.Handle));
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
column := gtk_tree_view_column_new();
gtk_widget_unset_flags(PGtkWidget(column), GTK_CAN_FOCUS);
// add renderers
pixrenderer := gtk_cell_renderer_pixbuf_new();
textrenderer := LCLIntfCellRenderer_New;//gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, pixrenderer, False);
//gtk_tree_view_column_set_attributes(column, pixrenderer,['pixbuf', RealIndex, nil]);
gtk_tree_view_column_pack_start(column, textrenderer, True);
//gtk_tree_view_column_set_attributes(column, textrenderer, ['text', 0, nil]);
gtk_tree_view_column_set_cell_data_func(column, pixrenderer, TGtkTreeCellDataFunc(@Gtk2WSLV_ListViewGetPixbufDataFuncForColumn), WidgetInfo, nil);
gtk_tree_view_column_set_cell_data_func(column, textrenderer, TGtkTreeCellDataFunc(@LCLIntfCellRenderer_CellDataFunc), WidgetInfo, nil);
//gtk_tree_view_column_set_cell_data_func(column, textrenderer, TGtkTreeCellDataFunc(@Gtk2WSLV_ListViewGetTextDataFunc), WidgetInfo, nil);
//store the TColumn in the column data for callbacks
g_object_set_data(G_OBJECT(column), PChar('TListColumn'), gpointer(AColumn));
// set callback for OnClick
SignalConnect(PGtkWidget(column), 'clicked', @Gtk2_ColumnClicked, Widgets^.WidgetInfo);
// insert column
gtk_tree_view_insert_column(GTK_TREE_VIEW(Widgets^.MainView), Column, AIndex);
//set clickable
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
// do not set these here, it will be set by the lcl
(*
// set title
gtk_tree_view_column_set_title(column, PChar(AColumn.Caption));
//set width
gtk_tree_view_column_set_fixed_width(Column, AColumn.Width);
// set Visible
gtk_tree_view_column_set_visible(Column, AColumn.Visible);
// set MinWidth
if AColumn.MinWidth > 0 then
gtk_tree_view_column_set_min_width(Column, AColumn.MinWidth);
// set MaxWidth
if AColumn.MaxWidth > 0 then
gtk_tree_view_column_set_max_width(Column, AColumn.MaxWidth);
//set resizable
gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN (column), True);
*)
end;
class procedure TGtk2WSCustomListView.ColumnMove(const ALV: TCustomListView;
const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
var
Widgets: PTVWidgets;
Column: PGtkTreeViewColumn;
PrevColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnMove') then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then Exit;
Column := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AOldIndex);
if Column <> nil then
begin
if ANewIndex = 0 then
PrevColumn := nil
else
PrevColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), ANewIndex);
gtk_tree_view_move_column_after(PGtkTreeView(Widgets^.MainView), Column, PrevColumn);
end;
end;
class procedure TGtk2WSCustomListView.ColumnSetAlignment(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn;
const AAlignment: TAlignment);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
Alignment: gfloat;
Value: TGValue;
renderers: PGList;
textrenderer: PGtkCellRenderer;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAlignment')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
begin
renderers := gtk_tree_view_column_get_cell_renderers(GtkColumn);
textrenderer := PGtkCellRenderer(g_list_last(renderers)^.data);
g_list_free(renderers);
Alignment := AlignToGtkAlign(AAlignment);
Value.g_type := G_TYPE_FLOAT;
Value.data[0].v_float:= Alignment;
g_object_set_property(G_OBJECT(textrenderer), PChar('xalign'), @Value);
{now we call set alignment because it calls update over visible rows in col}
gtk_tree_view_column_set_alignment(GtkColumn, Alignment);
end;
end;
class procedure TGtk2WSCustomListView.ColumnSetAutoSize(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean);
const
SizingMap: array[Boolean] of TGtkTreeViewColumnSizing = (
GTK_TREE_VIEW_COLUMN_FIXED,
GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAutoSize')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
begin
gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(GtkColumn), True);
gtk_tree_view_column_set_sizing(GtkColumn, SizingMap[AAutoSize]);
end;
end;
class procedure TGtk2WSCustomListView.ColumnSetCaption(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
gtk_tree_view_column_set_title(GtkColumn, PChar(EscapeUnderscores(ACaption)));
end;
class procedure TGtk2WSCustomListView.ColumnSetImage(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer
);
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetImage')
then Exit;
// ToDo: TGtk2WSCustomListView.ColumnSetImage
//DebugLn('TODO: Gtk2. TGtk2WSCustomListView.ColumnSetImage');
end;
class procedure TGtk2WSCustomListView.ColumnSetMaxWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetMaxWidth')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
gtk_tree_view_column_set_max_width(GtkColumn, AMaxWidth - Ord(AMaxWidth=0));
end;
class procedure TGtk2WSCustomListView.ColumnSetMinWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetMinWidth')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
gtk_tree_view_column_set_min_width(GtkColumn, AMinWidth - Ord(AMinWidth=0));
end;
class procedure TGtk2WSCustomListView.ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetWidth')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
begin
GtkColumn^.width := 0;
gtk_tree_view_column_set_fixed_width(GtkColumn, AWidth + Ord(AWidth<1));
end;
end;
class procedure TGtk2WSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetVisible')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
with Widgets^ do
begin
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(MainView), AIndex);
if AVisible then
g_object_set_data(G_OBJECT(GtkColumn), PChar('Visible'), gpointer(ptrint(1)))
else
g_object_set_data(G_OBJECT(GtkColumn), PChar('Visible'), gpointer(ptrint(0)));
if TLVHack(ALV).ViewStyle = vsReport then begin
gtk_tree_view_column_set_visible(GtkColumn, AVisible);
end;
end;
end;
class procedure TGtk2WSCustomListView.ColumnSetSortIndicator(
const ALV: TCustomListView; const AIndex: Integer;
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
const
GtkOrder : array [ TSortIndicator] of TGtkSortType = (0, GTK_SORT_ASCENDING, GTK_SORT_DESCENDING);
var
Widgets: PTVWidgets;
GtkColumn: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
if GtkColumn <> nil then
begin
if ASortIndicator = siNone then
gtk_tree_view_column_set_sort_indicator(GtkColumn, false)
else
begin
gtk_tree_view_column_set_sort_indicator(GtkColumn, true);
gtk_tree_view_column_set_sort_order(GtkColumn, GtkOrder[ASortIndicator]);
end;
end;
end;
class procedure TGtk2WSCustomListView.ItemDelete(const ALV: TCustomListView;
const AIndex: Integer);
var
Widgets: PTVWidgets;
{$IFDEF USEORIGTREEMODEL}
Iter: TGtkTreeIter;
{$ENDIF}
begin
if not WSCheckHandleAllocated(ALV, 'ItemDelete')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do begin
{$IFDEF USEORIGTREEMODEL}
if gtk_tree_model_iter_nth_child(TreeModel, @Iter, nil, AIndex) then
begin
gtk_list_store_remove(TreeModel, @Iter);
end;
{$ELSE}
PLCLListViewModel(TreeModel)^.NotifyRowDeleted(AIndex);
{$ENDIF}
end;
end;
class function TGtk2WSCustomListView.ItemDisplayRect(const ALV: TCustomListView; const AIndex, ASubItem: Integer;
ACode: TDisplayCode): TRect;
var
Widgets: PTVWidgets;
ItemRect, IconRect: TGdkRectangle;
Column: PGtkTreeViewColumn;
Path: PGtkTreePath;
X, Y, L, T, W, H: GInt;
ARect: TGdkRectangle;
R: TRect;
ANewCell: PGtkCellRenderer;
ANewPath: PGtkTreePath;
APGList: PGList;
pixrenderer: PGtkCellRenderer;
AWidth: gint;
AHeight: gint;
begin
Result := Rect(0, 0, 0, 0);
if not WSCheckHandleAllocated(ALV, 'ItemDisplayRect') then
Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if gtk_widget_realized(MainView) = False then
exit;
Path := gtk_tree_path_new_from_indices(AIndex, -1);
try
if GTK_IS_TREE_VIEW(MainView) then
begin
Column := gtk_tree_view_get_column(PGtkTreeView(MainView), ASubItem);
gtk_tree_view_get_cell_area(PGtkTreeView(MainView), Path, Column, @ItemRect);
if gtk_tree_view_get_headers_visible(PGtkTreeView(MainView)) then
begin
gtk_tree_view_column_cell_get_size(gtk_tree_view_get_column(PGtkTreeView(MainView), 0),
@ARect, @L, @T, @W, @H);
inc(ItemRect.y, H);
end;
if (ACode in [drIcon, drLabel]) and not TLVHack(ALV).OwnerDraw then
begin
IconRect := ItemRect;
APGList := gtk_tree_view_column_get_cell_renderers(gtk_tree_view_get_column(PGtkTreeView(MainView), 0));
pixrenderer := PGtkCellRenderer(g_list_last(APGList)^.prev^.data);
gtk_cell_renderer_get_fixed_size(pixrenderer, @AWidth, @AHeight);
if AWidth > 0 then
IconRect.Width := AWidth - 2;
if AHeight > 0 then
IconRect.Height := AHeight - 2;
g_list_free(APGList);
if ACode = drIcon then
ItemRect := IconRect
else
begin
ItemRect.x += AWidth + 2;
ItemRect.y += 2; // offset
ItemRect.Width -= AWidth + 2;
ItemRect.Height -= 2; // offset
end;
end;
end
else
if GTK_IS_ICON_VIEW(MainView) then
begin
ItemRect.x := 0;
ItemRect.y := 0;
ItemRect.width := gtk_icon_view_get_item_width(PGtkIconView(MainView));
ItemRect.height := 0;
if Path <> nil then
begin
ANewPath := nil;
ANewCell := nil;
R := ALV.ClientRect;
l := 0;
t := 0;
Result := Rect(0, 0, 0, 0);
while t < R.Bottom - 1 do
begin
l := 0;
while l < R.Right - 1 do
begin
if gtk_icon_view_get_item_at_pos(PGtkIconView(MainView), l, t, ANewPath, ANewCell) then
begin
if (ANewPath <> nil) and (gtk_tree_path_compare(Path, ANewPath) = 0) then
begin
gtk_cell_renderer_get_size(ANewCell, PGtkWidget(MainView), @ItemRect, @x,@y,@w,@h);
Result := Rect(l, t, w + l, h + t);
ItemRect := GdkRectFromRect(Result);
if ANewPath <> nil then
gtk_tree_path_free(ANewPath);
break;
end;
if ANewPath <> nil then
gtk_tree_path_free(ANewPath);
end;
inc(l, 1);
end;
inc(t, 1);
if not IsRectEmpty(Result) then
break;
end;
end;
end;
finally
gtk_tree_path_free(Path);
end;
Result := RectFromGdkRect(ItemRect);
end;
end;
class procedure TGtk2WSCustomListView.ItemExchange(const ALV: TCustomListView;
AItem: TListItem; const AIndex1, AIndex2: Integer);
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
ItemRect: TGdkRectangle;
begin
if not WSCheckHandleAllocated(ALV, 'ItemExchange') then
exit;
// gtk2 needs only update
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if GetViewModel(Widgets^.MainView) = nil then
exit;
if not gtk_widget_realized(Widgets^.MainView) then
exit;
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
begin
Path := gtk_tree_path_new_from_indices(AIndex1, -1);
gtk_tree_view_get_cell_area(PGtkTreeView(Widgets^.MainView), Path, nil, @ItemRect);
gtk_tree_path_free(Path);
if ItemRect.height = 0 then
begin
Path := gtk_tree_path_new_from_indices(AIndex2, -1);
gtk_tree_view_get_cell_area(PGtkTreeView(Widgets^.MainView), Path, nil, @ItemRect);
gtk_tree_path_free(Path);
end;
end else
ItemRect.height := 1; // force redraw
if ItemRect.height <> 0 then // item is visible
gtk_widget_queue_draw(Widgets^.MainView);
end;
class procedure TGtk2WSCustomListView.ItemMove(const ALV: TCustomListView;
AItem: TListItem; const AFromIndex, AToIndex: Integer);
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
ItemRect: TGdkRectangle;
begin
if not WSCheckHandleAllocated(ALV, 'ItemMove') then
exit;
// gtk2 needs only update
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if GetViewModel(Widgets^.MainView) = nil then
exit;
if not gtk_widget_realized(Widgets^.MainView) then
exit;
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
begin
Path := gtk_tree_path_new_from_indices(AFromIndex, -1);
gtk_tree_view_get_cell_area(PGtkTreeView(Widgets^.MainView), Path, nil, @ItemRect);
gtk_tree_path_free(Path);
if ItemRect.height = 0 then
begin
Path := gtk_tree_path_new_from_indices(AToIndex, -1);
gtk_tree_view_get_cell_area(PGtkTreeView(Widgets^.MainView), Path, nil, @ItemRect);
gtk_tree_path_free(Path);
end;
end else
ItemRect.height := 1; // force redraw
if ItemRect.height <> 0 then // item is visible
gtk_widget_queue_draw(Widgets^.MainView);
end;
class function TGtk2WSCustomListView.ItemGetChecked(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem): Boolean;
begin
Result := TLVItemHack(AItem).GetCheckedInternal;
end;
class function TGtk2WSCustomListView.ItemGetState(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const AState: TListItemState;
out AIsSet: Boolean): Boolean;
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
pstr: PChar;
Column: PGtkTreeViewColumn;
Cell: PGtkCellRenderer;
begin
Result := False;
if not WSCheckHandleAllocated(ALV, 'ItemGetState')
then Exit;
AIsSet := False;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if GetViewModel(MainView) = nil then
Exit; // we are in the midst of a begin update end update pair and the following will fail and cause gtk debug messages
case AState of
lisCut,
lisDropTarget:
begin
//TODO: do something with the rowcolor ?
end;
lisFocused:
begin
if GTK_IS_TREE_VIEW(MainView) then begin
Path:=nil;
Column:=nil;
gtk_tree_view_get_cursor(PGtkTreeView(MainView), Path, Column)
end
else
if GTK_IS_ICON_VIEW(MainView) then
gtk_icon_view_get_cursor(PGtkIconView(MainView), Path, Cell{%H-})
else
Path := nil;
if (Path<>nil) then
begin
pstr := gtk_tree_path_to_string(path);
AIsSet:=(StrToInt(pstr) = AIndex);
g_free(pstr);
end else
AIsSet:=false;
gtk_tree_path_free(Path);
Result := True;
end;
lisSelected:
begin
Path := gtk_tree_path_new_from_string(PChar(IntToStr(AIndex)));
if GTK_IS_TREE_VIEW(MainView) then
AIsSet := gtk_tree_selection_path_is_selected(TreeSelection, Path)
else
if GTK_IS_ICON_VIEW(MainView) then
AIsSet := gtk_icon_view_path_is_selected(PGtkIconView(MainView), Path)
else
AIsSet := False;
gtk_tree_path_free(Path);
Result := True;
end;
end;
end;
end;
class procedure TGtk2WSCustomListView.ItemInsert(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem);
var
Widgets: PTVWidgets;
{$IFDEF USEORIGTREEMODEL}
Iter: TGtkTreeIter;
Index: Integer;
{$ENDIF}
begin
if not WSCheckHandleAllocated(ALV, 'ItemInsert')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
{$IFDEF USEORIGTREEMODEL}
if AIndex = -1 then
Index := gtk_tree_model_iter_n_children(TreeModel, nil)
else
Index := AIndex;
gtk_list_store_insert_with_values(PGtkListStore(TreeModel), @Iter, Index, 0, Pointer(AItem), -1);
{$ELSE}
if not (lisfWSItemsCreated in ALV.Items.Flags) then
Exit;
PLCLListViewModel(TreeModel)^.NotifyRowInserted(AIndex);
{$ENDIF}
end;
end;
class procedure TGtk2WSCustomListView.ItemSetChecked(
const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem;
const AChecked: Boolean);
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetChecked')
then Exit;
// nothing needed here
end;
class procedure TGtk2WSCustomListView.ItemSetImage(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const ASubIndex,
AImageIndex: Integer);
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
ItemRect: TGdkRectangle;
BitImage: TBitmap;
pixbuf: PGDKPixBuf;
i, ImgListWidth: Integer;
ImgList: TCustomImageList;
ImgListRes: TCustomImageListResolution;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetImage')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if not gtk_widget_realized(MainView) then
begin
// DebugLn('WARNING: TGtk2WSCustomListView.ItemSetImage: MainView is not realized.');
Exit;
end;
Path := gtk_tree_path_new_from_indices(AIndex, -1);
if GTK_IS_TREE_VIEW(MainView) then
gtk_tree_view_get_cell_area(PGtkTreeView(MainView), Path, nil, @ItemRect)
else
ItemRect.height := 1; // force redraw
gtk_tree_path_free(Path);
if ItemRect.height <> 0 then // item is visible
begin
if (TListView(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) then
begin
ImgList := TListView(ALV).SmallImages;
ImgListWidth := TListView(ALV).SmallImagesWidth;
end
else
if (TListView(ALV).ViewStyle = vsIcon) then
begin
ImgList := TListView(ALV).LargeImages;
ImgListWidth := TListView(ALV).LargeImagesWidth;
end;
if Assigned(ImgList) and (ImgList.Count > 0) and (AImageIndex >= 0) then
begin
ImgListRes := ImgList.ResolutionForPPI[ImgListWidth, ALV.Font.PixelsPerInch, ALV.GetCanvasScaleFactor].Resolution;
if (ImgList.Count <> Widgets^.Images.Count) then
begin
if (TListView(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) then
SetImageList(ALV, lvilSmall, ImgListRes)
else
SetImageList(ALV, lvilLarge, ImgListRes);
exit;
end;
if (Widgets^.Images <> nil) then
begin
for i := 0 to Widgets^.Images.Count-1 do
if i = AImageIndex then
gdk_pixbuf_unref(PGdkPixBuf(Widgets^.Images.Items[i]));
pixbuf := nil;
BitImage := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, BitImage);
Gtk2_PixBufFromBitmap(BitImage,pixbuf);
Widgets^.Images.Items[AImageIndex] := pixbuf;
if GTK_IS_TREE_VIEW(MainView) then
gtk_tree_view_column_queue_resize(gtk_tree_view_get_column(PGtkTreeView(MainView), ASubIndex));
finally
BitImage.Free;
end;
end;
end;
gtk_widget_queue_draw(MainView);
end;
end;
end;
class procedure TGtk2WSCustomListView.ItemSetState(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const AState: TListItemState;
const AIsSet: Boolean);
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
BroadcastMsg: Boolean;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetState')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
// wwiInvalidEvent flag save us from infinite loop !
// when this flag is included TreeSelection 'changed' won't
// trigger - and it shouldn't LCL setted up selection.
// fixes #16399
Include(Widgets^.WidgetInfo^.Flags, wwiInvalidEvent);
try
BroadcastMsg := False;
with Widgets^ do
begin
if GetViewModel(MainView) = nil then
Exit; // we are in the midst of a begin update end update pair and the following will fail and cause gtk debug messages
case AState of
lisCut,
lisDropTarget:
begin
//TODO: do something with the rowcolor ?
end;
lisFocused:
begin
//gtk2 iter has no focus??
Path := gtk_tree_path_new_from_string(PChar(IntToStr(AIndex)));
if GTK_IS_TREE_VIEW(MainView) then
gtk_tree_view_set_cursor(PGtkTreeView(MainView), Path, nil, False)
else
if GTK_IS_ICON_VIEW(MainView) then
gtk_icon_view_set_cursor(PGtkIconView(MainView), Path, nil, False);
gtk_tree_path_free(Path);
end;
lisSelected:
begin
Path := gtk_tree_path_new_from_string(PChar(IntToStr(AIndex)));
if GTK_IS_TREE_VIEW(MainView) then
begin
if AIsSet and not gtk_tree_selection_path_is_selected(TreeSelection, Path) then
begin
gtk_tree_selection_select_path(TreeSelection, Path);
BroadcastMsg := True;
end else
if not AIsSet and gtk_tree_selection_path_is_selected(TreeSelection, Path) then
begin
gtk_tree_selection_unselect_path(TreeSelection, Path);
BroadcastMsg := True;
end;
end
else
if GTK_IS_ICON_VIEW(MainView) then
begin
if AIsSet and not gtk_icon_view_path_is_selected(PGtkIconView(MainView), Path) then
begin
gtk_icon_view_select_path(PGtkIconView(MainView), Path);
BroadCastMsg := True;
end else
if not AIsSet and gtk_icon_view_path_is_selected(PGtkIconView(MainView), Path) then
begin
gtk_icon_view_unselect_path(PGtkIconView(MainView), Path);
BroadCastMsg := True;
end;
end;
gtk_tree_path_free(Path);
if BroadcastMsg then
BroadCastListSelection(ALV, {%H-}PtrUInt(MainView), AIndex, not AIsSet);
end;
end;
end;
finally
Exclude(Widgets^.WidgetInfo^.Flags, wwiInvalidEvent);
end;
end;
class procedure TGtk2WSCustomListView.ItemSetText(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer;
const AText: String);
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
ItemRect: TGdkRectangle;
begin
// ToDo: TGtk2WSCustomListView.ItemSetText: this function queues a draw. Is this correct?
if not WSCheckHandleAllocated(ALV, 'ItemSetText')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if not gtk_widget_realized(MainView) then
Exit;
if GTK_IS_TREE_VIEW(MainView) then
begin
Path := gtk_tree_path_new_from_indices(AIndex, -1);
gtk_tree_view_get_cell_area(PGtkTreeView(MainView), Path, nil, @ItemRect);
gtk_tree_path_free(Path);
end
else
ItemRect.height := 1; // force redraw
if ItemRect.height <> 0 then // item is visible
gtk_widget_queue_draw(MainView);
end;
end;
class procedure TGtk2WSCustomListView.ItemShow(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
begin
if not WSCheckHandleAllocated(ALV, 'ItemShow')
then Exit;
// TODO: TGtk2WSCustomListView.ItemShow check for partial visiblity. currently scrolls to the Item to make it fully visible
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
Path := gtk_tree_path_new_from_indices(AIndex, -1);
if GTK_IS_TREE_VIEW(MainView) then
gtk_tree_view_scroll_to_cell(PGtkTreeView(MainView), Path, nil, False, 0, 0)
else
if GTK_IS_ICON_VIEW(MainView) then
gtk_icon_view_scroll_to_path(PGtkIconView(MainView), Path, False, 0, 0);
gtk_tree_path_free(Path);
end;
end;
class function TGtk2WSCustomListView.ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint;
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
ARect: TGdkRectangle;
Column: PGtkTreeViewColumn;
begin
if not WSCheckHandleAllocated(ALV, 'ItemGetPosition')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
Path := gtk_tree_path_new_from_indices(AIndex, -1);
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then
begin
Column := gtk_tree_view_get_column(PGtkTreeView(MainView), 0);
gtk_tree_view_get_cell_area(PGtkTreeView(MainView), Path, Column, @ARect);
Result.X := ARect.x;
Result.Y := Arect.y;
end
else
if GTK_IS_ICON_VIEW(MainView) then
begin
// todo: gtk gives no way to get item rectangle, while internally it uses it
Result.X := 0;
Result.Y := 0;
end;
end;
gtk_tree_path_free(Path);
end;
class procedure TGtk2WSCustomListView.ItemUpdate(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem);
{$IFDEF USEORIGTREEMODEL}
var
Widgets: PTVWidgets;
Iter: TGtkTreeIter;
{$ENDIF}
begin
if not WSCheckHandleAllocated(ALV, 'ItemUpdate')
then Exit;
{$IFDEF USEORIGTREEMODEL}
GetCommonTreeViewWidgets(PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
if gtk_tree_model_iter_nth_child(TreeModel, @Iter, nil, AIndex) then
gtk_list_store_set(PGtkListStore(TreeModel), @Iter, [0, Pointer(AItem), -1]);
{$ENDIF}
end;
class function TGtk2WSCustomListView.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
Widgets: PTVWidgets;
OrigScrollingData: PBaseScrollingWinControlData;
//ListViewData: PCustomListViewData;
//Allocation: TGTKAllocation;
ScrollWidget: PGtkScrolledWindow;
{$IFDEF USEORIGTREEMODEL}
PtrType: GType;
{$ENDIF}
SS: TPoint;
begin
Result := TGtk2WSBaseScrollingWinControl.CreateHandle(AWinControl, AParams);
if Result = 0 then Exit;
ScrollWidget := {%H-}PGtkScrolledWindow(Result);
gtk_widget_unset_flags(ScrollWidget^.hscrollbar, GTK_CAN_FOCUS);
gtk_widget_unset_flags(ScrollWidget^.vscrollbar, GTK_CAN_FOCUS);
SS := Gtk2TranslateScrollStyle(TListView(AWinControl).ScrollBars);
gtk_scrolled_window_set_policy(ScrollWidget,SS.X, SS.Y);
gtk_scrolled_window_set_shadow_type(ScrollWidget,
BorderStyleShadowMap[TCustomListView(AWinControl).BorderStyle]);
gtk_widget_show(PGtkWidget(ScrollWidget));
Widgets := nil;
New(Widgets);
with Widgets^ do
begin
Images := nil;
OldTreeSelection := nil;
{$IFDEF USEORIGTREEMODEL}
PtrType := G_TYPE_POINTER;
TreeModel := gtk_list_store_newv(1, @PtrType);
{$ELSE}
TreeModel:= LCLListViewModelNew(TCustomListView(AWinControl));
{$ENDIF}
if TLVHack(AWinControl).ViewStyle in [vsIcon,vsSmallIcon] then
begin
MainView := gtk_icon_view_new_with_model(TreeModel);
TreeSelection := nil;
if TLVHack(AWinControl).IconOptions.Arrangement = iaTop then
gtk_icon_view_set_columns(PGtkIconView(MainView), -1)
else
gtk_icon_view_set_columns(PGtkIconView(MainView), 1);
end
else
begin
if IsOldGtk2 then
OldTreeSelection := g_list_alloc;
MainView := gtk_tree_view_new_with_model(TreeModel);
TreeSelection := PGtkTreeSelection(gtk_tree_view_get_selection(PGtkTreeView(MainView)));
end;
g_object_unref(G_OBJECT(TreeModel));
// we added +1 because Ord(vsIcon) returns 0, so it's nil ptr
g_object_set_data(PGObject(MainView),'lcllistviewstyle', {%H-}gpointer(PtrInt(Ord(TLVHack(AWinControl).ViewStyle) + 1)));
gtk_container_add(GTK_CONTAINER(ScrollWidget),PGtkWidget(MainView));
// create widget info
// already created in TGtkWSBaseScrollingWinControl
// Replace the ScrollingInfo with our info
WidgetInfo := GetWidgetInfo(ScrollWidget);
OrigScrollingData := WidgetInfo^.UserData;
ScrollingData := OrigScrollingData^;
ItemCacheCount := 0;
WidgetInfo^.UserData := Widgets;
Dispose(OrigScrollingData);
WidgetInfo^.CoreWidget := PGtkWidget(MainView);
g_object_set_data(Pointer(MainView), 'widgetinfo', WidgetInfo);
gtk_widget_show_all(PGtkWidget(MainView));
if not AWinControl.HandleObjectShouldBeVisible and not (csDesigning in AWinControl.ComponentState) then
gtk_widget_hide(PGtkWidget(ScrollWidget));
SetListCallbacks(PGtkWidget(ScrollWidget), Widgets, WidgetInfo);
end;
end;
class procedure TGtk2WSCustomListView.DestroyHandle(const AWinControl: TWinControl);
var
Widgets: PTVWidgets;
i: Integer;
begin
GetCommonTreeViewWidgets({%H-}PGtkWidget(AWinControl.Handle), Widgets);
// on widget destroy we have no ItemDeleted notification and we must destroy ItemCache ourself
// if things will change please remove this destroy
Widgets^.ItemCacheCount := 0;
SetLength(Widgets^.ItemCache, 0);
if Widgets^.OldTreeSelection <> nil then
begin
g_list_free(Widgets^.OldTreeSelection);
Widgets^.OldTreeSelection := nil;
end;
if Widgets^.Images <> nil then
begin
for i := 0 to Widgets^.Images.Count-1 do
if Widgets^.Images.Items[i] <> nil then
gdk_pixbuf_unref(PGDKPixBuf(Widgets^.Images.Items[i]));
FreeAndNil(Widgets^.Images);
end;
if Widgets^.MainView <> nil then
g_object_set_data(Pointer(Widgets^.MainView), 'widgetinfo', nil);
TGtk2WSWinControl.DestroyHandle(AWinControl);
end;
class procedure TGtk2WSCustomListView.BeginUpdate(const ALV: TCustomListView);
begin
if not WSCheckHandleAllocated(ALV, 'BeginUpdate') then
exit;
g_object_set_data({%H-}PGObject(ALV.Handle),'lcl_gtkwidget_in_update', ALV);
end;
class procedure TGtk2WSCustomListView.EndUpdate(const ALV: TCustomListView);
begin
if not WSCheckHandleAllocated(ALV, 'EndUpdate') then
exit;
g_object_set_data({%H-}PGObject(ALV.Handle),'lcl_gtkwidget_in_update', nil);
end;
class function TGtk2WSCustomListView.GetBoundingRect(const ALV: TCustomListView): TRect;
begin
Result:=Rect(0,0,0,0);
if not WSCheckHandleAllocated(ALV, 'GetBoundingRect')
then Exit;
//DebugLn('TODO: TGtk2WSCustomListView.GetBoundingRect');
end;
class function TGtk2WSCustomListView.GetDropTarget(const ALV: TCustomListView): Integer;
var
Widgets: PTVWidgets;
begin
// TODO: implement
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetDropTarget')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
end;
class function TGtk2WSCustomListView.GetFocused(const ALV: TCustomListView): Integer;
var
Widgets: PTVWidgets;
Path: PGtkTreePath;
Column: PGtkTreeViewColumn;
Cell: PGtkCellRenderer;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetFocused')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then begin
Path:=nil;
Column:=nil;
gtk_tree_view_get_cursor(PGtkTreeView(MainView), Path, Column);
end
else begin
if GTK_IS_ICON_VIEW(MainView) then begin
Cell:=nil;
gtk_icon_view_get_cursor(PGtkIconView(MainView), Path, Cell);
end
else
Path := nil;
end;
if Path <> nil then
begin
Result := StrToInt(PChar(Path));
gtk_tree_path_free(Path);
end;
end;
end;
class function TGtk2WSCustomListView.GetHoverTime(const ALV: TCustomListView): Integer;
var
Widgets: PTVWidgets;
begin
// TODO: implement
Result := -1; // = default
if not WSCheckHandleAllocated(ALV, 'GetHoverTime')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
end;
end;
class function TGtk2WSCustomListView.GetItemAt(const ALV: TCustomListView; x, y: integer): Integer;
var
Widgets: PTVWidgets;
ItemPath: PGtkTreePath;
Column: PGtkTreeViewColumn;
cx, cy: gint;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetItemAt')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
begin
// gtk2 >= 2.19 changed treeview api
if gtk_minor_version >= 19 then
begin
gdk_window_get_position(gtk_tree_view_get_bin_window(PGtkTreeView(Widgets^.MainView)), @cx, @cy);
Dec(x, cx);
Dec(y, cy);
end else
begin
// convert X, Y to bin window coords
x := x + Round(PGtkTreeView(Widgets^.MainView)^.priv^.hadjustment^.value);
if GTK_TREE_VIEW_FLAG_SET(PGtkTreeView(Widgets^.MainView), GTK_TREE_VIEW_HEADERS_VISIBLE) then
begin
gdk_window_get_size(PGtkTreeView(Widgets^.MainView)^.priv^.header_window, @cx, @cy);
y := y - cy;
end;
end;
ItemPath:=nil;
Column:=nil;
if gtk_tree_view_get_path_at_pos(PGtkTreeView(Widgets^.MainView), x, y, ItemPath, Column, nil, nil) then
begin
if ItemPath <> nil then
begin
Result := gtk_tree_path_get_indices(ItemPath)^;
gtk_tree_path_free(ItemPath);
end;
end;
end
else
if GTK_IS_ICON_VIEW(Widgets^.MainView) then
begin
ItemPath := gtk_icon_view_get_path_at_pos(PGtkIconView(Widgets^.MainView),
x + Widgets^.ScrollingData.HValue, y + Widgets^.ScrollingData.VValue);
if ItemPath <> nil then
begin
Result := gtk_tree_path_get_indices(ItemPath)^;
gtk_tree_path_free(ItemPath);
end;
end;
end;
class function TGtk2WSCustomListView.GetSelCount(const ALV: TCustomListView): Integer;
var
Widgets: PTVWidgets;
AList: PGList;
begin
Result := 0;
if not WSCheckHandleAllocated(ALV, 'GetSelCount')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then
AList := gtk_tree_selection_get_selected_rows(TreeSelection, nil)
else
if GTK_IS_ICON_VIEW(MainView) then
AList := gtk_icon_view_get_selected_items(PGtkIconView(MainView))
else
Exit;
if AList <> nil then
begin
Result := g_list_length(AList);
g_list_free(AList);
end;
end;
end;
class function TGtk2WSCustomListView.GetSelection(const ALV: TCustomListView): Integer;
var
Widgets: PTVWidgets;
Iter: TGtkTreeIter;
Path: PGtkTreePath;
AList: PGList;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetSelection')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then
gtk_tree_selection_get_selected(TreeSelection, nil, @Iter)
else
if GTK_IS_ICON_VIEW(MainView) then
begin
AList := gtk_icon_view_get_selected_items(PGtkIconView(MainView));
if AList <> nil then
begin
Path := g_list_first(AList)^.data;
g_list_free(AList);
end else
Path := nil;
end;
Path := gtk_tree_model_get_path(TreeModel, @Iter);
Result := StrToInt(PChar(Path));
gtk_tree_path_free(Path);
end;
end;
class function TGtk2WSCustomListView.GetTopItem(const ALV: TCustomListView): Integer;
var
Res: Boolean;
s, e: PGtkTreePath;
Widgets: PTVWidgets;
Num: Pgint;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetTopItem') then
exit;
Res := false;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then
Res := gtk_tree_view_get_visible_range(PGtkTreeView(Widgets^.MainView), s, e)
else
if GTK_IS_ICON_VIEW(MainView) then
Res := gtk_icon_view_get_visible_range(PGtkTreeView(Widgets^.MainView), s, e)
else
Exit;
end;
if Res then
begin
Num := gtk_tree_path_get_indices(s);
if Num <> nil then Result := Num^;
gtk_tree_path_free(s);
gtk_tree_path_free(e);
end;
end;
class function TGtk2WSCustomListView.GetViewOrigin(const ALV: TCustomListView): TPoint;
var
Widgets: PTVWidgets;
begin
if not WSCheckHandleAllocated(ALV, 'GetViewOrigin')
then begin
Result := Point(0, 0);
Exit;
end;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
// not really needed to retrieve the adjustments, since the TVWidgets has this info also based on events
Result := Point(Widgets^.ScrollingData.HValue, Widgets^.ScrollingData.VValue);
end;
class function TGtk2WSCustomListView.GetVisibleRowCount(const ALV: TCustomListView): Integer;
var
Res: Boolean;
s, e: PGtkTreePath;
Widgets: PTVWidgets;
Num1,Num2: Pgint;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetVisibleRowCount') then
exit;
Result := 0;
Res := false;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then
Res := gtk_tree_view_get_visible_range(PGtkTreeView(Widgets^.MainView), s, e)
else
if GTK_IS_ICON_VIEW(MainView) then
Res := gtk_icon_view_get_visible_range(PGtkTreeView(Widgets^.MainView), s, e)
else
Exit;
end;
if Res then
begin
Num1 := gtk_tree_path_get_indices(s);
Num2 := gtk_tree_path_get_indices(e);
if (Num1 <> nil) and (Num2 <> nil) then Result := Num2^-Num1^+1;
gtk_tree_path_free(s);
gtk_tree_path_free(e);
end;
end;
class procedure TGtk2WSCustomListView.SelectAll(const ALV: TCustomListView;
const AIsSet: Boolean);
var
Widgets: PTVWidgets;
begin
if not WSCheckHandleAllocated(ALV, 'SelectAll') then
exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
Include(Widgets^.WidgetInfo^.Flags, wwiInvalidEvent);
try
with Widgets^ do
begin
if GTK_IS_TREE_VIEW(MainView) then
begin
if AIsSet then
gtk_tree_selection_select_all(gtk_tree_view_get_selection(PGtkTreeView(MainView)))
else
gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(PGtkTreeView(MainView)));
end else
begin
if GTK_IS_ICON_VIEW(MainView) then
begin
if AIsSet then
gtk_icon_view_select_all(PGtkIconView(MainView))
else
gtk_icon_view_unselect_all(PGtkIconView(MainView));
end;
end;
end;
finally
Exclude(Widgets^.WidgetInfo^.Flags, wwiInvalidEvent);
end;
end;
class procedure TGtk2WSCustomListView.SetAllocBy(const ALV: TCustomListView;
const AValue: Integer);
begin
if not WSCheckHandleAllocated(ALV, 'SetAllocBy')
then Exit;
end;
class procedure TGtk2WSCustomListView.SetColor(const AWinControl: TWinControl);
var
AWidget: PGTKWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then
Exit;
AWidget := {%H-}PGtkWidget(AWinControl.Handle);
AWidget := GetOrCreateWidgetInfo(AWidget)^.CoreWidget;
Gtk2WidgetSet.SetWidgetColor(AWidget,
AWinControl.Font.Color,
AWinControl.Color,
[GTK_STATE_NORMAL, GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, GTK_STYLE_BASE]);
end;
class procedure TGtk2WSCustomListView.SetDefaultItemHeight(
const ALV: TCustomListView; const AValue: Integer);
begin
if not WSCheckHandleAllocated(ALV, 'SetDefaultItemHeight')
then Exit;
end;
class procedure TGtk2WSCustomListView.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
Widget: PGtkWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetFont') then
Exit;
Widget := {%H-}PGtkWidget(AWinControl.Handle);
Widget := GetOrCreateWidgetInfo(Widget)^.CoreWidget;
Gtk2WidgetSet.SetWidgetFont(Widget, AFont);
Gtk2WidgetSet.SetWidgetColor(Widget, AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,
GTK_STATE_PRELIGHT,GTK_STATE_SELECTED,
GTK_STYLE_TEXT]);
end;
class procedure TGtk2WSCustomListView.SetHotTrackStyles(const ALV: TCustomListView;
const AValue: TListHotTrackStyles);
begin
if not WSCheckHandleAllocated(ALV, 'SetHotTrackStyles')
then Exit;
end;
class procedure TGtk2WSCustomListView.SetImageList(const ALV: TCustomListView;
const AList: TListViewImageList; const AValue: TCustomImageListResolution);
var
Widgets: PTVWidgets;
BitImage: TBitmap;
pixbuf: PGDKPixBuf;
i: Integer;
APGList: PGList;
pixrenderer: PGtkCellRenderer;
begin
if not WSCheckHandleAllocated(ALV, 'SetImageList')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
gtk_widget_queue_draw(Widgets^.MainView);
if ((AList = lvilLarge) and (TLVHack(ALV).ViewStyle = vsIcon)) or
((AList = lvilSmall) and (TLVHack(ALV).ViewStyle <> vsIcon)) then
begin
if Widgets^.Images <> nil then
begin
for i := 0 to Widgets^.Images.Count-1 do
gdk_pixbuf_unref(PGdkPixBuf(Widgets^.Images.Items[i]));
Widgets^.Images.Clear;
end;
if AValue = nil then
Exit;
if Widgets^.Images = nil then
Widgets^.Images := TList.Create;
if (AValue.Count = 0) and GTK_IS_TREE_VIEW(Widgets^.MainView) and (TLVHack(ALV).Columns.Count > 0) and
not TLVHack(ALV).OwnerDraw then
begin
APGList := gtk_tree_view_column_get_cell_renderers(gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), 0));
pixrenderer := PGtkCellRenderer(g_list_last(APGList)^.prev^.data);
gtk_cell_renderer_set_fixed_size(pixrenderer, AValue.Width + 2, AValue.Height + 2);
g_list_free(APGList);
gtk_tree_view_column_queue_resize(gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), 0));
end;
for i := 0 to AValue.Count-1 do
begin
pixbuf := nil;
BitImage := TBitmap.Create;
try
AValue.GetBitmap(i, BitImage);
Gtk2_PixBufFromBitmap(BitImage, pixbuf);
if GTK_IS_TREE_VIEW(Widgets^.MainView) and (TLVHack(ALV).Columns.Count > 0) and
not TLVHack(ALV).OwnerDraw then
begin
APGList := gtk_tree_view_column_get_cell_renderers(gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), 0));
pixrenderer := PGtkCellRenderer(g_list_last(APGList)^.prev^.data);
gtk_cell_renderer_set_fixed_size(pixrenderer, AValue.Width + 2, AValue.Height + 2);
g_list_free(APGList);
gtk_tree_view_column_queue_resize(gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), 0));
end;
Widgets^.Images.Add(pixbuf);
finally
BitImage.Free;
end;
end;
end;
end;
class procedure TGtk2WSCustomListView.SetItemsCount(const ALV: TCustomListView;
const Avalue: Integer);
var
Widgets: PTVWidgets;
{$IFDEF USEORIGTREEMODEL}
Iter: TGtkTreeIter;
Index: Integer;
{$ENDIF}
begin
if not WSCheckHandleAllocated(ALV, 'SetItemsCount')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
with Widgets^ do
begin
{$IFNDEF USEORIGTREEMODEL}
g_object_ref(TreeModel);
gtk_tree_view_set_model(PGtkTreeView(MainView), nil);
gtk_tree_view_set_model(PGtkTreeView(MainView), TreeModel);
g_object_unref(TreeModel);
{$ELSE}
gtk_list_store_clear(PGtkListStore(TreeModel));
for Index := 0 to AValue - 1 do
gtk_list_store_insert_with_values(PGtkListStore(TreeModel), @Iter, Index, 0, nil, -1);
{$ENDIF}
end;
end;
class procedure TGtk2WSCustomListView.SetProperty(const ALV: TCustomListView;
const AProp: TListViewProperty; const AIsSet: Boolean);
var
Widgets: PTVWidgets;
begin
if not WSCheckHandleAllocated(ALV, 'SetProperty')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
SetPropertyInternal(ALV, Widgets, AProp, AIsSet);
end;
class procedure TGtk2WSCustomListView.SetProperties(const ALV: TCustomListView;
const AProps: TListViewProperties);
var
Widgets: PTVWidgets;
Prop: TListViewProperty;
begin
if not WSCheckHandleAllocated(ALV, 'SetProperties')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
for Prop := Low(Prop) to High(Prop) do
SetPropertyInternal(ALV, Widgets, Prop, Prop in AProps);
end;
class procedure TGtk2WSCustomListView.SetScrollBars(const ALV: TCustomListView;
const AValue: TScrollStyle);
var
SS:TPoint;
ScrollWidget: PGtkScrolledWindow;
begin
if not WSCheckHandleAllocated(ALV, 'SetScrollBars') then
exit;
ScrollWidget := {%H-}PGtkScrolledWindow(ALV.Handle);
SS := Gtk2TranslateScrollStyle(AValue);
gtk_scrolled_window_set_policy(ScrollWidget ,SS.X, SS.Y);
end;
class procedure TGtk2WSCustomListView.SetSort(const ALV: TCustomListView;
const AType: TSortType; const AColumn: Integer;
const ASortDirection: TSortDirection);
var
Widgets: PTVWidgets;
begin
if not WSCheckHandleAllocated(ALV, 'SetSort')
then Exit;
// gtk2 needs only update
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
if GetViewModel(Widgets^.MainView) = nil then
exit;
if not gtk_widget_realized(Widgets^.MainView) then
exit;
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
gtk_widget_queue_draw(Widgets^.MainView);
end;
class procedure TGtk2WSCustomListView.SetViewOrigin(const ALV: TCustomListView;
const AValue: TPoint);
var
Widgets: PTVWidgets;
begin
if not WSCheckHandleAllocated(ALV, 'SetViewOrigin')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets{%H-});
//DebugLn(['TGtk2WSCustomListView.SetViewOrigin ',GetWidgetDebugReport(Widgets^.MainView)]);
if not GTK_WIDGET_REALIZED(Widgets^.MainView) then exit;
if GTK_IS_TREE_VIEW(Widgets^.MainView) then
gtk_tree_view_scroll_to_point(PGtkTreeView(Widgets^.MainView), AValue.X, AValue.Y)
else
if GTK_IS_ICON_VIEW(Widgets^.MainView) then
begin
// TODO: iconview
end;
end;
class procedure TGtk2WSCustomListView.SetViewStyle(const ALV: TCustomListView;
const AValue: TViewStyle);
var
APtrIntData: PtrInt;
procedure ShowColumns(const Widgets: PTVWidgets; const Show: Boolean);
var
List: PGList;
GtkColumn: PGtkTreeViewColumn;
i: Integer;
begin
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
Exit;
List := gtk_tree_view_get_columns(PGtkTreeView(Widgets^.MainView));
for i := 0 to g_list_length(List) - 1 do
begin
GtkColumn := g_list_nth_data(List, i);
if GtkColumn = nil then
Continue;
if not Show or
(Show and ({%H-}PtrUInt(g_object_get_data(G_OBJECT(GtkColumn),
PChar('Visible'))) <> 0)) then
gtk_tree_view_column_set_visible(GtkColumn, Show);
end;
g_list_free(List)
end;
var
Widgets: PTVWidgets;
begin
if not WSCheckHandleAllocated(ALV, 'SetViewStyle')
then Exit;
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets{%H-});
if g_object_get_data(PGObject(Widgets^.MainView),'lcllistviewstyle') <> nil then
APtrIntData := {%H-}PtrInt(g_object_get_data(PGObject(Widgets^.MainView),'lcllistviewstyle'))
else
APtrIntData := -1;
if (APtrIntData <> -1) and (APtrIntData - 1 <> Ord(AValue)) then
begin
// we have to free the GtkTreeView and Create GtkIconView etc depending on the new style
//RecreateMainView(ALV);
// we actually need to recreate our ListView since not only the widget changes but also columns
RecreateWnd(ALV);
Exit;
end;
ShowColumns(Widgets, AValue = vsReport);
with Widgets^ do
begin
case AValue of
vsIcon,
vsSmallIcon:
begin
SetNeedDefaultColumn(ALV, True);
end;
vsList:
begin
SetNeedDefaultColumn(ALV, True);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (MainView), False);
end;
vsReport:
begin
SetNeedDefaultColumn(ALV, False);
if TLVHack(ALV).ShowColumnHeaders = True then
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (MainView), True);
end;
end;
end;
// inherited SetViewStyle(ALV, Avalue);
end;
|