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
|
{ $Id$}
{
*****************************************************************************
* GtkWSStdCtrls.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.
*****************************************************************************
}
unit GtkWSStdCtrls;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Math,
LCLType, LMessages, LCLProc, Controls, Graphics, StdCtrls, Forms,
{$IFDEF gtk2}
glib2, gdk2pixbuf, gdk2, gtk2, Pango, Gtk2WSPrivate,
{$ELSE}
glib, gdk, gtk, gdkpixbuf,
GtkFontCache, Gtk1WSPrivate,
{$ENDIF}
InterfaceBase, WSStdCtrls, WSLCLClasses, WSProc, WSControls,
GtkInt, GtkDef, GTKWinApiWindow, GtkGlobals, GtkProc, GtkExtra, GtkWSPrivate;
type
{ TGtkWSScrollBar }
TGtkWSScrollBar = class(TWSScrollBar)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure SetParams(const AScrollBar: TCustomScrollBar); override;
end;
{ TGtkWSCustomGroupBox }
TGtkWSCustomGroupBox = class(TWSCustomGroupBox)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
{$ifdef gtk1}
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
{$endif}
end;
{ TGtkWSGroupBox }
TGtkWSGroupBox = class(TWSGroupBox)
published
end;
{ TGtkWSCustomComboBox }
TGtkWSCustomComboBox = class(TWSCustomComboBox)
published
{$IFDEF GTK1}
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class function GetDroppedDown(const ACustomComboBox: TCustomComboBox): Boolean; override;
class function GetSelStart(const ACustomComboBox: TCustomComboBox): integer; override;
class function GetSelLength(const ACustomComboBox: TCustomComboBox): integer; override;
class function GetItemIndex(const ACustomComboBox: TCustomComboBox): integer; override;
class function GetMaxLength(const ACustomComboBox: TCustomComboBox): integer; override;
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
class procedure SetArrowKeysTraverseList(const ACustomComboBox: TCustomComboBox;
NewTraverseList: boolean); override;
class procedure SetDroppedDown(const ACustomComboBox: TCustomComboBox; ADroppedDown: Boolean); override;
class procedure SetSelStart(const ACustomComboBox: TCustomComboBox; NewStart: integer); override;
class procedure SetSelLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;
class procedure SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); override;
class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;
class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override;
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override;
class procedure Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override;
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
{$ENDIF}
end;
{ TGtkWSComboBox }
TGtkWSComboBox = class(TWSComboBox)
published
end;
{ TGtkWSCustomListBox }
TGtkWSCustomListBox = class(TWSCustomListBox)
published
{$IFDEF GTK1}
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
class function GetTopIndex(const ACustomListBox: TCustomListBox): integer; override;
class procedure SelectItem(const ACustomListBox: TCustomListBox; AIndex: integer; ASelected: boolean); override;
class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean); override;
class procedure SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); override;
class procedure SetTopIndex(const ACustomListBox: TCustomListBox; const NewTopIndex: integer); override;
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
{$ENDIF}
end;
{ TGtkWSListBox }
TGtkWSListBox = class(TWSListBox)
published
end;
{ TGtkWSCustomEdit }
TGtkWSCustomEdit = class(TWSCustomEdit)
published
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
class procedure SetCharCase(const ACustomEdit: TCustomEdit; NewCase: TEditCharCase); override;
class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override;
class procedure SetMaxLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
class procedure SetPasswordChar(const ACustomEdit: TCustomEdit; NewChar: char); override;
class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class procedure SetColor(const AWinControl: TWinControl); override;
end;
{ TGtkWSCustomMemo }
TGtkWSCustomMemo = class(TWSCustomMemo)
published
{$ifdef GTK1}
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure AppendText(const ACustomMemo: TCustomMemo;
const AText: string); override;
class function GetStrings(const ACustomMemo: TCustomMemo): TStrings; override;
class procedure SetEchoMode(const ACustomEdit: TCustomEdit;
NewMode: TEchoMode); override;
class procedure SetMaxLength(const ACustomEdit: TCustomEdit;
NewLength: integer); override;
class procedure SetPasswordChar(const ACustomEdit: TCustomEdit;
NewChar: char); override;
class procedure SetReadOnly(const ACustomEdit: TCustomEdit;
NewReadOnly: boolean); override;
class procedure SetScrollbars(const ACustomMemo: TCustomMemo;
const NewScrollbars: TScrollStyle); override;
class procedure SetWordWrap(const ACustomMemo: TCustomMemo;
const NewWordWrap: boolean); override;
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
{$endif}
end;
{ TGtkWSEdit }
TGtkWSEdit = class(TWSEdit)
published
end;
{ TGtkWSMemo }
TGtkWSMemo = class(TWSMemo)
published
end;
{ TGtkWSCustomStaticText }
TGtkWSCustomStaticText = class(TWSCustomStaticText)
protected
class function GetLabelWidget(AFrame: PGtkFrame): PGtkLabel;
class function GetBoxWidget(AFrame: PGtkFrame): PGtkEventBox;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure SetAlignment(const ACustomStaticText: TCustomStaticText;
const NewAlignment: TAlignment); override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
class procedure SetStaticBorderStyle(const ACustomStaticText: TCustomStaticText; const NewBorderStyle: TStaticBorderStyle); override;
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
end;
{ TGtkWSStaticText }
TGtkWSStaticText = class(TWSStaticText)
published
end;
{ TGtkWSButtonControl }
TGtkWSButtonControl = class(TWSButtonControl)
published
end;
{ TGtkWSButton }
TGtkWSButton = class(TWSButton)
public
{SetCallbacks is made public so that it can be called from
TGtkWSBitBtn.CreateHandle.
TODO: move it to TGtkPrivateButton}
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
{$ifdef Gtk1}
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override;
class procedure SetShortcut(const AButton: TCustomButton; const ShortCutK1, ShortCutK2: TShortcut); override;
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
{$endif Gtk1}
end;
{ TGtkWSCustomCheckBox }
TGtkWSCustomCheckBox = class(TWSCustomCheckBox)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
{$IFDEF GTK1}
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override;
class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const ShortCutK1, ShortCutK2: TShortCut); override;
class procedure SetState(const ACB: TCustomCheckBox; const ANewState: TCheckBoxState); override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
{$ENDIF}
end;
{ TGtkWSCheckBox }
TGtkWSCheckBox = class(TWSCheckBox)
published
end;
{ TGtkWSToggleBox }
TGtkWSToggleBox = class(TWSToggleBox)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
end;
{ TGtkWSRadioButton }
TGtkWSRadioButton = class(TWSRadioButton)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
end;
function WidgetGetSelStart(const Widget: PGtkWidget): integer;
procedure WidgetSetSelLength(const Widget: PGtkWidget; NewLength: integer);
{$ifdef gtk1}
{$I gtk1memostringsh.inc}
{$endif}
implementation
uses
GtkWSControls, LazUtilities;
const
StaticBorderShadowMap: array[TStaticBorderStyle] of TGtkShadowType =
(
GTK_SHADOW_NONE,
GTK_SHADOW_ETCHED_IN,
GTK_SHADOW_IN
);
{$ifdef gtk1}
{$I gtk1memostrings.inc}
{$endif}
{ helper routines }
function WidgetGetSelStart(const Widget: PGtkWidget): integer;
begin
if Widget <> nil then
begin
if PGtkOldEditable(Widget)^.selection_start_pos
< PGtkOldEditable(Widget)^.selection_end_pos
then
Result:= PGtkOldEditable(Widget)^.selection_start_pos
else
Result:= PGtkOldEditable(Widget)^.current_pos;// selection_end_pos
end else
Result:= 0;
end;
procedure WidgetSetSelLength(const Widget: PGtkWidget; NewLength: integer);
begin
if Widget<>nil then
begin
gtk_editable_select_region(PGtkOldEditable(Widget),
gtk_editable_get_position(PGtkOldEditable(Widget)),
gtk_editable_get_position(PGtkOldEditable(Widget)) + NewLength);
end;
end;
{ TGtkWSScrollBar }
class procedure TGtkWSScrollBar.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
if TScrollBar(AWidgetInfo^.LCLObject).Kind = sbHorizontal then
TGtkWidgetset(Widgetset).SetCallback(LM_HSCROLL, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject)
else
TGtkWidgetset(Widgetset).SetCallback(LM_VSCROLL, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
class function TGtkWSScrollBar.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Adjustment: PGtkAdjustment;
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
with TScrollBar(AWinControl) do
begin
Adjustment := PgtkAdjustment(
gtk_adjustment_new(1, Min, Max, SmallChange, LargeChange,
Pagesize));
if (Kind = sbHorizontal) then
Widget := gtk_hscrollbar_new(Adjustment)
else
Widget := gtk_vscrollbar_new(Adjustment);
end;
gtk_object_set_data(PGTKObject(Adjustment), odnScrollBar, Widget);
Result := TLCLHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
class procedure TGtkWSScrollBar.SetParams(const AScrollBar: TCustomScrollBar);
var
Adjustment: PGtkAdjustment;
begin
with AScrollBar do
begin
//set properties for the range
Adjustment := gtk_range_get_adjustment (GTK_RANGE(Pointer(Handle)));
Adjustment^.lower := Min;
Adjustment^.Upper := Max;
Adjustment^.Value := Position;
Adjustment^.step_increment := SmallChange;
Adjustment^.page_increment := LargeChange;
end;
end;
{ TGtkWSCustomListBox }
{$IFDEF GTK1}
class function TGtkWSCustomListBox.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
ScrolledWnd: PGtkScrolledWindow absolute Widget;
ListBox: TCustomListBox absolute AWinControl;
List: Pointer;
begin
Widget := gtk_scrolled_window_new(nil, nil);
GTK_WIDGET_UNSET_FLAGS(ScrolledWnd^.hscrollbar, GTK_CAN_FOCUS);
GTK_WIDGET_UNSET_FLAGS(ScrolledWnd^.vscrollbar, GTK_CAN_FOCUS);
gtk_scrolled_window_set_policy(ScrolledWnd, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_show(Widget);
List := gtk_list_new;
gtk_scrolled_window_add_with_viewport(ScrolledWnd, List);
gtk_container_set_focus_vadjustment(List,
gtk_scrolled_window_get_vadjustment(ScrolledWnd));
gtk_container_set_focus_hadjustment(PGtkContainer(List),
gtk_scrolled_window_get_hadjustment(ScrolledWnd));
gtk_widget_show(List);
WidgetInfo := CreateWidgetInfo(Widget, AWinControl, AParams);
SetMainWidget(Widget, List);
WidgetInfo^.CoreWidget := List;
TGtkWidgetSet(WidgetSet).SetSelectionMode(AWinControl, Widget,
ListBox.MultiSelect, ListBox.ExtendedSelect);
Result := TLCLHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Set_RC_Name(AWinControl, Widget);
TGtkPrivateListClass(WSPrivate).SetCallbacks(Widget, WidgetInfo);
end;
class function TGtkWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
var
ScrolledWindow: PGtkScrolledWindow;
VertAdj: PGTKAdjustment;
AdjValue: integer;
ListWidget: PGtkList;
AWidget: PGtkWidget;
GListItem: PGList;
ListItemWidget: PGtkWidget;
begin
Result:=-1;
if ACustomListBox.FCompStyle in [csListBox, csCheckListBox] then
begin
AWidget:=PGtkWidget(ACustomListBox.Handle);
ListWidget:=PGtkList(GetWidgetInfo(AWidget, True)^.CoreWidget);
ScrolledWindow:=PGtkScrolledWindow(AWidget);
VertAdj:=gtk_scrolled_window_get_vadjustment(ScrolledWindow);
if VertAdj=nil then
AdjValue:=y
else
AdjValue:=RoundToInt(VertAdj^.value)+y;
GListItem:=ListWidget^.children;
while GListItem<>nil do begin
inc(Result);
ListItemWidget:=PGtkWidget(GListItem^.data);
dec(AdjValue,ListItemWidget^.Allocation.Height);
if AdjValue<0 then exit;
GListItem:=GListItem^.next;
end;
Result:=-1;
end;
end;
class function TGtkWSCustomListBox.GetItemIndex(const ACustomListBox: TCustomListBox
): integer;
var
Widget: PGtkWidget;// pointer to gtk-widget
GList : pGList; // Only used for listboxes, replace with widget!!!!!
Handle: HWND;
begin
Handle := ACustomListBox.Handle;
{!$IFdef GTK1}
if Handle<>0 then
begin
Widget := nil;
if Widget = nil then
begin
GList:= PGtkList(GetWidgetInfo(Pointer(Handle), True)^.
CoreWidget)^.selection;
if GList <> nil then
Widget:= PGtkWidget(GList^.data);
end;
if Widget = nil then
Result:= -1
else
Result:= gtk_list_child_position(PGtkList(
GetWidgetInfo(Pointer(Handle), True)^.
CoreWidget), Widget);
end
else
Result:=-1;
{!$EndIf}
end;
class function TGtkWSCustomListBox.GetItemRect(
const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect
): boolean;
var
ScrolledWindow: PGtkScrolledWindow;
VertAdj: PGTKAdjustment;
AdjValue: integer;
ListWidget: PGtkList;
AWidget: PGtkWidget;
GListItem: PGList;
ListItemWidget: PGtkWidget;
begin
Result:=false;
FillChar(ARect,SizeOf(ARect),0);
if ACustomListBox.FCompStyle in [csListBox, csCheckListBox] then
begin
AWidget:=PGtkWidget(ACustomListBox.Handle);
ListWidget:=PGtkList(GetWidgetInfo(AWidget, True)^.CoreWidget);
ScrolledWindow:=PGtkScrolledWindow(AWidget);
VertAdj:=gtk_scrolled_window_get_vadjustment(ScrolledWindow);
if VertAdj=nil then
AdjValue:=0
else
AdjValue:= (-RoundToInt(VertAdj^.value));
GListItem:=ListWidget^.children;
while GListItem<>nil do
begin
ListItemWidget:=PGtkWidget(GListItem^.data);
if Index=0 then
begin
ARect.Left:=0;
ARect.Top:=AdjValue;
ARect.Right:=ListItemWidget^.Allocation.Width;
ARect.Bottom:=ARect.Top+ListItemWidget^.Allocation.Height;
Result:=true;
exit;
end;
inc(AdjValue,ListItemWidget^.Allocation.Height);
dec(Index);
GListItem:=GListItem^.next;
end;
end;
end;
class function TGtkWSCustomListBox.GetSelCount(const ACustomListBox: TCustomListBox
): integer;
var
Handle: HWND;
begin
Handle := ACustomListBox.Handle;
Result := g_list_length(PGtkList(GetWidgetInfo(Pointer(Handle),
True)^.CoreWidget)^.selection);
end;
class function TGtkWSCustomListBox.GetSelected(const ACustomListBox: TCustomListBox;
const AIndex: integer): boolean;
var
Handle: HWND;
Widget : PGtkWidget; // pointer to gtk-widget (local use when neccessary)
//GList : pGList; // Only used for listboxes, replace with widget!!!!!
ListItem : PGtkListItem;// currently only used for listboxes
begin
Result := false; { assume: nothing found }
Handle := ACustomListBox.Handle;
{ Get the child in question of that index }
Widget:=GetWidgetInfo(Pointer(Handle),True)^.CoreWidget;
ListItem:= g_list_nth_data(PGtkList(Widget)^.children, AIndex);
if (ListItem<>nil)
and (g_list_index(PGtkList(Widget)^.selection, ListItem)>=0)
then Result:=true
//if CompareText(ACustomListBox.Name,'LBProperties')=0 then
// debugln('TGtkWSCustomListBox.GetSelected ',DbgSName(ACustomListBox),' Index=',dbgs(AIndex),' Selected=',dbgs(Result));
end;
class function TGtkWSCustomListBox.GetStrings(const ACustomListBox: TCustomListBox
): TStrings;
var
Widget: PGtkWidget;// pointer to gtk-widget
Handle: HWND;
begin
Handle := ACustomListBox.Handle;
Widget := GetWidgetInfo(Pointer(Handle), True)^.CoreWidget;
Result := TGtkListStringList.Create(PGtkList(Widget),
ACustomListBox, ACustomListBox.fCompStyle = csCheckListBox);
if ACustomListBox is TCustomListBox then
TGtkListStringList(Result).Sorted := ACustomListBox.Sorted;
end;
class function TGtkWSCustomListBox.GetTopIndex(const ACustomListBox: TCustomListBox): integer;
begin
Result := GetIndexAtXY(ACustomListBox, 0, 0);
end;
class procedure TGtkWSCustomListBox.SelectItem(const ACustomListBox: TCustomListBox;
AIndex: integer; ASelected: boolean);
var
Widget: PGtkWidget;// pointer to gtk-widget (local use when neccessary)
Handle: HWND;
begin
//if CompareText(ACustomListBox.Name,'LBProperties')=0 then
// debugln('TGtkWSCustomListBox.SelectItem ',DbgSName(ACustomListBox),' Index=',dbgs(AIndex),' Selected=',dbgs(ASelected));
Handle := ACustomListBox.Handle;
Widget := GetWidgetInfo(Pointer(Handle), True)^.CoreWidget;
if ASelected then gtk_list_select_item(PGtkList(Widget), AIndex)
else gtk_list_unselect_item(PGtkList(Widget), AIndex);
end;
class procedure TGtkWSCustomListBox.SetBorder(const ACustomListBox: TCustomListBox);
var
Handle: HWND;
Widget: PGtkWidget;// pointer to gtk-widget
begin
Handle := ACustomListBox.Handle;
Widget:= PGtkWidget(PGtkBin(Handle)^.child);
gtk_viewport_set_shadow_type(PGtkViewPort(Widget), BorderStyleShadowMap[ACustomListBox.BorderStyle]);
end;
class procedure TGtkWSCustomListBox.SetItemIndex(const ACustomListBox: TCustomListBox;
const AIndex: integer);
var
Handle: HWND;
Widget: PGtkWidget;
begin
//if CompareText(ACustomListBox.Name,'LBProperties')=0 then
// debugln('TGtkWSCustomListBox.SetItemIndex ',DbgSName(ACustomListBox),' Index=',dbgs(AIndex));
Handle := ACustomListBox.Handle;
if Handle<>0 then
begin
LockOnChange(PGtkObject(Handle),+1);
Widget:=GetWidgetInfo(Pointer(Handle),True)^.CoreWidget;
if AIndex >= 0 then
gtk_list_select_item(PGtkList(Widget), AIndex)
else
gtk_list_unselect_all(PGtkList(Widget));
LockOnChange(PGtkObject(Handle),-1);
end;
end;
class procedure TGtkWSCustomListBox.SetSelectionMode(
const ACustomListBox: TCustomListBox;
const AExtendedSelect, AMultiSelect: boolean);
begin
//if CompareText(ACustomListBox.Name,'LBProperties')=0 then
// debugln('TGtkWSCustomListBox.SetSelectionMode ',DbgSName(ACustomListBox));
TGtkWidgetSet(WidgetSet).SetSelectionMode(ACustomListBox,
PGtkWidget(ACustomListBox.Handle), AMultiSelect, AExtendedSelect);
end;
class procedure TGtkWSCustomListBox.SetSorted(const ACustomListBox: TCustomListBox;
AList: TStrings; ASorted: boolean);
begin
//if CompareText(ACustomListBox.Name,'LBProperties')=0 then
// debugln('TGtkWSCustomListBox.SetSorted ',DbgSName(ACustomListBox));
if AList is TGtkListStringList then
TGtkListStringList(AList).Sorted := ASorted
else
raise Exception.Create('');
end;
class procedure TGtkWSCustomListBox.SetTopIndex(
const ACustomListBox: TCustomListBox; const NewTopIndex: integer);
var
ScrolledWindow: PGtkScrolledWindow;
VertAdj: PGTKAdjustment;
AdjValue, MaxAdjValue: integer;
ListWidget: PGtkList;
AWidget: PGtkWidget;
GListItem: PGList;
ListItemWidget: PGtkWidget;
i: Integer;
requisition: TGtkRequisition;
begin
//if CompareText(ACustomListBox.Name,'LBProperties')=0 then
// debugln('TGtkWSCustomListBox.SetTopIndex ',DbgSName(ACustomListBox));
AWidget:=PGtkWidget(ACustomListBox.Handle);
ListWidget:=PGtkList(GetWidgetInfo(AWidget, True)^.CoreWidget);
ScrolledWindow:=PGtkScrolledWindow(AWidget);
AdjValue:=0;
GListItem:=ListWidget^.children;
i:=0;
while GListItem<>nil do begin
ListItemWidget:=PGtkWidget(GListItem^.data);
if i>=NewTopIndex then break;
if ListItemWidget<>nil then begin
gtk_widget_size_request(ListItemWidget,@requisition);
inc(AdjValue,requisition.height);
end;
//DebugLn(['TGtkWSCustomListBox.SetTopIndex ',i,' AdjValue=',AdjValue,' Flags=',WidgetFlagsToString(ListItemWidget)]);
inc(i);
GListItem:=GListItem^.next;
end;
VertAdj:=gtk_scrolled_window_get_vadjustment(ScrolledWindow);
MaxAdjValue:=RoundToInt(VertAdj^.upper);
if AdjValue>MaxAdjValue then AdjValue:=MaxAdjValue;
//DebugLn(['TGtkWSCustomListBox.SetTopIndex AdjValue=',AdjValue,' VertAdj^.upper=',VertAdj^.upper,' VertAdj^.page_size=',VertAdj^.page_size]);
gtk_adjustment_set_value(VertAdj,AdjValue);
end;
class procedure TGtkWSCustomListBox.SetColor(const AWinControl: TWinControl);
var
AWidget, ListWidget: PGTKWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
AWidget := PGtkWidget(AWinControl.Handle);
ListWidget := GetWidgetInfo(AWidget, True)^.CoreWidget;
GtkWidgetSet.SetWidgetColor(ListWidget, AWinControl.Font.Color,
AWinControl.Color,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED,
GTK_STYLE_BASE]);
end;
class procedure TGtkWSCustomListBox.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
Widget: PGtkWidget;
GList: PGList;
ChildWidget: PGTKLabel;
begin
if not AWinControl.HandleAllocated then exit;
{ Get the selections }
Widget := GetWidgetInfo(Pointer(AWinControl.Handle))^.CoreWidget;
GList := PGtkList(Widget)^.children;
while Assigned(GList) do
begin
// DebugLn('TGtkWSCustomListBox.SetFont for item ',PGTKLabel(PGtkBin(GList^.data)^.child)^.thelabel);
ChildWidget := PGTKLabel(PGtkBin(GList^.data)^.child);
GtkWidgetSet.SetWidgetColor(PGtkWidget(ChildWidget), AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
GtkWidgetSet.SetWidgetFont(PGtkWidget(ChildWidget), AFont);
GList := GList^.Next;
end;
end;
{$ENDIF}
{ TGtkWSCustomComboBox }
{$IFDEF GTK1}
function gtkComboBoxChanged(Widget: PGtkWidget; Info: PWidgetInfo): GBoolean; cdecl;
var
Mess : TLMessage;
GtkComboWidget: PGtkCombo;
GtkListWidget: PGtkList;
LCLIndex: PInteger;
GtkIndex: Integer;
begin
Result := CallBackDefaultReturn;
if ComponentIsDestroyingHandle(TWinControl(Info^.LCLObject)) or
(Info^.ChangeLock > 0) or
(gtk_signal_n_emissions_by_name(PGtkObject(widget), 'changed') > 1) or
(GTK_WIDGET_VISIBLE(PGtkCombo(Info^.CoreWidget)^.popwin)) then exit;
{$IFDEF EventTrace}
EventTrace('changed', Info^.LCLObject);
{$ENDIF}
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_CHANGED;
DeliverMessage(Info^.LCLObject, Mess);
GtkComboWidget := PGtkCombo(Info^.CoreWidget);
GtkListWidget := PGtkList(GtkComboWidget^.list);
LCLIndex := PInteger(Info^.UserData);
//Check if an item is selected
if (GtkListWidget^.selection <> nil) then
begin
GtkIndex := gtk_list_child_position(GtkListWidget,
PGtkWidget(GtkListWidget^.selection^.data));
//If the selected item index changed send a LM_SELCHANGE msg
if LCLIndex^ <> GtkIndex then
begin
gtk_list_set_selection_mode(GtkListWidget, GTK_SELECTION_BROWSE);
LCLIndex^ := GtkIndex;
Mess.Msg := LM_SELCHANGE;
DeliverMessage(Info^.LCLObject, Mess);
end;
end
else
begin
LCLIndex^ := -1;
gtk_list_set_selection_mode(GtkListWidget, GTK_SELECTION_SINGLE);
end;
end;
class function TGtkWSCustomComboBox.GetDroppedDown(
const ACustomComboBox: TCustomComboBox): Boolean;
var
ComboWidget: PGtkCombo;
begin
if not WSCheckHandleAllocated(ACustomComboBox, 'GetDroppedDown') then
Exit(False);
ComboWidget:=PGtkCombo(ACustomComboBox.Handle);
Result := GTK_WIDGET_VISIBLE(ComboWidget^.popwin);
end;
class procedure TGtkWSCustomComboBox.SetDroppedDown(
const ACustomComboBox: TCustomComboBox; ADroppedDown: Boolean);
procedure gtk_combo_get_pos(combo : PGtkCombo; var x : gint; var y : gint;
var height : gint; var width : gint);
var
popwin : PGtkbin;
widget : PGtkWidget;
popup : PGtkScrolledwindow;
real_height : gint;
list_requisition : PGtkRequisition;
show_hscroll : gboolean;
show_vscroll : gboolean;
avail_height : gint;
min_height : gint;
alloc_width : gint;
work_height : gint;
old_height : gint;
old_width : gint;
okay_to_exit : boolean;
const
EMPTY_LIST_HEIGHT = 15;
begin
show_hscroll := False;
show_vscroll := False;
widget := GTK_WIDGET(combo);
popup := GTK_SCROLLED_WINDOW (combo^.popup);
popwin := GTK_BIN (combo^.popwin);
gdk_window_get_origin (combo^.entry^.window, @x, @y);
real_height := MIN (combo^.entry^.requisition.height,
combo^.entry^.allocation.height);
y := y + real_height;
avail_height := gdk_screen_height () - y;
New(list_requisition);
if combo^.list<>nil then begin
gtk_widget_size_request (combo^.list, list_requisition);
end else begin
list_requisition^.height:=1;
list_requisition^.width:=1;
end;
min_height := MIN (list_requisition^.height,popup^.vscrollbar^.requisition.height);
if GTK_LIST (combo^.list)^.children = nil then
list_requisition^.height := list_requisition^.height + EMPTY_LIST_HEIGHT;
alloc_width := (cardinal(widget^.allocation.width) -
2 * cardinal(gtk_widget_get_xthickness(gtk_bin_get_child(popwin))) -
2 * border_width(GTK_CONTAINER (gtk_bin_get_child(popwin))^) -
2 * border_width(GTK_CONTAINER (combo^.popup)^) -
2 * border_width(GTK_CONTAINER (gtk_bin_get_child(PGTKBin(popup)))^) -
2 * cardinal(gtk_widget_get_xthickness(gtk_bin_get_child(PGTKBin(popup)))));
work_height := (2 * cardinal(gtk_widget_get_ythickness(gtk_bin_get_child(popwin))) +
2 * border_width(GTK_CONTAINER (gtk_bin_get_child(popwin))^) +
2 * border_width(GTK_CONTAINER (combo^.popup)^) +
2 * border_width(GTK_CONTAINER (gtk_bin_get_child(PGTKBin(popup)))^) +
2 * cardinal(gtk_widget_get_xthickness(gtk_bin_get_child(PGTKBin(popup)))));
repeat
okay_to_exit := True;
old_width := alloc_width;
old_height := work_height;
if ((not show_hscroll) and (alloc_width < list_requisition^.width)) then
begin
work_height := work_height + popup^.hscrollbar^.requisition.height +
GTK_SCROLLED_WINDOW_CLASS(gtk_object_get_class(combo^.popup))^.scrollbar_spacing;
show_hscroll := TRUE;
okay_to_exit := False;
end;
if ((not show_vscroll) and (work_height + list_requisition^.height > avail_height)) then
begin
if ((work_height + min_height > avail_height) and (y - real_height > avail_height)) then
begin
y := y - (work_height + list_requisition^.height + real_height);
break;
end;
alloc_width := alloc_width -
popup^.vscrollbar^.requisition.width +
GTK_SCROLLED_WINDOW_CLASS(gtk_object_get_class(combo^.popup))^.scrollbar_spacing;
show_vscroll := TRUE;
okay_to_exit := False;
end;
until ((old_width <> alloc_width) or (old_height <> work_height) or okay_to_exit);
width := widget^.allocation.width;
if (show_vscroll) then
height := avail_height
else
height := work_height + list_requisition^.height;
if (x < 0) then
x := 0;
Dispose(list_requisition);
end;
var
ComboWidget: PGtkCombo;
height, width, x, y : gint;
old_width, old_height : gint;
begin
if not WSCheckHandleAllocated(ACustomComboBox, 'SetDroppedDown') then Exit;
ComboWidget:=PGtkCombo(ACustomComboBox.Handle);
if ADroppedDown<>GTK_WIDGET_VISIBLE(ComboWidget^.popwin) then begin
if ADroppedDown then begin
old_width := ComboWidget^.popwin^.allocation.width;
old_height := ComboWidget^.popwin^.allocation.height;
gtk_combo_get_pos(ComboWidget,x,y,height,width);
if ((old_width <> width) or (old_height <> height)) then
begin
gtk_widget_hide (GTK_SCROLLED_WINDOW(ComboWidget^.popup)^.hscrollbar);
gtk_widget_hide (GTK_SCROLLED_WINDOW(ComboWidget^.popup)^.vscrollbar);
end;
gtk_widget_set_uposition (comboWidget^.popwin,x, y);
gtk_widget_set_usize(ComboWidget^.popwin,width ,height);
gtk_widget_realize(ComboWidget^.popwin);
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
gdk_window_resize(ComboWidget^.popwin^.window,width,height);
{$IFDEF DebugGDKTraps}
EndGDKErrorTrap;
{$ENDIF}
gtk_widget_show (ComboWidget^.popwin);
gtk_widget_grab_focus(ComboWidget^.popwin);
end else
gtk_widget_hide (ComboWidget^.popwin);
end;
end;
class procedure TGtkWSCustomComboBox.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
with TGtkWidgetset(Widgetset) do
begin
//gtk1 and gtk2 have different 'changed' event handlers
g_signal_connect(PGtkObject(PGtkCombo(AGtkWidget)^.entry),
'changed', TGTKSignalFunc(@gtkComboBoxChanged), AWidgetInfo);
g_signal_connect(PGtkObject(PGtkCombo(AGtkWidget)^.popwin),
'hide', TGTKSignalFunc(@gtkComboBoxChanged), AWidgetInfo);
SetCallback(LM_COMMAND, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
end;
class function TGtkWSCustomComboBox.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
ComboBox: TComboBox absolute AWinControl;
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
ComboWidget: PGtkCombo absolute Widget;
ItemList: TGtkListStringList;
GtkList: PGtkList;
Allocation: TGtkAllocation;
LCLIndex: PInteger;
begin
Widget := gtk_combo_new();
SetMainWidget(Widget, ComboWidget^.entry);
SetMainWidget(Widget, ComboWidget^.button);
gtk_combo_disable_activate(ComboWidget);
gtk_combo_set_case_sensitive(ComboWidget, GdkTrue);
GtkList:=PGtkList(ComboWidget^.List);
// Items
ItemList:= TGtkListStringList.Create(GtkList, ComboBox, False);
gtk_object_set_data(PGtkObject(Widget), GtkListItemLCLListTag, ItemList);
ItemList.Assign(ComboBox.Items);
ItemList.Sorted:= ComboBox.Sorted;
WidgetInfo := CreateWidgetInfo(Widget, AWinControl, AParams);
New(LCLIndex);
WidgetInfo^.UserData := LCLIndex;
WidgetInfo^.DataOwner := True;
// ItemIndex
// Switching the selection mode is necessary to avoid the following problems:
// - The first added item is automatically selected when mode is "BROWSE"
// - Is not possible to select the previous selected item if mode is "BROWSE"
// and current index is -1
// - The item is deselected after a second click if mode is "SINGLE"
// - The OnSelect event could be fired after add the first item when mode is
// "BROWSE". Since LM_SELCHANGE is sent in 'changed' event now, no problem.
// So basically the mode is set to BROWSE when a item is selected and
// "SINGLE" when there's no item selected
if ComboBox.ItemIndex >= 0 then
begin
gtk_list_set_selection_mode(GtkList, GTK_SELECTION_BROWSE);
gtk_list_select_item(GtkList, ComboBox.ItemIndex);
LCLIndex^ := ComboBox.ItemIndex;
end
else
begin
gtk_list_set_selection_mode(GtkList, GTK_SELECTION_SINGLE);
LCLIndex^ := -1;
end;
// MaxLength
gtk_entry_set_max_length(PGtkEntry(ComboWidget^.entry),guint16(ComboBox.MaxLength));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLHandle(Widget);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(Widget, @Allocation);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
class function TGtkWSCustomComboBox.GetSelStart(
const ACustomComboBox: TCustomComboBox): integer;
begin
Result := WidgetGetSelStart(PGtkWidget(PGtkCombo(ACustomComboBox.Handle
)^.entry));
end;
class function TGtkWSCustomComboBox.GetSelLength(
const ACustomComboBox: TCustomComboBox): integer;
begin
with PGtkOldEditable(PGtkCombo(ACustomComboBox.Handle)^.entry)^ do begin
Result:= Abs(integer(selection_end_pos)-integer(selection_start_pos));
end;
end;
class function TGtkWSCustomComboBox.GetText(const AWinControl: TWinControl;
var AText: String): Boolean;
begin
//DebugLn('TGtkWSCustomComboBox.GetText ',DbgSName(ACustomComboBox),' ',GetWidgetDebugReport(PGtkWidget(ACustomComboBox.Handle)));
AText := gtk_entry_get_text(PGtkEntry(PGtkCombo(AWinControl.Handle)^.entry));
//if AWinControl.Name='FileExtensionsComboBox' then
// DebugLn('TGtkWSCustomComboBox.GetText ',DbgSName(AWinControl),' ',GetWidgetDebugReport(PGtkWidget(AWinControl.Handle)),' AText="',AText,'"');
Result:=true;
end;
class function TGtkWSCustomComboBox.GetItemIndex(
const ACustomComboBox: TCustomComboBox): integer;
var
ListWidget: PGtkList;
begin
//DebugLn('TGtkWSCustomComboBox.GetItemIndex ',DbgSName(ACustomComboBox),' ',GetWidgetDebugReport(PGtkWidget(ACustomComboBox.Handle)));
ListWidget := PGtkList(PGtkCombo(ACustomComboBox.Handle)^.list);
if ListWidget^.selection <> nil then
Result := gtk_list_child_position(ListWidget, ListWidget^.selection^.data)
else
Result := -1;
end;
class function TGtkWSCustomComboBox.GetMaxLength(
const ACustomComboBox: TCustomComboBox): integer;
begin
Result:= PGtkEntry(PGtkCombo(ACustomComboBox.Handle)^.entry)^.text_max_length;
end;
class procedure TGtkWSCustomComboBox.SetArrowKeysTraverseList(
const ACustomComboBox: TCustomComboBox;
NewTraverseList: boolean);
var
GtkCombo: PGtkCombo;
begin
GtkCombo := GTK_COMBO(Pointer(ACustomComboBox.Handle));
if ACustomComboBox.ArrowKeysTraverseList then
begin
gtk_combo_set_use_arrows(GtkCombo,GdkTrue);
end else
begin
gtk_combo_set_use_arrows(GtkCombo,GdkFalse);
end;
end;
class procedure TGtkWSCustomComboBox.SetSelStart(
const ACustomComboBox: TCustomComboBox; NewStart: integer);
begin
if NewStart < 0 then NewStart := 0; // prevent SegFault in gtk
gtk_editable_set_position(
PGtkOldEditable(PGtkCombo(ACustomComboBox.Handle)^.entry), NewStart);
end;
class procedure TGtkWSCustomComboBox.SetSelLength(
const ACustomComboBox: TCustomComboBox; NewLength: integer);
begin
WidgetSetSelLength(PGtkCombo(ACustomComboBox.Handle)^.entry, NewLength);
end;
class procedure TGtkWSCustomComboBox.SetItemIndex(
const ACustomComboBox: TCustomComboBox; NewIndex: integer);
var
ComboWidget: PGtkCombo;
WidgetInfo: PWidgetInfo;
begin
ComboWidget := PGtkCombo(ACustomComboBox.Handle);
WidgetInfo := GetWidgetInfo(ComboWidget);
//Store the LCLIndex
PInteger(WidgetInfo^.UserData)^ := NewIndex;
//Avoid calling OnChange/OnSelect events
Inc(WidgetInfo^.ChangeLock);
//gtk_list_select_item does not update the list when Index is -1
if NewIndex > -1 then
begin
gtk_list_set_selection_mode(PGtkList(ComboWidget^.list),
GTK_SELECTION_BROWSE);
gtk_list_select_item(PGtkList(ComboWidget^.list), NewIndex);
end
else
begin
gtk_list_set_selection_mode(PGtkList(ComboWidget^.list),
GTK_SELECTION_SINGLE);
gtk_entry_set_text(PGtkEntry(ComboWidget^.entry), '');
end;
Dec(WidgetInfo^.ChangeLock);
end;
class procedure TGtkWSCustomComboBox.SetMaxLength(
const ACustomComboBox: TCustomComboBox; NewLength: integer);
begin
gtk_entry_set_max_length(PGtkEntry(PGtkCombo(ACustomComboBox.Handle)^.entry),
guint16(NewLength));
end;
class procedure TGtkWSCustomComboBox.SetStyle(
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
var
GtkCombo: PGtkCombo;
begin
GtkCombo := GTK_COMBO(Pointer(ACustomComboBox.Handle));
if not ACustomComboBox.Style.HasEditBox then
begin
// do not set ok_if_empty = true, otherwise it can hang focus
gtk_combo_set_value_in_list(GtkCombo,GdkTrue,GdkTrue);
gtk_combo_set_use_arrows_always(GtkCombo,GdkTrue);
gtk_combo_set_case_sensitive(GtkCombo,GdkFalse);
end
else
begin
// do not set ok_if_empty = true, otherwise it can hang focus
gtk_combo_set_value_in_list(GtkCombo,GdkFalse,GdkTrue);
gtk_combo_set_use_arrows_always(GtkCombo,GdkFalse);
gtk_combo_set_case_sensitive(GtkCombo,GdkTrue);
end;
end;
class procedure TGtkWSCustomComboBox.SetText(const AWinControl: TWinControl;
const AText: String);
var
ComboControl: TCustomComboBox absolute AWinControl;
ComboWidget: PGtkCombo;
WidgetInfo: PWidgetInfo;
i: Integer;
begin
if ComboControl.ReadOnly then
begin
i := ComboControl.Items.IndexOf(AText);
TGtkWSCustomComboBox.SetItemIndex(ComboControl, i);
end
else
begin
ComboWidget := PGtkCombo(AWinControl.Handle);
WidgetInfo := GetWidgetInfo(ComboWidget);
// lock combobox, so that no OnChange event is not fired
Inc(WidgetInfo^.ChangeLock);
// set text
// The String > PChar conversion ensures at least a null terminated string
gtk_entry_set_text(PGtkEntry(ComboWidget^.entry), PChar(AText));
// unlock combobox
Dec(WidgetInfo^.ChangeLock);
end;
end;
class function TGtkWSCustomComboBox.GetItems(
const ACustomComboBox: TCustomComboBox): TStrings;
begin
Result := TStrings(gtk_object_get_data(PGtkObject(ACustomComboBox.Handle),
GtkListItemLCLListTag));
end;
class procedure TGtkWSCustomComboBox.Sort(const ACustomComboBox: TCustomComboBox;
AList: TStrings; IsSorted: boolean);
begin
TGtkListStringList(AList).Sorted := IsSorted;
end;
class procedure TGtkWSCustomComboBox.SetColor(const AWinControl: TWinControl);
var
AWidget, EntryWidget: PGTKWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
AWidget := PGtkWidget(AWinControl.Handle);
EntryWidget := PGtkCombo(AWidget)^.entry;
GtkWidgetSet.SetWidgetColor(EntryWidget, AWinControl.Font.Color, AWinControl.Color,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED,GTK_STYLE_BASE]);
end;
class procedure TGtkWSCustomComboBox.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
AWidget: PGTKWidget;
EntryWidget: PGtkWidget;
begin
if not AWinControl.HandleAllocated then exit;
AWidget := PGtkWidget(AWinControl.Handle);
EntryWidget := PGtkCombo(AWidget)^.entry;
if EntryWidget<>nil then
begin
GtkWidgetSet.SetWidgetColor(EntryWidget, AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
GtkWidgetSet.SetWidgetFont(EntryWidget, AFont);
end;
end;
{$ENDIF}
{ TGtkWSCustomEdit }
class procedure TGtkWSCustomEdit.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
with TGtkWidgetset(Widgetset) do
begin
SetCallback(LM_CHANGED, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_ACTIVATE, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_CUT, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_COPY, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_PASTE, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
end;
class function TGtkWSCustomEdit.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Widget: PGtkWidget; // ptr to the newly created GtkWidget
WidgetInfo: PWidgetInfo;
begin
Widget := gtk_entry_new();
gtk_editable_set_editable(PGtkEditable(Widget), not TCustomEdit(AWinControl).ReadOnly);
gtk_widget_show_all(Widget);
Result := TLCLHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
if Result = 0 then
Exit;
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
class function TGtkWSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit): integer;
begin
Result := WidgetGetSelStart(GetWidgetInfo(Pointer(ACustomEdit.Handle),
true)^.CoreWidget);
end;
class function TGtkWSCustomEdit.GetSelLength(const ACustomEdit: TCustomEdit): integer;
begin
with PGtkOldEditable(GetWidgetInfo(Pointer(ACustomEdit.Handle), true)^.
CoreWidget)^ do
begin
Result:=Abs(integer(selection_end_pos)-integer(selection_start_pos));
end;
end;
class procedure TGtkWSCustomEdit.SetCharCase(const ACustomEdit: TCustomEdit;
NewCase: TEditCharCase);
begin
// TODO: implement me!
end;
class procedure TGtkWSCustomEdit.SetEchoMode(const ACustomEdit: TCustomEdit;
NewMode: TEchoMode);
begin
// XXX TODO: GTK 1.x does not support EchoMode emNone.
// This will have to be coded around, but not a priority
SetPasswordChar(ACustomEdit, ACustomEdit.PasswordChar);
end;
class procedure TGtkWSCustomEdit.SetMaxLength(const ACustomEdit: TCustomEdit;
NewLength: integer);
var
Widget: PGtkWidget;
begin
Widget:=PGtkWidget(ACustomEdit.Handle);
if GtkWidgetIsA(Widget, GTK_TYPE_ENTRY) then
gtk_entry_set_max_length(GTK_ENTRY(Widget), guint16(NewLength));
end;
class procedure TGtkWSCustomEdit.SetPasswordChar(const ACustomEdit: TCustomEdit;
NewChar: char);
var
Widget: PGtkWidget;
begin
Widget:=PGtkWidget(ACustomEdit.Handle);
if GtkWidgetIsA(Widget, GTK_TYPE_ENTRY) then
gtk_entry_set_visibility(GTK_ENTRY(Widget),
(ACustomEdit.EchoMode = emNormal) and (NewChar = #0));
end;
class procedure TGtkWSCustomEdit.SetReadOnly(const ACustomEdit: TCustomEdit;
NewReadOnly: boolean);
var
Widget: PGtkWidget;
begin
Widget := PGtkWidget(ACustomEdit.Handle);
if GtkWidgetIsA(Widget, GTK_TYPE_ENTRY) then
gtk_entry_set_editable(GTK_ENTRY(Widget), not NewReadOnly);
end;
class procedure TGtkWSCustomEdit.SetSelStart(const ACustomEdit: TCustomEdit;
NewStart: integer);
var
Widget: PGtkWidget;
MaxPos: Integer;
begin
Widget:=GetWidgetInfo(Pointer(ACustomEdit.Handle), true)^.CoreWidget;
if WidgetGetSelStart(Widget)=NewStart then exit;
// sometimes the gtk freezes the memo, changes something and emits the change
// event. Then the LCL gets notified and wants to react: force thaw (unfreeze)
if GTK_IS_TEXT(Widget) then
begin
gtk_text_thaw(PGtkText(Widget));
MaxPos := gtk_text_get_length(PGtkText(Widget));
end
else
if GTK_IS_ENTRY(Widget) then
MaxPos := PGtkEntry(Widget)^.text_length
else
MaxPos := 0;
gtk_editable_set_position(PGtkOldEditable(Widget), Min(NewStart, MaxPos));
WidgetSetSelLength(Widget,0); // Setting the selection start should cancel any selection
end;
class procedure TGtkWSCustomEdit.SetSelLength(const ACustomEdit: TCustomEdit;
NewLength: integer);
begin
WidgetSetSelLength(GetWidgetInfo(Pointer(ACustomEdit.Handle),true)^.CoreWidget,
NewLength);
end;
class procedure TGtkWSCustomEdit.SetText(const AWinControl: TWinControl;
const AText: string);
var
Widget: PGtkWidget;
Mess : TLMessage;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetText') then
Exit;
{$IFDEF VerboseTWinControlRealText}
DebugLn(['TGtkWSCustomEdit.SetText START ',DbgSName(AWinControl),' AText="',AText,'"']);
{$ENDIF}
Widget:=PGtkWidget(AWinControl.Handle);
// some gtk2 versions fire the change event twice
// lock the event and send the message afterwards
// see bug http://bugs.freepascal.org/view.php?id=14615
LockOnChange(PgtkObject(Widget), +1);
try
gtk_entry_set_text(PGtkEntry(Widget), PChar(AText));
finally
LockOnChange(PgtkObject(Widget), -1);
end;
{$IFDEF VerboseTWinControlRealText}
DebugLn(['TGtkWSCustomEdit.SetText SEND TEXTCHANGED message ',DbgSName(AWinControl),' New="',gtk_entry_get_text(PGtkEntry(AWinControl.Handle)),'"']);
{$ENDIF}
FillByte(Mess,SizeOf(Mess),0);
Mess.Msg := CM_TEXTCHANGED;
DeliverMessage(AWinControl, Mess);
{$IFDEF VerboseTWinControlRealText}
DebugLn(['TGtkWSCustomEdit.SetText END ',DbgSName(AWinControl),' New="',gtk_entry_get_text(PGtkEntry(AWinControl.Handle)),'"']);
{$ENDIF}
end;
class procedure TGtkWSCustomEdit.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
begin
GetGTKDefaultWidgetSize(AWinControl,PreferredWidth,PreferredHeight,
WithThemeSpace);
//debugln('TGtkWSCustomEdit.GetPreferredSize ',DbgSName(AWinControl),' PreferredWidth=',dbgs(PreferredWidth),' PreferredHeight=',dbgs(PreferredHeight));
end;
class procedure TGtkWSCustomEdit.SetColor(const AWinControl: TWinControl);
var
AWidget: PGTKWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
AWidget := PGtkWidget(AWinControl.Handle);
// don't change selected state
GtkWidgetSet.SetWidgetColor(AWidget, clNone, AWinControl.Color,
[GTK_STATE_NORMAL, GTK_STYLE_BASE]);
end;
{ TGtkWSCustomStaticText }
class function TGtkWSCustomStaticText.GetLabelWidget(AFrame: PGtkFrame): PGtkLabel;
begin
{$IFDEF GTK2}
Result := PGtkLabel(PGtkBin(GetBoxWidget(AFrame))^.child);
{$ELSE}
Result := PGtkLabel(GetBoxWidget(AFrame)^.bin.child);
{$ENDIF}
end;
class function TGtkWSCustomStaticText.GetBoxWidget(AFrame: PGtkFrame): PGtkEventBox;
begin
{$IFDEF GTK2}
Result := PGtkEventBox(PGtkBin(AFrame)^.child);
{$ELSE}
Result := PGtkEventBox(AFrame^.bin.Child);
{$ENDIF}
end;
class function TGtkWSCustomStaticText.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams
): TLCLHandle;
var
AStaticText: TCustomStaticText;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
EventBox, LblWidget: PGtkWidget;
begin
// TStaticText control is a Text area with frame around. Both Text and Area around
// text can have their own color
// To implement that in gtk we need:
// 1. GtkLabel to handle Text
// 2. GtkEventBox to draw color area around GtkLabel (since GtkLabel have no window)
// 3. GtkFrame to draw frame around Text area
// GtkFrame is our main widget - it is container and it contains GtkEventBox
// GtkEventBox is also containter and it contains GtkLabel
AStaticText := AWinControl as TCustomStaticText;
Result := TLCLHandle(PtrUInt(gtk_frame_new(nil))); // frame is the main container - to decorate label
if Result = 0 then Exit;
gtk_frame_set_shadow_type(PGtkFrame(Result), StaticBorderShadowMap[AStaticText.BorderStyle]);
EventBox := gtk_event_box_new; // our area
LblWidget := gtk_label_new(PChar(TCustomStaticText(AWinControl).Caption)); // our text widget
gtk_container_add(PGtkContainer(EventBox), LblWidget);
SetLabelAlignment(PGtkLabel(LblWidget), AStaticText.Alignment);
gtk_widget_show(LblWidget);
gtk_widget_show(EventBox);
gtk_container_add(PGtkContainer(Result), EventBox);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Pointer(Result), dbgsName(AWinControl));
{$ENDIF}
WidgetInfo := CreateWidgetInfo(Pointer(Result), AStaticText, AParams);
WidgetInfo^.CoreWidget := EventBox;
gtk_object_set_data(PGtkObject(EventBox), 'widgetinfo', WidgetInfo);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(PGtkWidget(Result), @Allocation);
Set_RC_Name(AWinControl, PGtkWidget(Result));
SetCallbacks(PGtkWidget(Result), WidgetInfo);
end;
class procedure TGtkWSCustomStaticText.SetAlignment(const ACustomStaticText: TCustomStaticText;
const NewAlignment: TAlignment);
var
LblWidget: PGtkLabel;
begin
if not WSCheckHandleAllocated(ACustomStaticText, 'SetAlignment')
then Exit;
LblWidget := GetLabelWidget(PGtkFrame(ACustomStaticText.Handle));
SetLabelAlignment(LblWidget, NewAlignment);
end;
class procedure TGtkWSCustomStaticText.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
begin
GetGTKDefaultWidgetSize(AWinControl, PreferredWidth, PreferredHeight,
WithThemeSpace);
//debugln('TGtkWSCustomStaticText.GetPreferredSize ',DbgSName(AWinControl),' PreferredWidth=',dbgs(PreferredWidth),' PreferredHeight=',dbgs(PreferredHeight));
end;
class function TGtkWSCustomStaticText.GetText(const AWinControl: TWinControl;
var AText: String): Boolean;
begin
// The text is static, so let the LCL fallback to FCaption
Result := False;
end;
class procedure TGtkWSCustomStaticText.SetText(const AWinControl: TWinControl;
const AText: String);
var
FrameWidget: PGtkFrame;
LblWidget: PGtkLabel;
DC: HDC;
ALabel: PChar;
begin
if not WSCheckHandleAllocated(AWincontrol, 'SetText')
then Exit;
FrameWidget := PGtkFrame(AWinControl.Handle);
LblWidget := GetLabelWidget(FrameWidget);
if TStaticText(AWinControl).ShowAccelChar then
begin
DC := Widgetset.GetDC(HWND(PtrUInt(LblWidget)));
ALabel := TGtkWidgetSet(WidgetSet).ForceLineBreaks(
DC, PChar(AText), TStaticText(AWinControl).Width, false);
Widgetset.DeleteDC(DC);
GtkWidgetSet.SetLabelCaption(LblWidget, ALabel
{$IFDEF Gtk1}, AWinControl, PGtkWidget(FrameWidget), 'grab_focus'{$ENDIF});
StrDispose(ALabel);
end else
begin
gtk_label_set_text(LblWidget, PChar(AText));
gtk_label_set_pattern(LblWidget, nil);
end;
end;
class procedure TGtkWSCustomStaticText.SetStaticBorderStyle(
const ACustomStaticText: TCustomStaticText;
const NewBorderStyle: TStaticBorderStyle);
begin
if not WSCheckHandleAllocated(ACustomStaticText, 'SetStaticBorderStyle')
then Exit;
gtk_frame_set_shadow_type(PGtkFrame(ACustomStaticText.Handle), StaticBorderShadowMap[NewBorderStyle]);
end;
class procedure TGtkWSCustomStaticText.SetCallbacks(
const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
SignalConnect(AGtkWidget, 'grab_focus', @gtkActivateCB, AWidgetInfo);
end;
class procedure TGtkWSCustomStaticText.SetColor(const AWinControl: TWinControl);
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
GtkWidgetSet.SetWidgetColor(PGtkWidget(GetBoxWidget(PGtkFrame(AWinControl.Handle))),
clNone, AWinControl.Color,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,
GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
end;
class procedure TGtkWSCustomStaticText.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
Widget: PGtkWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetFont')
then Exit;
Widget := PGtkWidget(GetLabelWidget(PGtkFrame(AWinControl.Handle)));
GtkWidgetSet.SetWidgetColor(Widget, AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
GtkWidgetSet.SetWidgetFont(Widget, AFont);
end;
{ TGtkWSButton }
function GtkWSButton_Clicked(AWidget: PGtkWidget; AInfo: PWidgetInfo): GBoolean; cdecl;
var
Msg: TLMessage;
begin
Result := CallBackDefaultReturn;
if AInfo^.ChangeLock > 0 then Exit;
Msg.Msg := LM_CLICKED;
Result := DeliverMessage(AInfo^.LCLObject, Msg) = 0;
end;
class procedure TGtkWSButton.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
SignalConnect(AGtkWidget, 'clicked', @GtkWSButton_Clicked, AWidgetInfo);
end;
{$IFDEF Gtk1}
class function TGtkWSButton.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Button: TCustomButton;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
Button := AWinControl as TCustomButton;
Result := TLCLHandle(PtrUInt(gtk_button_new_with_label('button')));
if Result = 0 then Exit;
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Pointer(Result),'button');
{$ENDIF}
WidgetInfo := CreateWidgetInfo(Pointer(Result), Button, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(PGtkWidget(Result), @Allocation);
Set_RC_Name(AWinControl, PGtkWidget(Result));
SetCallbacks(PGtkWidget(Result), WidgetInfo);
end;
class function TGtkWSButton.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
begin
// The button text is static, so let the LCL fallback to FCaption
Result := False;
end;
class procedure TGtkWSButton.SetDefault(const AButton: TCustomButton; ADefault: Boolean);
begin
if not WSCheckHandleAllocated(AButton, 'SetDefault')
then Exit;
if ADefault
and (GTK_WIDGET_CAN_DEFAULT(pgtkwidget(AButton.Handle))) then
//gtk_widget_grab_default(pgtkwidget(handle))
else begin
{DebugLn('LM_BTNDEFAULT_CHANGED ',TCustomButton(Sender).Name,':',Sender.ClassName,' widget can not grab default ',
' visible=',GTK_WIDGET_VISIBLE(PGtkWidget(Handle)),
' realized=',GTK_WIDGET_REALIZED(PGtkWidget(Handle)),
' mapped=',GTK_WIDGET_MAPPED(PGtkWidget(Handle)),
'');}
// gtk_widget_Draw_Default(pgtkwidget(Handle)); //this isn't right but I'm not sure what to call
end;
end;
class procedure TGtkWSButton.SetShortcut(const AButton: TCustomButton; const ShortCutK1, ShortCutK2: TShortcut);
begin
if not WSCheckHandleAllocated(AButton, 'SetShortcut')
then Exit;
{$IFDEF Gtk1}
Accelerate(AButton, PGtkWidget(AButton.Handle), ShortCutK1, 'clicked');
{$ENDIF}
// gtk2: shortcuts are handled by the LCL
end;
class procedure TGtkWSButton.SetText(const AWinControl: TWinControl; const AText: String);
var
BtnWidget: PGtkButton;
LblWidget: PGtkLabel;
begin
if not WSCheckHandleAllocated(AWincontrol, 'SetText')
then Exit;
BtnWidget := PGtkButton(AWinControl.Handle);
{$IFDEF GTK2}
LblWidget := PGtkLabel(PGtkBin(BtnWidget)^.Child);
{$ELSE}
LblWidget := PGtkLabel(BtnWidget^.Child);
{$ENDIF}
if LblWidget = nil
then begin
//DebugLn(Format('trace: [WARNING] Button %s(%s) has no label', [AWinControl.Name, AWinControl.ClassName]));
LblWidget := PGtkLabel(gtk_label_new(''));
gtk_container_add(PGtkContainer(BtnWidget), PGtkWidget(LblWidget));
end;
GtkWidgetSet.SetLabelCaption(LblWidget, AText
{$IFDEF Gtk1}, AWinControl,PGtkWidget(BtnWidget), 'clicked'{$ENDIF});
end;
class procedure TGtkWSButton.SetColor(const AWinControl: TWinControl);
var
Widget: PGTKWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
Widget := PGtkWidget(AWinControl.Handle);
GtkWidgetSet.SetWidgetColor(Widget, clNone, AWinControl.Color,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
end;
class procedure TGtkWSButton.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
Widget: PGTKWidget;
LblWidget: PGtkWidget;
begin
if not AWinControl.HandleAllocated then exit;
Widget:= PGtkWidget(AWinControl.Handle);
LblWidget := (pGtkBin(Widget)^.Child);
if LblWidget <> nil then
begin
GtkWidgetSet.SetWidgetColor(LblWidget, AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
GtkWidgetSet.SetWidgetFont(LblWidget, AFont);
end;
end;
class procedure TGtkWSButton.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
begin
GetGTKDefaultWidgetSize(AWinControl,PreferredWidth,PreferredHeight,
WithThemeSpace);
//debugln('TGtkWSButton.GetPreferredSize ',DbgSName(AWinControl),' PreferredWidth=',dbgs(PreferredWidth),' PreferredHeight=',dbgs(PreferredHeight));
end;
{$ENDIF Gtk1}
{ TGtkWSCustomCheckBox }
class procedure TGtkWSCustomCheckBox.SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
TGtkWidgetset(WidgetSet).SetCallback(LM_CHANGED, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
{$IFDEF Gtk1}
class function TGtkWSCustomCheckBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams
): TLCLHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
Widget := gtk_check_button_new_with_label(AParams.Caption);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLHandle(Widget);
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(PGtkWidget(Result), @Allocation);
Set_RC_Name(AWinControl, PGtkWidget(Result));
SetCallbacks(PGtkWidget(Result), WidgetInfo);
end;
class function TGtkWSCustomCheckBox.RetrieveState(
const ACustomCheckBox: TCustomCheckBox): TCheckBoxState;
var
ToggleButton: PGtkToggleButton;
begin
ToggleButton:=PGtkToggleButton(ACustomCheckBox.Handle);
if (gtk_object_get_data(PgtkObject(ToggleButton),'Grayed')<>nil) then
Result:=cbGrayed
else if gtk_toggle_button_get_active(ToggleButton) then
Result := cbChecked
else
Result := cbUnChecked;
end;
class procedure TGtkWSCustomCheckBox.SetShortCut(
const ACustomCheckBox: TCustomCheckBox; const ShortCutK1, ShortCutK2: TShortCut);
begin
Accelerate(ACustomCheckBox, PGtkWidget(ACustomCheckBox.Handle), ShortCutK1,
'activate_item');
end;
class procedure TGtkWSCustomCheckBox.SetState(const ACB: TCustomCheckBox;
const ANewState: TCheckBoxState);
var
GtkObject: PGtkObject;
begin
if not WSCheckHandleAllocated(ACB, 'SetState')
then Exit;
GtkObject := PGtkObject(ACB.Handle);
LockOnChange(GtkObject,1);
if ANewState=cbGrayed then
gtk_object_set_data(GtkObject, 'Grayed', GtkObject)
else
gtk_object_set_data(GtkObject, 'Grayed', nil);
gtk_toggle_button_set_active(PGtkToggleButton(GtkObject), ANewState = cbChecked);
LockOnChange(GtkObject,-1);
end;
class procedure TGtkWSCustomCheckBox.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
begin
GetGTKDefaultWidgetSize(AWinControl,PreferredWidth,PreferredHeight,
WithThemeSpace);
//debugln('TGtkWSCustomCheckBox.GetPreferredSize ',DbgSName(AWinControl),' PreferredWidth=',dbgs(PreferredWidth),' PreferredHeight=',dbgs(PreferredHeight));
end;
class procedure TGtkWSCustomCheckBox.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
Widget: PGTKWidget;
LblWidget: PGtkWidget;
begin
if not AWinControl.HandleAllocated then exit;
Widget:= PGtkWidget(AWinControl.Handle);
LblWidget := (pGtkBin(Widget)^.Child);
if LblWidget<>nil then
begin
GtkWidgetSet.SetWidgetColor(LblWidget, AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
GtkWidgetSet.SetWidgetFont(LblWidget, AFont);
end;
end;
{$ENDIF}
{ TGtkWSCustomMemo }
{$ifdef GTK1}
class procedure TGtkWSCustomMemo.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
with TGtkWidgetset(Widgetset) do
begin
SetCallback(LM_CHANGED, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_ACTIVATE, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_CUT, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_COPY, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_PASTE, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
end;
class function TGtkWSCustomMemo.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
P: Pointer;
TempWidget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
P := gtk_scrolled_window_new(nil, nil);
TempWidget := gtk_text_new(nil, nil);
gtk_container_add(p, TempWidget);
GTK_WIDGET_UNSET_FLAGS(PGtkScrolledWindow(p)^.hscrollbar, GTK_CAN_FOCUS);
GTK_WIDGET_UNSET_FLAGS(PGtkScrolledWindow(p)^.vscrollbar, GTK_CAN_FOCUS);
gtk_scrolled_window_set_policy(PGtkScrolledWindow(p),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_text_set_adjustments(PGtkText(TempWidget),
gtk_scrolled_window_get_hadjustment(PGtkScrolledWindow(p)),
gtk_scrolled_window_get_vadjustment(PGtkScrolledWindow(p)));
WidgetInfo := CreateWidgetInfo(P, AWinControl, AParams);
SetMainWidget(p, TempWidget);
WidgetInfo^.CoreWidget := TempWidget;
gtk_text_set_editable (PGtkText(TempWidget), not TCustomMemo(AWinControl).ReadOnly);
if TCustomMemo(AWinControl).WordWrap then
gtk_text_set_line_wrap(PGtkText(TempWidget), GdkTrue)
else
gtk_text_set_line_wrap(PGtkText(TempWidget), GdkFalse);
gtk_text_set_word_wrap(PGtkText(TempWidget), GdkTrue);
gtk_widget_show_all(P);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P,dbgsName(AWinControl));
{$ENDIF}
Result := TLCLHandle(PtrUInt(P));
//DebugLn(['TGtkWSCustomMemo.CreateHandle ']);
Set_RC_Name(AWinControl, P);
SetCallbacks(P, WidgetInfo);
end;
class procedure TGtkWSCustomMemo.AppendText(const ACustomMemo: TCustomMemo;
const AText: string);
var
Widget: PGtkWidget;
CurMemoLen: gint;
begin
if Length(AText) = 0 then
exit;
Widget:=GetWidgetInfo(Pointer(ACustomMemo.Handle), true)^.CoreWidget;
gtk_text_freeze(PGtkText(Widget));
CurMemoLen := gtk_text_get_length(PGtkText(Widget));
//debugln('TGtkWSCustomMemo.AppendText "',AText,'" CurMemoLen=',dbgs(CurMemoLen));
gtk_editable_insert_text(PGtkOldEditable(Widget), PChar(AText), Length(AText),
@CurMemoLen);
//debugln('TGtkWSCustomMemo.AppendText B CurMemoLen=',dbgs(CurMemoLen));
gtk_text_thaw(PGtkText(Widget));
end;
class function TGtkWSCustomMemo.GetStrings(const ACustomMemo: TCustomMemo): TStrings;
var
Widget: PGtkText;
begin
Widget:=PGtkText(GetWidgetInfo(Pointer(ACustomMemo.Handle), true)^.CoreWidget);
Result:=TGtkMemoStrings.Create(Widget, ACustomMemo);
end;
class procedure TGtkWSCustomMemo.SetEchoMode(const ACustomEdit: TCustomEdit;
NewMode: TEchoMode);
begin
// no password char in memo
end;
class procedure TGtkWSCustomMemo.SetMaxLength(const ACustomEdit: TCustomEdit;
NewLength: integer);
var
ImplWidget: PGtkWidget;
i: integer;
begin
if (ACustomEdit.MaxLength > 0) then
begin
ImplWidget := GetWidgetInfo(PGtkWidget(ACustomEdit.Handle), true)^.CoreWidget;
i := gtk_text_get_length(GTK_TEXT(ImplWidget));
if i > ACustomEdit.MaxLength then
gtk_editable_delete_text(PGtkOldEditable(ImplWidget),
ACustomEdit.MaxLength, i);
end;
end;
class procedure TGtkWSCustomMemo.SetPasswordChar(const ACustomEdit: TCustomEdit;
NewChar: char);
begin
// no password char in memo
end;
class procedure TGtkWSCustomMemo.SetReadOnly(const ACustomEdit: TCustomEdit;
NewReadOnly: boolean);
var
ImplWidget : PGtkWidget;
begin
ImplWidget:= GetWidgetInfo(PGtkWidget(ACustomEdit.Handle), true)^.CoreWidget;
gtk_text_set_editable (GTK_TEXT(ImplWidget), not ACustomEdit.ReadOnly);
end;
class procedure TGtkWSCustomMemo.SetColor(const AWinControl: TWinControl);
var
AWidget: PGTKWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
AWidget := PGtkWidget(AWinControl.Handle);
AWidget := GetWidgetInfo(AWidget, true)^.CoreWidget;
GtkWidgetSet.SetWidgetColor(AWidget, clNone, AWinControl.Color,
[GTK_STATE_NORMAL, GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, GTK_STATE_SELECTED,
GTK_STYLE_BASE]);
end;
class procedure TGtkWSCustomMemo.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
AWidget: PGTKWidget;
begin
if not AWinControl.HandleAllocated then exit;
AWidget:= PGtkWidget(AWinControl.Handle);
AWidget:= GetWidgetInfo(AWidget, true)^.CoreWidget;
if AWidget<>nil then begin
GtkWidgetSet.SetWidgetColor(AWidget, AFont.Color, clNone,
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED,
GTK_STYLE_TEXT]);
GtkWidgetSet.SetWidgetFont(AWidget, AFont);
end;
end;
class procedure TGtkWSCustomMemo.SetScrollbars(const ACustomMemo: TCustomMemo;
const NewScrollbars: TScrollStyle);
var
wHandle: HWND;
begin
wHandle := ACustomMemo.Handle;
case ACustomMemo.Scrollbars of
ssHorizontal: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_ALWAYS, GTK_POLICY_NEVER);
ssVertical: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
ssBoth: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
ssAutoHorizontal: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
ssAutoVertical: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
ssAutoBoth: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
else
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
end;
end;
class procedure TGtkWSCustomMemo.SetWordWrap(const ACustomMemo: TCustomMemo;
const NewWordWrap: boolean);
var
ImplWidget : PGtkWidget;
begin
ImplWidget:= GetWidgetInfo(PGtkWidget(ACustomMemo.Handle), true)^.CoreWidget;
gtk_text_freeze(PGtkText(ImplWidget));
if ACustomMemo.WordWrap then
gtk_text_set_line_wrap(GTK_TEXT(ImplWidget), GdkTrue)
else
gtk_text_set_line_wrap(GTK_TEXT(ImplWidget), GdkFalse);
gtk_text_set_word_wrap(GTK_TEXT(ImplWidget), GdkTrue);
gtk_text_thaw(PGtkText(ImplWidget));
end;
{$endif}
{ TGtkWSCustomGroupBox }
class procedure TGtkWSCustomGroupBox.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
end;
{$ifdef gtk1}
class function TGtkWSCustomGroupBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
TempWidget: PGTKWidget; // pointer to gtk-widget (local use when neccessary)
p : pointer; // ptr to the newly created GtkWidget
Allocation: TGTKAllocation;
WidgetInfo: PWidgetInfo;
begin
if AParams.Caption <> '' then
P := gtk_frame_new(AParams.Caption)
else
P := gtk_frame_new(nil);
WidgetInfo := CreateWidgetInfo(P, AWinControl, AParams);
TempWidget := CreateFixedClientWidget;
gtk_container_add(GTK_CONTAINER(p), TempWidget);
WidgetInfo^.ClientWidget := TempWidget;
WidgetInfo^.CoreWidget := TempWidget;
gtk_object_set_data(PGtkObject(TempWidget), 'widgetinfo', WidgetInfo);
gtk_widget_show(TempWidget);
gtk_widget_show(P);
Result := TLCLHandle(PtrUInt(P));
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(P, @Allocation);
Set_RC_Name(AWinControl, P);
SetCallbacks(P, WidgetInfo);
end;
class procedure TGtkWSCustomGroupBox.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
var
Widget: PGtkWidget;
border_width: Integer;
begin
Widget := PGtkWidget(AWinControl.Handle);
PreferredWidth := (gtk_widget_get_xthickness(Widget)) * 2
+PGtkFrame(Widget)^.label_width;
PreferredHeight := Max(gtk_widget_get_ythickness(Widget),
PGtkFrame(Widget)^.label_height)
+ gtk_widget_get_ythickness(Widget);
if WithThemeSpace then begin
border_width:=(PGtkContainer(Widget)^.flag0 and bm_TGtkContainer_border_width)
shr bp_TGtkContainer_border_width;
inc(PreferredWidth, border_width);
inc(PreferredHeight,2*border_width);
end;
end;
class procedure TGtkWSCustomGroupBox.SetText(const AWinControl: TWinControl;
const AText: string);
begin
if not WSCheckHandleAllocated(AWinControl, 'SetText') then Exit;
if AText <> '' then
gtk_frame_set_label(PGtkFrame(AWinControl.Handle), PChar(AText))
else
gtk_frame_set_label(PGtkFrame(AWinControl.Handle), nil);
end;
{$endif}
{ TGtkWSRadioButton }
class function TGtkWSRadioButton.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Widget, TempWidget: PGtkWidget;
LabelWidget: PGtkLabel;
TempInt: Integer;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
with TRadioButton(AWinControl) do
begin
// Look for our parent's control and use the first radio we find for grouping
TempWidget := nil;
if (Parent <> nil) then
begin
for TempInt := 0 to Parent.ControlCount - 1 do
begin
if (Parent.Controls[TempInt] is TRadioButton) and
TWinControl(Parent.Controls[TempInt]).HandleAllocated then
begin
TempWidget := PGtkWidget(TWinControl(Parent.Controls[TempInt]).Handle);
Break;
end;
end;
end;
if TempWidget <> nil then
Widget := gtk_radio_button_new_with_label(PGtkRadioButton(TempWidget)^.group,'')
else
Widget := gtk_radio_button_new_with_label(nil, '');
LabelWidget := PGtkLabel(gtk_bin_get_child(PGtkBin(@PGTKToggleButton(Widget)^.Button)));
GtkWidgetSet.SetLabelCaption(LabelWidget, AParams.Caption
{$IFDEF Gtk1}, AWinControl, Widget, 'clicked'{$ENDIF});
end;
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLHandle(Widget);
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(Widget, @Allocation);
Set_RC_Name(AWinControl, Widget);
TGtkWSCustomCheckBox.SetCallbacks(Widget, WidgetInfo);
end;
{ TGtkWSToggleBox }
class function TGtkWSToggleBox.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
Widget := gtk_toggle_button_new_with_label(AParams.Caption);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLHandle(Widget);
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(Widget, @Allocation);
Set_RC_Name(AWinControl, Widget);
TGtkWSCustomCheckBox.SetCallbacks(Widget, WidgetInfo);
end;
end.
|