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
|
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Mattias Gaertner
Abstract:
Provides general classes and methods to access and handle IDE dialogs and
windows.
}
unit IDEWindowIntf;
{$mode objfpc}{$H+}
interface
uses
Math, Classes, SysUtils,
// LCL
LCLProc, LCLIntf, Forms, Controls, LCLType,
// LazUtils
LazConfigStorage, LazUTF8, LazMethodList,
// IdeIntf
IDEOptionsIntf;
const
IDEWndCfgFileVersion = 2;
// 2: changed default WindowPlacement from iwpRestoreWindowSize to iwpRestoreWindowGeometry
//----------------------------------------------------------------------------
// layout settings of modal forms (dialogs) in the IDE
type
TIDEDialogLayoutList = class;
{ TIDEDialogLayout - for modal forms
For non modal forms see TIDEWindowCreator below }
TIDEDialogLayout = class
private
FList: TIDEDialogLayoutList;
FModified: boolean;
FName: string;
FWidth: integer;
FHeight: integer;
procedure SetList(const AValue: TIDEDialogLayoutList);
procedure SetModified(const AValue: boolean);
procedure SetWidth(const AValue: integer);
procedure SetHeight(const AValue: integer);
public
constructor Create(const TheName: string; TheList: TIDEDialogLayoutList);
procedure Assign(Source: TIDEDialogLayout);
function SizeValid: boolean;
property Width: integer read FWidth write SetWidth;
property Height: integer read FHeight write SetHeight;
property Name: string read FName;
procedure LoadFromConfig(Config: TConfigStorage; const Path: string);
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
property List: TIDEDialogLayoutList read FList write SetList;
property Modified: boolean read FModified write SetModified;
end;
TIDEDialogLayoutClass = class of TIDEDialogLayout;
{ TIDEDialogLayoutList - for modal forms }
TIDEDialogLayoutList = class
private
FItemClass: TIDEDialogLayoutClass;
FItems: TList;
FModified: boolean;
function GetItems(Index: integer): TIDEDialogLayout;
protected
procedure SetModified(const AValue: boolean); virtual;
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TIDEDialogLayoutList);
procedure ApplyLayout(ADialog: TControl;
DefaultWidth, DefaultHeight: integer;
UseAsMin: boolean = false);
procedure ApplyLayout(ADialog: TControl);
procedure SaveLayout(ADialog: TControl);
procedure Clear;
function Count: integer;
function Find(const DialogName: string;
CreateIfNotExists: boolean): TIDEDialogLayout;
function Find(ADialog: TObject;
CreateIfNotExists: boolean): TIDEDialogLayout;
function IndexOf(const DialogName: string): integer;
procedure LoadFromConfig(Config: TConfigStorage; const Path: string);
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
property Items[Index: integer]: TIDEDialogLayout read GetItems;
property Modified: boolean read FModified write SetModified;
property ItemClass: TIDEDialogLayoutClass read FItemClass write FItemClass;
end;
{ TIDEDialogLayoutStorage }
TIDEDialogLayoutStorage = class(TComponent)
protected
procedure OnCreateForm(Sender: TObject);
procedure OnCloseForm(Sender: TObject; var {%H-}CloseAction: TCloseAction);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
var
IDEDialogLayoutList: TIDEDialogLayoutList = nil;// set by the IDE
type
{ TSimpleWindowLayout stores information about the position, min/maximized state
and similar things for an IDE window or dialog, like the source editor,
the object inspector, the main bar or the message view.
}
TIDEWindowState = (iwsNormal, iwsMaximized, iwsMinimized, iwsHidden);
TIDEWindowStates = set of TIDEWindowState;
TSimpleWindowLayoutDividerPosSizeGetter =
function(AForm: TCustomForm; AColId: Integer; var ASize: Integer): Boolean;
TSimpleWindowLayoutDividerPosSizeSetter =
procedure(AForm: TCustomForm; AColId: Integer; ASize: Integer);
{ TSimpleWindowLayoutDividerPos }
TSimpleWindowLayoutDividerPos = class
private
FDefaultSize: integer;
FDisplayName: PString;
FId: Integer;
FIdString: String;
FSize: integer;
function GetDisplayName: String;
protected
procedure SetDisplayName(ADisplayName: PString);
procedure SetId(AnId: Integer);
public
constructor Create(AnIdString: String);
constructor Create(AnIdString: String; AnId: Integer; ADisplayName: PString);
procedure Assign(ADividerPos: TSimpleWindowLayoutDividerPos); reintroduce;
procedure LoadFromConfig(Config: TConfigStorage; const Path: string);
function SaveToConfig(Config: TConfigStorage; const Path: string) : Boolean;
procedure Clear;
property IdString: String read FIdString;
property Id: Integer read FId;
property DisplayName: String read GetDisplayName;
property Size: integer read FSize write FSize;
property DefaultSize: integer read FDefaultSize write FDefaultSize;
end;
{ TSimpleWindowLayoutDividerPosList }
TSimpleWindowLayoutDividerPosList = class
private
FList: TList;
function GetItems(Index: Integer): TSimpleWindowLayoutDividerPos;
function GetNamedItems(Index: Integer): TSimpleWindowLayoutDividerPos;
protected
procedure Merge(AnItem: TSimpleWindowLayoutDividerPos);
public
constructor Create;
destructor Destroy; override;
procedure Assign(ADividerPosList: TSimpleWindowLayoutDividerPosList); reintroduce;
procedure LoadFromConfig(Config: TConfigStorage; const Path: string);
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
procedure Clear;
procedure ClearItems;
function Add(AnIdString: String; AnId: Integer; ADisplayName: PString): TSimpleWindowLayoutDividerPos;
function Add(AnIdString: String): TSimpleWindowLayoutDividerPos;
function Count: Integer;
function NamedCount: Integer;
function Find(AnId: Integer): TSimpleWindowLayoutDividerPos;
function Find(AnIdString: String): TSimpleWindowLayoutDividerPos;
function IndexOf(AnId: Integer): Integer;
function IndexOf(AnIdString: String): Integer;
function IndexOf(AnItem: TSimpleWindowLayoutDividerPos): Integer;
property Items[Index: Integer]: TSimpleWindowLayoutDividerPos read GetItems; default;
property NamedItems[Index: Integer]: TSimpleWindowLayoutDividerPos read GetNamedItems;
end;
{ TSimpleWindowLayout }
TSimpleWindowLayout = class(TComponent)
private
FApplied: boolean;
FFormCaption: string;
FVisible: boolean;
FLeft: integer;
FTop: integer;
FWidth: integer;
FHeight: integer;
FDefaultLeft: integer;
FDefaultTop: integer;
FDefaultWidth: integer;
FDefaultHeight: integer;
FWindowState: TIDEWindowState;
FForm: TCustomForm;
FFormID: string;
FDividers: TSimpleWindowLayoutDividerPosList;
procedure SetForm(const AForm: TCustomForm);
function GetFormCaption: string;
procedure OnFormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AFormID: string); reintroduce;
destructor Destroy; override;
procedure Clear;
procedure GetCurrentPosition;
function Apply(const aForce: Boolean = False): Boolean;
procedure ApplyDivider;
procedure Assign(Layout: TSimpleWindowLayout); reintroduce;
procedure ReadCurrentDividers;
procedure ReadCurrentCoordinates;
procedure ReadCurrentState;
procedure LoadFromConfig(Config: TConfigStorage; const Path: string; FileVersion: integer);
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
function CustomCoordinatesAreValid: boolean;
function DefaultCoordinatesAreValid: boolean;
procedure CloseForm;
function ValidateAndSetCoordinates(const aForce: Boolean = False): Boolean;
procedure SetDefaultPosition(const AForm: TCustomForm);
public
property FormID: string read FFormID write FFormID;
function FormBaseID(out SubIndex: Integer): String; // split FormID into name+number
property FormCaption: string read GetFormCaption;
property Left: integer read FLeft write FLeft;
property Top: integer read FTop write FTop;
property Width: integer read FWidth write FWidth;
property Height: integer read FHeight write FHeight;
property DefaultLeft: integer read FDefaultLeft write FDefaultLeft;
property DefaultTop: integer read FDefaultTop write FDefaultTop;
property DefaultWidth: integer read FDefaultWidth write FDefaultWidth;
property DefaultHeight: integer read FDefaultHeight write FDefaultHeight;
property WindowState: TIDEWindowState read FWindowState write FWindowState;
property Form: TCustomForm read FForm write SetForm;
property Visible: boolean read FVisible write FVisible;
property Applied: boolean read FApplied write FApplied;
property Dividers: TSimpleWindowLayoutDividerPosList read FDividers;
end;
{ TSimpleWindowLayoutList }
TLayoutMoveToVisbleMode = (
vmAlwaysMoveToVisible,
vmNeverMoveToVisible,
vmOnlyMoveOffScreenToVisible // Only make visible, if offscreen (with a threshold)
);
TSimpleWindowLayoutList = class
private
fItems: TFPList;
fRegisterEventHandlers: Boolean;
function GetItems(Index: Integer): TSimpleWindowLayout;
procedure OnScreenRemoveForm(Sender: TObject; AForm: TCustomForm);
public
constructor Create(ARegisterEventHandlers: Boolean);
destructor Destroy; override;
procedure Clear;
procedure Delete(Index: Integer);
procedure ApplyAndShow(Sender: TObject; AForm: TCustomForm;
BringToFront: boolean;
AMoveToVisbleMode: TLayoutMoveToVisbleMode = vmOnlyMoveOffScreenToVisible);
procedure StoreWindowPositions;
procedure SetDefaultPosition(const AForm: TCustomForm);
procedure MoveToTop(const AFormID: string);
procedure CopyItemsFrom(SrcList: TSimpleWindowLayoutList);
function Add(ALayout: TSimpleWindowLayout): integer;
function CreateWindowLayout(const TheFormID: string): TSimpleWindowLayout;
function CreateWindowLayout(const TheForm: TCustomForm): TSimpleWindowLayout;
function IndexOf(const FormID: string): integer;
function IndexOf(const AForm: TCustomForm): integer;
function ItemByForm(AForm: TCustomForm): TSimpleWindowLayout;
function ItemByFormID(const FormID: string): TSimpleWindowLayout;
function ItemByFormCaption(const aFormCaption: string): TSimpleWindowLayout;
procedure CloseForm(AForm: TCustomForm);
procedure LoadFromConfig(Config: TConfigStorage; const Path: string);
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
public
function Count: integer;
property Items[Index: Integer]: TSimpleWindowLayout read GetItems; default;
end;
const
IDEWindowStateNames: array[TIDEWindowState] of string = (
'Normal', 'Maximized', 'Minimized', 'Hidden'
);
function StrToIDEWindowState(const s: string): TIDEWindowState;
type
TIWCState = (
iwcsHidden,
iwcsIconified,
iwcsNormal,
iwcsDocked
);
TIWGetFormState = (
iwgfDisabled, // create if not exist with disabled autosizing
iwgfEnabled, // create if not exists
iwgfShow, // create and show
iwgfShowOnTop // create, show and bring to front
);
TIWGetFormStates = set of TIWGetFormState;
TCreateIDEWindowMethod = procedure(Sender: TObject; aFormName: string;
var AForm: TCustomForm; DoDisableAutoSizing: boolean) of object;
TCreateIDEWindowProc = procedure(Sender: TObject; aFormName: string;
var AForm: TCustomForm; DoDisableAutoSizing: boolean);
TGetDefaultIDEWindowLayoutEvent = procedure(Sender: TObject; aFormName: string;
out aBounds: TRect; out DockSibling: string; out DockAlign: TAlign) of object;
TShowIDEWindowEvent = procedure(Sender: TObject; AForm: TCustomForm;
BringToFront: boolean) of object;
{ TIDEWindowCreator
Every dockable window of the IDE needs a TIDEWindowCreator. }
TIDEWindowCreator = class
private
FCreateFormMethod: TCreateIDEWindowMethod;
FCreateFormProc: TCreateIDEWindowProc;
FDockAlign: TAlign;
FDockSibling: string;
FFormName: string;
FBottom: string;
FLeft: string;
FMulti: boolean;
FOnGetDividerSize: TSimpleWindowLayoutDividerPosSizeGetter;
FOnGetLayout: TGetDefaultIDEWindowLayoutEvent;
FOnSetDividerSize: TSimpleWindowLayoutDividerPosSizeSetter;
FState: TIWCState;
FTop: string;
FRight: string;
FDividerTemplate: TSimpleWindowLayoutDividerPosList;
function GetDividerTemplate: TSimpleWindowLayoutDividerPosList;
procedure SetBottom(const AValue: string);
procedure SetLeft(const AValue: string);
procedure SetTop(const AValue: string);
procedure SetRight(const AValue: string);
procedure InitSimpleLayout(ALayout: TSimpleWindowLayout);
public
constructor Create(aFormName: string); overload;
constructor Create(aFormName: string;
CreateFormProc: TCreateIDEWindowProc;
CreateFormMethod: TCreateIDEWindowMethod;
aLeft, aTop, aRight, aBottom: string;
aDockSibling : string = '';
aDockAlign: TAlign = alNone;
aMulti: boolean = false;
GetLayoutEvent: TGetDefaultIDEWindowLayoutEvent = nil); overload;
destructor Destroy; override;
property FormName: string read FFormName; // prefix for all forms
property Multi: boolean read FMulti; // there can be more than one of this form, e.g. the source editors and the package editors
property OnCreateFormMethod: TCreateIDEWindowMethod read FCreateFormMethod write FCreateFormMethod;
property OnCreateFormProc: TCreateIDEWindowProc read FCreateFormProc write FCreateFormProc;
function NameFits(const AName: string): boolean;
// hints for the layout system / dock master. It may ignore them completely.
property State: TIWCState read FState write FState;
property Left: string read FLeft write SetLeft; // '12' for 12 pixel, '10%' for 10 percent of screen.width
property Top: string read FTop write SetTop; // '12' for 12 pixel, '10%' for 10 percent of screen.height
property Right: string read FRight write SetRight; // '12' for 12 pixel, '+12' for a Width of 12 pixel, '-12' for Screen.Width-12, '10%' for 10 percent of screen.width
property Bottom: string read FBottom write SetBottom; // '12' for 12 pixel, '+12' for a Height of 12 pixel, '10%' for 10 percent of screen.height
property DockSibling: string read FDockSibling write FDockSibling; // another form name
property DockAlign: TAlign read FDockAlign write FDockAlign;
property OnGetLayout: TGetDefaultIDEWindowLayoutEvent read FOnGetLayout
write FOnGetLayout;
procedure CheckBoundValue(s: string);
procedure GetDefaultBounds(AForm: TCustomForm; out DefBounds: TRect);
function CreateSimpleLayout: TSimpleWindowLayout;
// TODO: Need a WindowCreator factory, by class of TForm
// then this data can be stored per window class
property DividerTemplate: TSimpleWindowLayoutDividerPosList read GetDividerTemplate;
property OnGetDividerSize: TSimpleWindowLayoutDividerPosSizeGetter read FOnGetDividerSize write FOnGetDividerSize;
property OnSetDividerSize: TSimpleWindowLayoutDividerPosSizeSetter read FOnSetDividerSize write FOnSetDividerSize;
end;
{ TIDEWindowCreatorList }
TIDEWindowCreatorList = class
private
fItems: TFPList; // list of TIDEWindowCreator
FSimpleLayoutStorage: TSimpleWindowLayoutList;
FOnLayoutChanged: TMethodList;
procedure LayoutChanged;
function GetItems(Index: integer): TIDEWindowCreator;
procedure ErrorIfFormExists(FormName: string);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function Count: integer;
property Items[Index: integer]: TIDEWindowCreator read GetItems; default;
function Add(aLayout: TIDEWindowCreator): integer; overload;
function Add(aFormName: string): TIDEWindowCreator; overload;
function Add(aFormName: string;
CreateFormProc: TCreateIDEWindowProc;
CreateFormMethod: TCreateIDEWindowMethod;
// you can pass some hints to the layout system how to place the form by default
// Note: the IDE dockmaster may completely ignore these values
aLeft, aTop, aRight, aBottom: string;
aDockSibling : string = '';
aDockAlign: TAlign = alNone;
aMulti: boolean = false; // if true, then there can be more than one instance, the aFormName is the shared prefix
GetLayoutEvent: TGetDefaultIDEWindowLayoutEvent = nil
): TIDEWindowCreator; overload;
procedure Delete(Index: integer);
function IndexOfName(FormName: string): integer;
function FindWithName(FormName: string): TIDEWindowCreator;
function GetForm(aFormName: string; AutoCreate: boolean;
DisableAutoSizing: boolean = false): TCustomForm;
procedure ShowForm(AForm: TCustomForm; BringToFront: boolean;
AMoveToVisbleMode: TLayoutMoveToVisbleMode = vmOnlyMoveOffScreenToVisible); overload;
function ShowForm(AFormName: string; BringToFront: boolean): TCustomForm; overload;
procedure CreateForm(var AForm; AFormClass: TCustomFormClass;
DoDisableAutoSizing: boolean; TheOwner: TComponent); // utility function to create a form with delayed autosizing
property SimpleLayoutStorage: TSimpleWindowLayoutList read FSimpleLayoutStorage;
procedure RestoreSimpleLayout;
procedure AddLayoutChangedHandler(const aEvent: TNotifyEvent);
procedure RemoveLayoutChangedHandler(const aEvent: TNotifyEvent);
function GetScreenrectForDefaults: TRect;
end;
var
IDEWindowCreators: TIDEWindowCreatorList = nil; // set by the IDE
type
TDockSides = set of TAlign;
{ TIDEDockMaster }
TIDEDockMaster = class
protected
FHideSimpleLayoutOptions: boolean;
public
procedure MakeIDEWindowDockable(AControl: TWinControl); virtual; abstract; // make AControl dockable, it can be docked and other dockable windows can be docked to it, this does not make it visible
procedure MakeIDEWindowDockSite(AForm: TCustomForm; ASides: TDockSides = [alBottom]); virtual; abstract; // make AForm a dock site, AForm can not be docked, its Parent must be kept nil, this does not make it visible
procedure ShowForm(AForm: TCustomForm; BringToFront: boolean); virtual; abstract; // make a form visible, set BringToFront=true if form should be shown on active screen and on front of other windows, normally this focus the form
function AddableInWindowMenu({%H-}AForm: TCustomForm): boolean; virtual;
procedure AdjustMainIDEWindowHeight(const {%H-}AIDEWindow: TCustomForm;
const {%H-}AAdjustHeight: Boolean; const {%H-}ANewHeight: Integer); virtual;
procedure CloseAll; virtual; // close all forms, called after IDE has saved all and shuts down
procedure ResetSplitters; virtual; abstract; // if the dock site has been resized after loading, you have to reset (percentual) splitters
function DockedDesktopOptClass: TAbstractDesktopDockingOptClass; virtual; abstract;
property HideSimpleLayoutOptions: boolean read FHideSimpleLayoutOptions;
end;
TIDEWindowGlobalOption = class
public
CanSetVisibility: Boolean;
end;
TIDEWindowsGlobalOptions = class
private
FList: TStringList;
public
constructor Create;
destructor Destroy; override;
public
procedure Add(const aFormIDPrefix: string; CanSetVisibility: Boolean);
function CanSetVisibility(const aFormID: string): Boolean;
end;
var
IDEDockMaster: TIDEDockMaster = nil; // can be set by a package
procedure MakeIDEWindowDockable(AControl: TWinControl);
procedure MakeIDEWindowDockSite(AForm: TCustomForm);
procedure CloseAllForms;
function IDEWindowsGlobalOptions: TIDEWindowsGlobalOptions;
procedure SetPopupModeParentForPropertyEditor(const AEditorDlg: TCustomForm);
procedure Register;
implementation
uses
LazIDEIntf;
var
FIDEWindowsGlobalOptions: TIDEWindowsGlobalOptions = nil;
procedure SetPopupModeParentForPropertyEditor(const AEditorDlg: TCustomForm);
begin
if IDEDockMaster<>nil then
AEditorDlg.PopupParent:=LazarusIDE.GetMainBar// sets PopupMode:=pmExplicit automatically
else
AEditorDlg.PopupMode:=pmNone;
end;
function StrToIDEWindowState(const s: string): TIDEWindowState;
begin
for Result:=Low(TIDEWindowState) to High(TIDEWindowState) do
if UTF8CompareText(s,IDEWindowStateNames[Result])=0 then exit;
Result:=iwsNormal;
end;
procedure MakeIDEWindowDockable(AControl: TWinControl);
begin
if Assigned(IDEDockMaster) then
IDEDockMaster.MakeIDEWindowDockable(AControl);
end;
procedure MakeIDEWindowDockSite(AForm: TCustomForm);
begin
if Assigned(IDEDockMaster) then
IDEDockMaster.MakeIDEWindowDockSite(AForm);
end;
procedure CloseAllForms;
var
i: Integer;
AForm: TCustomForm;
AControl: TWinControl;
begin
// hide all forms
i:=Screen.CustomFormCount-1;
while i>=0 do begin
AForm:=GetParentForm(Screen.CustomForms[i]);
AForm.Hide;
dec(i);
if i>=Screen.CustomFormCount then i:=Screen.CustomFormCount-1;
end;
// close all forms except the MainForm
i:=Screen.CustomFormCount-1;
while i>=0 do begin
AForm:=Screen.CustomForms[i];
if (AForm<>Application.MainForm) and not AForm.IsParentOf(Application.MainForm)
then begin
AControl:=AForm;
while (AControl.Parent<>nil)
and (AControl.Parent<>Application.MainForm) do begin
AControl:=AControl.Parent;
if AControl is TCustomForm then AForm:=TCustomForm(AControl);
end;
AForm.Close;
end;
dec(i);
if i>=Screen.CustomFormCount then i:=Screen.CustomFormCount-1;
end;
end;
function IDEWindowsGlobalOptions: TIDEWindowsGlobalOptions;
begin
if not Assigned(FIDEWindowsGlobalOptions) then
FIDEWindowsGlobalOptions := TIDEWindowsGlobalOptions.Create;
Result := FIDEWindowsGlobalOptions;
end;
procedure Register;
begin
RegisterComponents('Misc',[TIDEDialogLayoutStorage]);
end;
{ TIDEWindowsGlobalOptions }
procedure TIDEWindowsGlobalOptions.Add(const aFormIDPrefix: string;
CanSetVisibility: Boolean);
var
xIndex: Integer;
begin
xIndex := FList.Add(aFormIDPrefix);
if FList.Objects[xIndex] = nil then
FList.Objects[xIndex] := TIDEWindowGlobalOption.Create;
TIDEWindowGlobalOption(FList.Objects[xIndex]).CanSetVisibility := CanSetVisibility;
end;
function TIDEWindowsGlobalOptions.CanSetVisibility(const aFormID: string
): Boolean;
var
I: Integer;
begin
for I := 0 to FList.Count-1 do
if Copy(aFormID, 1, Length(FList[I])) = FList[I] then
begin
Result := TIDEWindowGlobalOption(FList.Objects[I]).CanSetVisibility;
Exit;
end;
Result := True;//default is true
end;
constructor TIDEWindowsGlobalOptions.Create;
begin
inherited Create;
FList := TStringList.Create;
FList.Sorted := True;
FList.OwnsObjects := True;
end;
destructor TIDEWindowsGlobalOptions.Destroy;
begin
FList.Free;
inherited Destroy;
end;
{ TSimpleWindowLayoutDividerPosList }
function TSimpleWindowLayoutDividerPosList.GetItems(Index: Integer): TSimpleWindowLayoutDividerPos;
begin
Result := TSimpleWindowLayoutDividerPos(FList[Index]);
end;
function TSimpleWindowLayoutDividerPosList.GetNamedItems(Index: Integer): TSimpleWindowLayoutDividerPos;
var
i: Integer;
begin
Result := nil;
i := 0;
while i < Count do begin
if Items[i].DisplayName <> '' then begin
if Index = 0 then begin
Result := Items[i];
exit;
end;
dec(Index);
end;
inc(i);
end;
end;
procedure TSimpleWindowLayoutDividerPosList.Merge(AnItem: TSimpleWindowLayoutDividerPos);
var
i: Integer;
old: TSimpleWindowLayoutDividerPos;
begin
i := IndexOf(AnItem.IdString);
FList.Add(AnItem);
if i < 0 then
exit;
old := Items[i];
if AnItem.Id < 0 then
AnItem.SetId(old.Id);
if AnItem.DisplayName = '' then
AnItem.SetDisplayName(old.FDisplayName);
if AnItem.DefaultSize < 0 then
AnItem.DefaultSize := old.DefaultSize;
FList.Remove(old);
old.Free;
end;
constructor TSimpleWindowLayoutDividerPosList.Create;
begin
FList := TList.Create;
end;
destructor TSimpleWindowLayoutDividerPosList.Destroy;
begin
Clear;
inherited Destroy;
FreeAndNil(FList);
end;
procedure TSimpleWindowLayoutDividerPosList.Assign(ADividerPosList: TSimpleWindowLayoutDividerPosList);
var
i: Integer;
tmp: TSimpleWindowLayoutDividerPos;
begin
Clear;
for i := 0 to ADividerPosList.Count - 1 do begin
tmp := Add('');
tmp.Assign(ADividerPosList[i]);
end;
end;
procedure TSimpleWindowLayoutDividerPosList.LoadFromConfig(Config: TConfigStorage;
const Path: string);
var
tmp: TSimpleWindowLayoutDividerPos;
c, i: Integer;
begin
ClearItems;
c := Config.GetValue(Path+'Count', 0);
for i := 0 to c - 1 do begin
tmp := TSimpleWindowLayoutDividerPos.Create('');
tmp.LoadFromConfig(Config, Path + 'Item' + IntToStr(i) + '/');
Merge(tmp);
end;
end;
procedure TSimpleWindowLayoutDividerPosList.SaveToConfig(Config: TConfigStorage;
const Path: string);
var
i, c: Integer;
begin
c := 0;
for i := 0 to Count - 1 do
if Items[i].SaveToConfig(Config, Path + 'Item' + IntToStr(c) + '/') then
inc(c);
for i := c to Count - 1 do
Config.DeletePath(Path + 'Item' + IntToStr(i) + '/');
Config.SetDeleteValue(Path+'Count', c, 0);
end;
procedure TSimpleWindowLayoutDividerPosList.Clear;
begin
while FList.Count > 0 do begin
TObject(FList[0]).Free;
FList.Delete(0);
end;
end;
procedure TSimpleWindowLayoutDividerPosList.ClearItems;
var
i: Integer;
begin
for i := 0 to Count - 1 do
Items[i].Clear;
end;
function TSimpleWindowLayoutDividerPosList.Add(AnIdString: String;
AnId: Integer; ADisplayName: PString): TSimpleWindowLayoutDividerPos;
var
i: Integer;
begin
i := IndexOf(AnId);
if i < 0
then begin
Result := TSimpleWindowLayoutDividerPos.Create(AnIdString, AnId, ADisplayName);
FList.Add(Result);
end
else begin
Result := Items[i];
if ADisplayName = nil then
Result.SetDisplayName(ADisplayName);
end
end;
function TSimpleWindowLayoutDividerPosList.Add(AnIdString: String): TSimpleWindowLayoutDividerPos;
begin
Result := Add(AnIdString, -1, nil);
end;
function TSimpleWindowLayoutDividerPosList.Count: Integer;
begin
Result := FList.Count;
end;
function TSimpleWindowLayoutDividerPosList.NamedCount: Integer;
var
i: Integer;
begin
Result := 0;
i := Count - 1;
while i >= 0 do begin
if Items[i].DisplayName <> '' then inc(Result);
dec(i);
end;
end;
function TSimpleWindowLayoutDividerPosList.Find(AnId: Integer): TSimpleWindowLayoutDividerPos;
var
i: Integer;
begin
Result := nil;
i := IndexOf(AnId);
if i >= 0 then
Result := Items[i];
end;
function TSimpleWindowLayoutDividerPosList.Find(AnIdString: String): TSimpleWindowLayoutDividerPos;
var
i: Integer;
begin
Result := nil;
i := IndexOf(AnIdString);
if i >= 0 then
Result := Items[i];
end;
function TSimpleWindowLayoutDividerPosList.IndexOf(AnId: Integer): Integer;
begin
Result := Flist.Count-1;
while Result >= 0 do begin
if Items[Result].Id = AnId then
exit;
dec(Result);
end;
end;
function TSimpleWindowLayoutDividerPosList.IndexOf(AnIdString: String): Integer;
begin
Result := Flist.Count-1;
while Result >= 0 do begin
if Items[Result].IdString = AnIdString then
exit;
dec(Result);
end;
end;
function TSimpleWindowLayoutDividerPosList.IndexOf(AnItem: TSimpleWindowLayoutDividerPos): Integer;
begin
Result := FList.IndexOf(AnItem);
end;
{ TSimpleWindowLayoutDividerPos }
function TSimpleWindowLayoutDividerPos.GetDisplayName: String;
begin
if FDisplayName = nil then
Result := ''
else
Result := FDisplayName^;
end;
procedure TSimpleWindowLayoutDividerPos.SetDisplayName(ADisplayName: PString);
begin
FDisplayName := ADisplayName;
end;
procedure TSimpleWindowLayoutDividerPos.SetId(AnId: Integer);
begin
FId := AnId;
end;
constructor TSimpleWindowLayoutDividerPos.Create(AnIdString: String);
begin
Create(AnIdString, -1, nil);
end;
constructor TSimpleWindowLayoutDividerPos.Create(AnIdString: String; AnId: Integer;
ADisplayName: PString);
begin
FDefaultSize := -1;
Clear;
FId := AnId;
FIdString := AnIdString;
FDisplayName := ADisplayName;
end;
procedure TSimpleWindowLayoutDividerPos.Assign(ADividerPos: TSimpleWindowLayoutDividerPos);
begin
FDefaultSize := ADividerPos.FDefaultSize;
FDisplayName := ADividerPos.FDisplayName;
FId := ADividerPos.FId;
FIdString := ADividerPos.FIdString;
FSize := ADividerPos.FSize;
end;
procedure TSimpleWindowLayoutDividerPos.LoadFromConfig(Config: TConfigStorage;
const Path: string);
begin
Clear;
FIdString := Config.GetValue(Path+'ID', '');
FSize := Config.GetValue(Path+'Size', -1);
end;
function TSimpleWindowLayoutDividerPos.SaveToConfig(Config: TConfigStorage;
const Path: string): Boolean;
begin
Result := (FSize <> -1);
if not Result then
exit;
Config.SetDeleteValue(Path+'ID', FIdString, '');
Config.SetDeleteValue(Path+'Size', FSize, -1);
end;
procedure TSimpleWindowLayoutDividerPos.Clear;
begin
FSize := FDefaultSize;
end;
{ TIDEDialogLayout }
procedure TIDEDialogLayout.SetList(const AValue: TIDEDialogLayoutList);
begin
if FList=AValue then exit;
FList:=AValue;
if (List<>nil) and Modified then List.Modified:=true;
end;
procedure TIDEDialogLayout.SetModified(const AValue: boolean);
begin
FModified:=AValue;
if FModified and (FList<>nil) then FList.Modified:=true;
end;
procedure TIDEDialogLayout.SetWidth(const AValue: integer);
begin
if FWidth=AValue then exit;
FWidth:=AValue;
Modified:=true;
end;
procedure TIDEDialogLayout.SetHeight(const AValue: integer);
begin
if FHeight=AValue then exit;
FHeight:=AValue;
Modified:=true;
end;
constructor TIDEDialogLayout.Create(const TheName: string;
TheList: TIDEDialogLayoutList);
begin
FName:=TheName;
FList:=TheList;
end;
procedure TIDEDialogLayout.Assign(Source: TIDEDialogLayout);
begin
FName := Source.FName;
FWidth := Source.FWidth;
FHeight := Source.FHeight;
FModified := True;
end;
function TIDEDialogLayout.SizeValid: boolean;
begin
Result:=(Width>10) and (Height>10);
end;
procedure TIDEDialogLayout.LoadFromConfig(Config: TConfigStorage; const Path: string);
begin
FName:=Config.GetValue(Path+'Name/Value','');
FWidth:=Config.GetValue(Path+'Size/Width',0);
FHeight:=Config.GetValue(Path+'Size/Height',0);
Modified:=false;
end;
procedure TIDEDialogLayout.SaveToConfig(Config: TConfigStorage; const Path: string);
begin
Config.SetValue(Path+'Name/Value',Name);
Config.SetValue(Path+'Size/Width',Width);
Config.SetValue(Path+'Size/Height',Height);
Modified:=false;
end;
{ TIDEDialogLayoutList }
function TIDEDialogLayoutList.GetItems(Index: integer): TIDEDialogLayout;
begin
Result:=TIDEDialogLayout(FItems[Index]);
end;
procedure TIDEDialogLayoutList.SetModified(const AValue: boolean);
begin
if FModified=AValue then exit;
FModified:=AValue;
end;
constructor TIDEDialogLayoutList.Create;
begin
inherited Create;
FItems:=TList.Create;
FItemClass:=TIDEDialogLayout;
end;
destructor TIDEDialogLayoutList.Destroy;
begin
Clear;
FreeAndNil(FItems);
inherited Destroy;
end;
procedure TIDEDialogLayoutList.Assign(Source: TIDEDialogLayoutList);
var
i: Integer;
Layout: TIDEDialogLayout;
begin
FItemClass := Source.FItemClass;
Clear;
for i:=0 to Source.FItems.Count-1 do begin
Layout := TIDEDialogLayout.Create(Source.Items[i].Name, Self);
Layout.Assign(Source.Items[i]);
FItems.Add(Layout);
end;
FModified := True;
end;
procedure TIDEDialogLayoutList.ApplyLayout(ADialog: TControl;
DefaultWidth, DefaultHeight: integer; UseAsMin: boolean);
var
ALayout: TIDEDialogLayout;
NewWidth, NewHeight: integer;
begin
if (ADialog=nil) or (Self=nil) then exit;
ALayout:=Find(ADialog,true);
//debugln(['TIDEDialogLayoutList.ApplyLayout ',ALayout.Name,' ',ALayout.SizeValid,' ',ALayout.Width,',',ALayout.Height]);
if ALayout.SizeValid then begin
NewWidth:=ADialog.Scale96ToForm(ALayout.Width);
NewHeight:=ADialog.Scale96ToForm(ALayout.Height);
end else begin
NewWidth:=DefaultWidth;
NewHeight:=DefaultHeight;
end;
if UseAsMin then begin
if NewWidth<DefaultWidth then NewWidth:=DefaultWidth;
if NewHeight<DefaultHeight then NewHeight:=DefaultHeight;
end;
ADialog.SetBounds(ADialog.Left,ADialog.Top,NewWidth,NewHeight);
end;
procedure TIDEDialogLayoutList.ApplyLayout(ADialog: TControl);
begin
ApplyLayout(ADialog,ADialog.Width,ADialog.Height);
end;
procedure TIDEDialogLayoutList.SaveLayout(ADialog: TControl);
var
ALayout: TIDEDialogLayout;
begin
if (ADialog=nil) or (Self=nil) then exit;
ALayout:=Find(ADialog,true);
ALayout.Width:=ADialog.ScaleFormTo96(ADialog.Width);
ALayout.Height:=ADialog.ScaleFormTo96(ADialog.Height);
end;
procedure TIDEDialogLayoutList.Clear;
var i: integer;
begin
for i:=0 to FItems.Count-1 do
Items[i].Free;
FItems.Clear;
end;
function TIDEDialogLayoutList.Count: integer;
begin
Result:=FItems.Count;
end;
function TIDEDialogLayoutList.Find(const DialogName: string;
CreateIfNotExists: boolean): TIDEDialogLayout;
var i: integer;
begin
i:=IndexOf(DialogName);
if (i<0) then begin
if CreateIfNotExists then begin
Result:=FItemClass.Create(DialogName,Self);
FItems.Add(Result);
end else begin
Result:=nil;
end;
end else begin
Result:=Items[i];
end;
end;
function TIDEDialogLayoutList.Find(ADialog: TObject; CreateIfNotExists: boolean
): TIDEDialogLayout;
begin
if ADialog<>nil then begin
Result:=Find(ADialog.ClassName,CreateIfNotExists);
end else begin
Result:=nil;
end;
end;
function TIDEDialogLayoutList.IndexOf(const DialogName: string): integer;
begin
Result:=Count-1;
while (Result>=0) and (CompareText(DialogName,Items[Result].Name)<>0) do
dec(Result);
end;
procedure TIDEDialogLayoutList.LoadFromConfig(Config: TConfigStorage; const Path: string);
var
NewCount, i: integer;
NewDialogLayout: TIDEDialogLayout;
begin
Clear;
NewCount:=Config.GetValue(Path+'Count',0);
for i:=0 to NewCount-1 do begin
NewDialogLayout:=FItemClass.Create('',Self);
FItems.Add(NewDialogLayout);
NewDialogLayout.LoadFromConfig(Config,Path+'Dialog'+IntToStr(i+1)+'/');
end;
Modified:=false;
end;
procedure TIDEDialogLayoutList.SaveToConfig(Config: TConfigStorage; const Path: string);
var i: integer;
begin
Config.SetDeleteValue(Path+'Count',Count,0);
for i:=0 to Count-1 do
Items[i].SaveToConfig(Config,Path+'Dialog'+IntToStr(i+1)+'/');
Modified:=false;
end;
{ TIDEDialogLayoutStorage }
procedure TIDEDialogLayoutStorage.OnCreateForm(Sender: TObject);
begin
IDEDialogLayoutList.ApplyLayout(Sender as TControl);
end;
procedure TIDEDialogLayoutStorage.OnCloseForm(Sender: TObject;
var CloseAction: TCloseAction);
begin
IDEDialogLayoutList.SaveLayout(Sender as TControl);
end;
constructor TIDEDialogLayoutStorage.Create(TheOwner: TComponent);
var
Form: TCustomForm;
begin
inherited Create(TheOwner);
if Owner is TCustomForm then
begin
Form:=TCustomForm(Owner);
Form.AddHandlerCreate(@OnCreateForm);
Form.AddHandlerClose(@OnCloseForm);
end;
end;
destructor TIDEDialogLayoutStorage.Destroy;
var
Form: TCustomForm;
begin
if Owner is TCustomForm then
begin
Form:=TCustomForm(Owner);
Form.RemoveAllHandlersOfObject(Self);
end;
inherited Destroy;
end;
{ TSimpleWindowLayout }
constructor TSimpleWindowLayout.Create(AFormID: string);
var
Creator: TIDEWindowCreator;
begin
inherited Create(nil);
FDividers := TSimpleWindowLayoutDividerPosList.Create;
FormID := AFormID;
Clear;
Creator := IDEWindowCreators.FindWithName(AFormID);
if Creator <> nil then
Creator.InitSimpleLayout(Self);
end;
destructor TSimpleWindowLayout.Destroy;
begin
Form:=nil;
inherited Destroy;
FDividers.Free;
end;
procedure TSimpleWindowLayout.LoadFromConfig(Config: TConfigStorage;
const Path: string; FileVersion: integer);
var
P: string;
begin
if FileVersion=0 then ;
// set all values to default
Clear;
// read settings
// build path
P:=FormID;
if P='' then exit;
P:=Path+P+'/';
FFormCaption := Config.GetValue(P+'Caption/Value', fFormID);
// custom position
Left := Config.GetValue(P+'CustomPosition/Left', Left);
Top := Config.GetValue(P+'CustomPosition/Top', Top);
Width := Config.GetValue(P+'CustomPosition/Width', Width);
Height := Config.GetValue(P+'CustomPosition/Height', Height);
// state
fWindowState:=StrToIDEWindowState(Config.GetValue(
P+'WindowState/Value',IDEWindowStateNames[iwsNormal]));
FVisible:=Config.GetValue(P+'Visible/Value',false);
//debugln(['TSimpleWindowLayout.LoadFromConfig ',FormID,' ',Left,',',Top,',',Width,',',Height]);
FDividers.LoadFromConfig(Config, P + 'Divider/');
end;
procedure TSimpleWindowLayout.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation=opRemove then begin
if fForm=AComponent then begin
fForm:=nil;
Applied:=false;
end;
end;
end;
procedure TSimpleWindowLayout.SaveToConfig(Config: TConfigStorage;
const Path: string);
var
P: string;
begin
// build path
P:=FormID;
if P='' then exit;
P:=Path+P+'/';
Config.SetDeleteValue(P+'Caption/Value',FFormCaption,'');
// placement
Config.DeleteValue(P+'WindowPlacement/Value');
// custom position
Config.SetDeleteValue(P+'CustomPosition/Left', Left, 0);
Config.SetDeleteValue(P+'CustomPosition/Top', Top, 0);
Config.SetDeleteValue(P+'CustomPosition/Width', Width, 0);
Config.SetDeleteValue(P+'CustomPosition/Height', Height, 0);
// state
Config.SetDeleteValue(P+'WindowState/Value',IDEWindowStateNames[fWindowState],IDEWindowStateNames[iwsNormal]);
Config.SetDeleteValue(P+'Visible/Value',FVisible,false);
FDividers.SaveToConfig(Config, P + 'Divider/');
end;
procedure TSimpleWindowLayout.SetDefaultPosition(const AForm: TCustomForm);
begin
FDefaultLeft := AForm.Left;
FDefaultTop := AForm.Top;
FDefaultWidth := AForm.Width;
FDefaultHeight := AForm.Height;
end;
procedure TSimpleWindowLayout.OnFormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
GetCurrentPosition;
end;
function TSimpleWindowLayout.CustomCoordinatesAreValid: boolean;
begin
Result:=(Width>0) and (Height>0); // and (Left>10-Width) and (Top>10-Height);
end;
function TSimpleWindowLayout.DefaultCoordinatesAreValid: boolean;
begin
Result:=(DefaultWidth>0) and (DefaultHeight>0);
end;
procedure TSimpleWindowLayout.CloseForm;
begin
GetCurrentPosition;
end;
function TSimpleWindowLayout.ValidateAndSetCoordinates(const aForce: Boolean
): Boolean;
var
i: Integer;
NewBounds: TRect;
xForm: TCustomForm;
begin
Result := False;
xForm := Form;
if Assigned(xForm) and
(aForce or CustomCoordinatesAreValid) then
begin
if not CustomCoordinatesAreValid then//default position
begin
if not DefaultCoordinatesAreValid then//don't change the coordinates if default position is invalid
Exit;
NewBounds := Bounds(DefaultLeft, DefaultTop, DefaultWidth, DefaultHeight)
end else// explicit position
NewBounds := Bounds(Left, Top, Width, Height);
// set minimum size
if NewBounds.Right - NewBounds.Left < 60 then
NewBounds.Right := NewBounds.Left + 60;
if NewBounds.Bottom - NewBounds.Top < 60 then
NewBounds.Bottom := NewBounds.Top + 60;
// Move to visible area :
// window is out at left side of screen
if NewBounds.Right < Screen.DesktopLeft + 60 then
OffsetRect(NewBounds, Screen.DesktopLeft + 60 - NewBounds.Right, 0);
// window is out above the screen
if NewBounds.Bottom < Screen.DesktopTop+60 then
OffsetRect(NewBounds, 0, Screen.DesktopTop + 60 - NewBounds.Bottom);
// window is out at right side of screen, i = right edge of screen - 60
i := Screen.DesktopWidth + Screen.DesktopLeft - 60;
if NewBounds.Left > i then begin
NewBounds.Left := i;
NewBounds.Right := NewBounds.Right + i - NewBounds.Left;
end;
// window is out below the screen, i = bottom edge of screen - 60
i := Screen.DesktopHeight + Screen.DesktopTop - 60;
if NewBounds.Top > i then begin
NewBounds.Top := i;
NewBounds.Bottom := NewBounds.Bottom + i - NewBounds.Top;
end;
if xForm.WindowState = wsNormal then
xForm.SetBounds(NewBounds.Left, NewBounds.Top,
NewBounds.Right - NewBounds.Left,
NewBounds.Bottom - NewBounds.Top)
else
xForm.SetRestoredBounds(NewBounds.Left, NewBounds.Top,
NewBounds.Right - NewBounds.Left,
NewBounds.Bottom - NewBounds.Top);
Result := True;
end;
end;
function TSimpleWindowLayout.FormBaseID(out SubIndex: Integer): String;
var
i: Integer;
begin
Result := FormID;
SubIndex := -1;
i := length(Result);
while (i > 0) and (Result[i] in ['0'..'9']) do
dec(i);
if (i < 1) or (i = length(Result)) then
exit;
SubIndex := StrToInt(copy(Result, i+1, length(Result)));
Result := copy(Result, 1, i);
end;
procedure TSimpleWindowLayout.SetForm(const AForm: TCustomForm);
begin
if fForm=AForm then exit;
if Assigned(Form) then
begin
RemoveFreeNotification(Form);
Form.RemoveHandlerClose(@OnFormClose);
end;
fForm:=AForm;
if Assigned(Form) then
begin
Assert(Form.Name <> '');
fFormID := Form.Name;
FFormCaption := Form.Caption;
FreeNotification(Form);
Form.AddHandlerClose(@OnFormClose);
Applied:=false;
end;
end;
function TSimpleWindowLayout.GetFormCaption: string;
begin
if Form<>nil then
FFormCaption:=Form.Caption
else if FFormCaption='' then
FFormCaption:=FormID;
Result:=FFormCaption;
end;
procedure TSimpleWindowLayout.Clear;
begin
//debugln(['TSimpleWindowLayout.Clear ',FormID]);
fApplied := False;
fVisible := False;
fLeft:=0;
fTop:=0;
fWidth:=0;
fHeight:=0;
fWindowState:=iwsNormal;
FDividers.ClearItems;
end;
procedure TSimpleWindowLayout.ReadCurrentCoordinates;
var
p: TPoint;
xForm: TCustomForm;
begin
xForm := Form;
if (xForm<>nil) then
begin
if xForm.Parent<>nil then
p:=xForm.ClientOrigin
else
p:=Point(0,0);
if (xForm.WindowState=wsNormal) then
begin
Left:=xForm.Left+p.X;
Top:=xForm.Top+p.Y;
Width:=xForm.Width;
Height:=xForm.Height;
end else
begin
Left:=xForm.RestoredLeft+p.X;
Top:=xForm.RestoredTop+p.Y;
Width:=xForm.RestoredWidth;
Height:=xForm.RestoredHeight;
end;
end;
end;
procedure TSimpleWindowLayout.ReadCurrentState;
begin
Visible:=(Form<>nil) and Form.IsVisible;
if Form<>nil then begin
case Form.WindowState of
wsMinimized: fWindowState:=iwsMinimized;
wsMaximized: fWindowState:=iwsMaximized;
else
fWindowState:=iwsNormal;
end;
end;
end;
procedure TSimpleWindowLayout.Assign(Layout: TSimpleWindowLayout);
begin
Clear;
Assert(FFormID = Layout.FFormID);
//IMPORTANT: do not assign FForm and FFormID!
FVisible:=Layout.FVisible;
FLeft:=Layout.FLeft;
FTop:=Layout.FTop;
FWidth:=Layout.FWidth;
FHeight:=Layout.FHeight;
FWindowState:=Layout.FWindowState;
FDividers.Assign(Layout.FDividers);
end;
procedure TSimpleWindowLayout.ReadCurrentDividers;
var
i, j: Integer;
Creator: TIDEWindowCreator;
xForm: TCustomForm;
begin
Creator:=IDEWindowCreators.FindWithName(FormID);
if (Creator = nil) or (Creator.OnGetDividerSize = nil) then exit;
xForm := Form;
if xForm = nil then exit;
for i := 0 to FDividers.Count - 1 do begin
if FDividers[i].FId < 0 then continue;
j:=-1;
if Creator.OnGetDividerSize(xForm, FDividers[i].Id, j) then
FDividers[i].Size := j
else
FDividers[i].Size := -1; // Default / Not Changed / Unavailable
end;
end;
procedure TSimpleWindowLayout.GetCurrentPosition;
begin
//debugln('TSimpleWindowLayout.GetCurrentPosition ',DbgSName(Self),' ',FormID,' ',IDEWindowPlacementNames[WindowPlacement]);
ReadCurrentCoordinates;
ReadCurrentDividers;
ReadCurrentState;
//debugln('TSimpleWindowLayout.GetCurrentPosition ',DbgSName(Self),' ',FormID,' Width=',dbgs(Width));
end;
function TSimpleWindowLayout.Apply(const aForce: Boolean): Boolean;
var
xForm: TCustomForm;
begin
Result := False;
xForm := Form;
if xForm = nil then exit;
Applied:=true;
{$IFDEF VerboseIDEDocking}
debugln(['TSimpleWindowLayoutList.ApplyAndShow restore ',
FormID,' ',IDEWindowPlacementNames[WindowPlacement],
' ',Left,',',Top,',',Width,',',Height]);
{$ENDIF}
//DebugLn(['TMainIDE.OnApplyWindowLayout ',IDEWindowStateNames[WindowState]]);
case WindowState of
iwsMinimized: xForm.WindowState:=wsMinimized;
iwsMaximized: xForm.WindowState:=wsMaximized;
end;
Result := ValidateAndSetCoordinates(aForce); // Adjust bounds to screen area and apply them.
if WindowState in [iwsMinimized, iwsMaximized] then
Result := True;
ApplyDivider;
end;
procedure TSimpleWindowLayout.ApplyDivider;
var
i: Integer;
Creator: TIDEWindowCreator;
begin
Creator:=IDEWindowCreators.FindWithName(FormID);
if (Creator <> nil) and (Creator.OnSetDividerSize <> nil) then begin
for i := 0 to FDividers.Count - 1 do begin
if (FDividers[i].FId < 0) or (FDividers[i].Size < 0) then continue;
Creator.OnSetDividerSize(Form, FDividers[i].Id, FDividers[i].Size);
end;
end;
end;
{ TSimpleWindowLayoutList }
procedure TSimpleWindowLayoutList.Clear;
var
i: integer;
begin
for i:=0 to Count-1 do Items[i].Free;
fItems.Clear;
end;
procedure TSimpleWindowLayoutList.Delete(Index: Integer);
begin
Items[Index].Free;
fItems.Delete(Index);
end;
function TSimpleWindowLayoutList.GetItems(Index: Integer): TSimpleWindowLayout;
begin
Result:=TSimpleWindowLayout(fItems[Index]);
end;
procedure TSimpleWindowLayoutList.OnScreenRemoveForm(Sender: TObject;
AForm: TCustomForm);
begin
CloseForm(AForm);
end;
constructor TSimpleWindowLayoutList.Create(ARegisterEventHandlers: Boolean);
begin
fItems:=TFPList.Create;
fRegisterEventHandlers := ARegisterEventHandlers;
if ARegisterEventHandlers then
Screen.AddHandlerRemoveForm(@OnScreenRemoveForm);
end;
destructor TSimpleWindowLayoutList.Destroy;
begin
Screen.RemoveHandlerRemoveForm(@OnScreenRemoveForm);
Clear;
FreeAndNil(fItems);
inherited Destroy;
end;
function TSimpleWindowLayoutList.IndexOf(const FormID: string): integer;
begin
Result:=Count-1;
while (Result>=0) and (FormID<>Items[Result].FormID) do dec(Result);
end;
function TSimpleWindowLayoutList.IndexOf(const AForm: TCustomForm): integer;
begin
Result:=Count-1;
while (Result>=0) and (AForm<>Items[Result].Form) do dec(Result);
end;
procedure TSimpleWindowLayoutList.LoadFromConfig(Config: TConfigStorage; const Path: string);
// do not clear, just add/replace the values from the config
var
i: integer;
ID: String;
xLayoutIndex, FileVersion: Integer;
begin
FileVersion:=Config.GetValue(Path+'Desktop/Version', IDEWndCfgFileVersion);
// create new windows
i := Config.GetValue(Path+'Desktop/FormIdCount', 0);
//debugln(['TSimpleWindowLayoutList.LoadFromConfig ',i]);
while i > 0 do begin
ID := Config.GetValue(Path+'Desktop/FormIdList/a'+IntToStr(i), '');
//debugln(['TSimpleWindowLayoutList.LoadFromConfig ',i,' ',ID]);
if IsValidIdent(ID) then
begin
xLayoutIndex := IndexOf(ID);
if (xLayoutIndex = -1) then
begin
CreateWindowLayout(ID);
xLayoutIndex := Count-1;
end;
fItems.Move(xLayoutIndex, 0);
end;
dec(i);
end;
for i:=0 to Count-1 do
Items[i].LoadFromConfig(Config,Path,FileVersion);
end;
procedure TSimpleWindowLayoutList.MoveToTop(const AFormID: string);
var
I: Integer;
begin
I := IndexOf(AFormID);
if I>=0 then
fItems.Move(I, fItems.Count-1);
end;
procedure TSimpleWindowLayoutList.SaveToConfig(Config: TConfigStorage; const Path: string);
var
i: integer;
begin
Config.SetValue(Path+'Desktop/Version', IDEWndCfgFileVersion);
Config.SetDeleteValue(Path+'Desktop/FormIdCount',Count,0);
//debugln(['TSimpleWindowLayoutList.SaveToConfig ',Count]);
for i:=0 to Count-1 do begin
Config.SetDeleteValue(Path+'Desktop/FormIdList/a'+IntToStr(i+1),Items[i].FormID,'');
Items[i].SaveToConfig(Config,Path);
end;
end;
procedure TSimpleWindowLayoutList.SetDefaultPosition(const AForm: TCustomForm);
var
xLayout: TSimpleWindowLayout;
begin
if AForm.Name <> '' then
begin
xLayout:=ItemByFormID(AForm.Name);
if xLayout<>nil then
xLayout.SetDefaultPosition(AForm);
end;
end;
function TSimpleWindowLayoutList.Count: integer;
begin
Result:=fItems.Count;
end;
function TSimpleWindowLayoutList.ItemByForm(AForm: TCustomForm): TSimpleWindowLayout;
var
i: integer;
begin
i:=IndexOf(AForm);
if i>=0 then
Result:=Items[i]
else
Result:=nil;
end;
function TSimpleWindowLayoutList.ItemByFormID(const FormID: string): TSimpleWindowLayout;
var
i: integer;
begin
i:=IndexOf(FormID);
if i>=0 then
Result:=Items[i]
else
Result:=nil;
end;
function TSimpleWindowLayoutList.ItemByFormCaption(const aFormCaption: string): TSimpleWindowLayout;
var
i: integer;
begin
i := Count - 1;
while i >= 0 do begin
Result := Items[i];
if Result.FormCaption = aFormCaption then
exit;
dec(i);
end;
Result:=nil;
end;
procedure TSimpleWindowLayoutList.CloseForm(AForm: TCustomForm);
var
ALayout: TSimpleWindowLayout;
begin
ALayout:=ItemByForm(AForm);
if ALayout<>nil then
ALayout.CloseForm;
end;
procedure TSimpleWindowLayoutList.ApplyAndShow(Sender: TObject; AForm: TCustomForm;
BringToFront: boolean; AMoveToVisbleMode: TLayoutMoveToVisbleMode);
function IsFormMovable(AForm: TCustomForm; BorderX: Integer = 100;
BorderTop: Integer = 0; BorderBottom: Integer = 50): Boolean;
var
I: Integer;
xFormRect, xWA, xRectLT, xRectRT, xRectCT: TRect;
begin
xFormRect := AForm.BoundsRect;
Result := False;
for I := 0 to Screen.MonitorCount-1 do
begin
xWA := Screen.Monitors[I].WorkareaRect;
//the user must be able to move the window
// - that means we check the topleft, topcenter and topright coordinates of the form
// if they are movable
xRectLT := Rect(xWA.Left-BorderX, xWA.Top-BorderTop, xWA.Right-BorderX, xWA.Bottom-BorderBottom);
xRectCT := Rect(xWA.Left, xWA.Top-BorderTop, xWA.Right, xWA.Bottom-BorderBottom);
xRectRT := Rect(xWA.Left+BorderX, xWA.Top-BorderTop, BorderX, xWA.Bottom-BorderBottom);
if PtInRect(xRectLT, xFormRect.TopLeft)
or PtInRect(xRectCT, Point((xFormRect.Left+xFormRect.Right) div 2, AForm.Top))
or PtInRect(xRectRT, Point(xFormRect.Right, AForm.Top))
then
Exit(True);
end;
end;
var
ALayout: TSimpleWindowLayout;
NewBounds: TRect;
Creator: TIDEWindowCreator;
DockSiblingName: string;
DockAlign: TAlign;
DockSibling: TCustomForm;
DockSiblingBounds: TRect;
Offset: TPoint;
ARestoreVisible: Boolean;
begin
{$IFDEF VerboseIDEDocking}
debugln(['TSimpleWindowLayoutList.ApplyAndShow Form=',DbgSName(AForm),' ',BringToFront,
' DesktopWidth=', Screen.DesktopWidth, ' DesktopHeight=', Screen.DesktopHeight]);
{$ENDIF}
try
ALayout:=ItemByFormID(AForm.Name);
if ALayout<>nil then
begin
ALayout.Form:=AForm;
if ALayout.Applied then exit;
if ALayout.Apply then exit;
end;
{$IFDEF VerboseIDEDocking}
debugln(['TSimpleWindowLayoutList.ApplyAndShow no stored layout found, layout registered=',
ALayout<>nil,' AForm=',DbgSName(AForm)]);
{$ENDIF}
// no layout found => use default
Creator:=IDEWindowCreators.FindWithName(AForm.Name);
if Creator<>nil then
begin
if Creator.OnGetLayout<>nil then
Creator.OnGetLayout(Self,AForm.Name,NewBounds,DockSiblingName,DockAlign)
else begin
Creator.GetDefaultBounds(AForm,NewBounds);
DockSiblingName:=Creator.DockSibling;
DockAlign:=Creator.DockAlign;
end;
{$IFDEF VerboseIDEDocking}
debugln(['TSimpleWindowLayoutList.ApplyAndShow creator found for ',DbgSName(AForm),': Left=',Creator.Left,' Top=',Creator.Top,' Right=',Creator.Right,' Bottom=',Creator.Bottom,' Creator.DockSibling=',Creator.DockSibling,' Creator.DockAlign=',dbgs(Creator.DockAlign),' NewBounds=',dbgs(NewBounds),' DockSibling=',DockSiblingName,' DockAlign=',dbgs(DockAlign)]);
{$ENDIF}
if DockSiblingName<>'' then
begin
DockSibling:=Screen.FindForm(DockSiblingName);
if DockSibling<>nil then
begin
DockSiblingBounds:=DockSibling.BoundsRect;
if DockSibling.Parent<>nil then
begin
Offset:=DockSibling.ClientToScreen(Point(0,0));
OffsetRect(DockSiblingBounds,Offset.X,Offset.Y);
end;
case DockAlign of
alLeft:
begin
NewBounds.Top:=DockSiblingBounds.Top;
NewBounds.Bottom:=DockSiblingBounds.Bottom;
OffsetRect(NewBounds,DockSiblingBounds.Left-6-NewBounds.Right,0);
end;
alRight:
begin
NewBounds.Top:=DockSiblingBounds.Top;
NewBounds.Bottom:=DockSiblingBounds.Bottom;
OffsetRect(NewBounds,DockSiblingBounds.Right+6-NewBounds.Left,0);
end;
alTop:
begin
NewBounds.Left:=DockSiblingBounds.Left;
NewBounds.Right:=DockSiblingBounds.Right;
OffsetRect(NewBounds,0,DockSiblingBounds.Top-25-NewBounds.Bottom);
end;
alBottom:
begin
NewBounds.Left:=DockSiblingBounds.Left;
NewBounds.Right:=DockSiblingBounds.Right;
OffsetRect(NewBounds,0,DockSiblingBounds.Bottom+25-NewBounds.Top);
end;
alClient:
NewBounds:=DockSibling.BoundsRect;
end;
end;
end;
{$IFDEF VerboseIDEDocking}
debugln(['TSimpleWindowLayoutList.ApplyAndShow ',DbgSName(AForm),' NewBounds=',dbgs(NewBounds)]);
{$ENDIF}
NewBounds.Left:=Min(10000,Max(-10000,NewBounds.Left));
NewBounds.Top:=Min(10000,Max(-10000,NewBounds.Top));
NewBounds.Right:=Max(NewBounds.Left+100,NewBounds.Right);
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
AForm.BoundsRect:=NewBounds;
AMoveToVisbleMode := vmOnlyMoveOffScreenToVisible;
end;
finally
if (AForm.WindowState in [wsNormal,wsMaximized]) and BringToFront then
begin
// do not change Visible property while designing form. issue #20602
// we save it into ARestoreVisible before any changes from here.
if IsFormDesign(AForm) then
ARestoreVisible := AForm.Visible;
if (AMoveToVisbleMode = vmAlwaysMoveToVisible) or
( (AMoveToVisbleMode = vmOnlyMoveOffScreenToVisible) and
(not IsFormMovable(AForm)) )
then
AForm.EnsureVisible(true)
else
AForm.ShowOnTop;
if IsFormDesign(AForm) then
AForm.Visible := ARestoreVisible;
end else
begin
if IsFormDesign(AForm) then
ARestoreVisible := AForm.Visible;
AForm.Visible := True;
if (AForm.WindowState in [wsMinimized]) then
begin
if BringToFront then
begin
// issue #19769
if AForm.Visible and not (fsModal in AForm.FormState) then
AForm.Visible := False;
if (AMoveToVisbleMode = vmAlwaysMoveToVisible) or
( (AMoveToVisbleMode = vmOnlyMoveOffScreenToVisible) and
(not IsFormMovable(AForm)) )
then
AForm.EnsureVisible(true)
else
AForm.ShowOnTop;
end;
end;
if IsFormDesign(AForm) then
AForm.Visible := ARestoreVisible;
end;
end;
end;
procedure TSimpleWindowLayoutList.StoreWindowPositions;
var
i: integer;
xOldLayoutIndex: Integer;
begin
//store positions
for i:=0 to Count-1 do
Items[i].GetCurrentPosition;
//store z-order
for i:=Screen.CustomFormCount-1 downto 0 do
begin
xOldLayoutIndex := IndexOf(Screen.CustomForms[i]);
if xOldLayoutIndex > 0 then
fItems.Move(xOldLayoutIndex, 0);
end;
end;
procedure TSimpleWindowLayoutList.CopyItemsFrom(SrcList: TSimpleWindowLayoutList);
var
SrcI: Integer;//index in SrcList
SelfI: Integer;//index in Self
begin
if SrcList=nil then exit;
//do not clear self, always copy items
for SrcI:=0 to SrcList.Count-1 do
begin
SelfI := IndexOf(SrcList[SrcI].FormID);
if SelfI < 0 then
SelfI := Self.Add(TSimpleWindowLayout.Create(SrcList[SrcI].FormID));//not found, create
Self.fItems.Move(SelfI, Min(SrcI, Self.Count-1));//move it to right position
SelfI := SrcI;
Self.Items[SelfI].Assign(SrcList[SrcI])
end;
end;
function TSimpleWindowLayoutList.Add(ALayout: TSimpleWindowLayout): integer;
begin
Result:=fItems.Add(ALayout);
end;
function TSimpleWindowLayoutList.CreateWindowLayout(const TheFormID: string
): TSimpleWindowLayout;
begin
if TheFormID='' then
raise Exception.Create('TEnvironmentOptions.CreateWindowLayout TheFormID empty');
if not IsValidIdent(TheFormID) then
raise Exception.Create('TEnvironmentOptions.CreateWindowLayout TheFormID "'+TheFormID+'" invalid identifier');
if ItemByFormID(TheFormID)<>nil then
raise Exception.Create('TEnvironmentOptions.CreateWindowLayout TheFormID "'+TheFormID+'" already exists');
Result:=TSimpleWindowLayout.Create(TheFormID);
Add(Result);
end;
function TSimpleWindowLayoutList.CreateWindowLayout(const TheForm: TCustomForm
): TSimpleWindowLayout;
begin
Result:=CreateWindowLayout(TheForm.Name);
Result.Form:=TheForm;
end;
{ TIDEWindowCreator }
procedure TIDEWindowCreator.SetBottom(const AValue: string);
begin
CheckBoundValue(AValue);
if FBottom=AValue then exit;
FBottom:=AValue;
end;
function TIDEWindowCreator.GetDividerTemplate: TSimpleWindowLayoutDividerPosList;
begin
If FDividerTemplate = nil then
FDividerTemplate := TSimpleWindowLayoutDividerPosList.Create;
Result := FDividerTemplate;
end;
procedure TIDEWindowCreator.SetLeft(const AValue: string);
begin
CheckBoundValue(AValue);
if FLeft=AValue then exit;
FLeft:=AValue;
end;
procedure TIDEWindowCreator.SetTop(const AValue: string);
begin
CheckBoundValue(AValue);
if FTop=AValue then exit;
FTop:=AValue;
end;
procedure TIDEWindowCreator.SetRight(const AValue: string);
begin
CheckBoundValue(AValue);
if FRight=AValue then exit;
FRight:=AValue;
end;
procedure TIDEWindowCreator.CheckBoundValue(s: string);
var
p: Integer;
begin
if s='' then exit;
p:=1;
if (p<=length(s)) and (s[p] in ['+','-']) then inc(p);
while (p<=length(s)) and (s[p] in ['0'..'9']) do inc(p);
if p<=1 then
raise Exception.Create('TIDEWindowDefaultLayout.CheckBoundValue: expected number, but '+s+' found');
// check for percent
if (p<=length(s)) and (s[p]='%') then inc(p);
if p<=length(s) then
raise Exception.Create('TIDEWindowDefaultLayout.CheckBoundValue: expected number, but '+s+' found');
end;
procedure TIDEWindowCreator.GetDefaultBounds(AForm: TCustomForm; out DefBounds: TRect);
var
aRight: LongInt;
aBottom: LongInt;
ScreenR: TRect;
ScreenW: Integer;
ScreenH: Integer;
begin
ScreenR:=IDEWindowCreators.GetScreenrectForDefaults;
ScreenW:=ScreenR.Right-ScreenR.Left;
ScreenH:=ScreenR.Bottom-ScreenR.Top;
// left
if Left='' then
DefBounds.Left:=ScreenR.Left+AForm.Left
else if Left[length(Left)]='%' then
DefBounds.Left:=ScreenR.Left+ScreenW*StrToIntDef(copy(Left,1,length(Left)-1),0) div 100
else
DefBounds.Left:=ScreenR.Left+StrToIntDef(Left,0);
// top
if Top='' then
DefBounds.Top:=ScreenR.Top+AForm.Top
else if Top[length(Top)]='%' then
DefBounds.Top:=ScreenR.Top+ScreenH*StrToIntDef(copy(Top,1,length(Top)-1),0) div 100
else
DefBounds.Top:=ScreenR.Top+StrToIntDef(Top,0);
// right
if Right='' then
aRight:=DefBounds.Left+AForm.Width
else begin
// 300 = fixed at 300,
// +300 = Left+300
// 30% = fixed at 30% on screen
// +30% = Left+30% of screen
// -300 = fixed 300 from right border of screen
// -30% = fixed 30% from right border of screen
if Right[length(Right)]='%' then
aRight:=ScreenW*StrToIntDef(copy(Right,1,length(Right)-1),0) div 100
else
aRight:=StrToIntDef(Right,0);
if aRight<0 then
aRight:=ScreenR.Right+aRight // relative to right of screen
else if (Right<>'') and (Right[1]='+') then
inc(aRight,DefBounds.Left) // relative to Left
else
inc(aRight,ScreenR.Left); // relative to left of screen
end;
DefBounds.Right:=aRight;
// bottom
if Bottom='' then
aBottom:=DefBounds.Top+AForm.Height
else begin
// 300 = fixed at 300,
// +300 = Top+300
// 30% = fixed at 30% on screen
// +30% = Top+30% of screen
// -300 = fixed 300 from bottom border of screen
// -30% = fixed 30% from bottom border of screen
if Bottom[length(Bottom)]='%' then
aBottom:=ScreenH*StrToIntDef(copy(Bottom,1,length(Bottom)-1),0) div 100
else
aBottom:=StrToIntDef(Bottom,0);
if aBottom<0 then
aBottom:=ScreenR.Bottom+aBottom // relative to bottom of screen
else if (Bottom<>'') and (Bottom[1]='+') then
inc(aBottom,DefBounds.Top) // relative to Top
else
inc(aBottom,ScreenR.Top); // relative to top of screen
end;
DefBounds.Bottom:=aBottom;
end;
function TIDEWindowCreator.CreateSimpleLayout: TSimpleWindowLayout;
begin
Result:=IDEWindowCreators.SimpleLayoutStorage.ItemByFormID(FormName);
if not Assigned(Result) then
begin
Result := IDEWindowCreators.SimpleLayoutStorage.CreateWindowLayout(FormName);
InitSimpleLayout(Result);
end;
end;
procedure TIDEWindowCreator.InitSimpleLayout(ALayout: TSimpleWindowLayout);
begin
if FDividerTemplate <> nil then
ALayout.Dividers.Assign(FDividerTemplate);
end;
constructor TIDEWindowCreator.Create(aFormName: string);
begin
FFormName:=aFormName;
FDividerTemplate := nil;
end;
constructor TIDEWindowCreator.Create(aFormName: string;
CreateFormProc: TCreateIDEWindowProc;
CreateFormMethod: TCreateIDEWindowMethod;
aLeft, aTop, aRight, aBottom: string; aDockSibling: string; aDockAlign: TAlign; aMulti: boolean;
GetLayoutEvent: TGetDefaultIDEWindowLayoutEvent);
begin
Create(aFormName);
FMulti:=aMulti;
Left:=aLeft;
Top:=aTop;
Right:=aRight;
Bottom:=aBottom;
DockSibling:=aDockSibling;
DockAlign:=aDockAlign;
OnCreateFormMethod:=CreateFormMethod;
OnCreateFormProc:=CreateFormProc;
OnGetLayout:=GetLayoutEvent;
end;
destructor TIDEWindowCreator.Destroy;
begin
inherited Destroy;
FreeAndNil(FDividerTemplate);
end;
function TIDEWindowCreator.NameFits(const AName: string): boolean;
begin
Result:=CompareText(copy(AName,1,Length(FormName)),FormName)=0;
end;
{ TIDEWindowCreatorList }
function TIDEWindowCreatorList.GetItems(Index: integer): TIDEWindowCreator;
begin
Result:=TIDEWindowCreator(fItems[Index]);
end;
procedure TIDEWindowCreatorList.ErrorIfFormExists(FormName: string);
begin
if IndexOfName(FormName)>=0 then
raise Exception.Create('TIDEWindowDefaultLayoutList.Add: form name '+FormName+' already exists');
end;
constructor TIDEWindowCreatorList.Create;
begin
fItems:=TFPList.Create;
FSimpleLayoutStorage:=TSimpleWindowLayoutList.Create(True);
FOnLayoutChanged:=TMethodList.Create;
end;
destructor TIDEWindowCreatorList.Destroy;
begin
Clear;
FreeAndNil(fItems);
FreeAndNil(FSimpleLayoutStorage);
FOnLayoutChanged.Free;
inherited Destroy;
end;
procedure TIDEWindowCreatorList.Clear;
var
i: Integer;
begin
for i:=0 to fItems.Count-1 do
TObject(fItems[i]).Free;
end;
function TIDEWindowCreatorList.Count: integer;
begin
Result:=fItems.Count;
end;
function TIDEWindowCreatorList.Add(aLayout: TIDEWindowCreator): integer;
begin
ErrorIfFormExists(aLayout.FormName);
Result:=fItems.Add(aLayout);
end;
procedure TIDEWindowCreatorList.AddLayoutChangedHandler(const aEvent: TNotifyEvent);
begin
FOnLayoutChanged.Add(TMethod(aEvent));
end;
function TIDEWindowCreatorList.Add(aFormName: string): TIDEWindowCreator;
begin
ErrorIfFormExists(aFormName);
Result:=TIDEWindowCreator.Create(aFormName);
Add(Result);
end;
function TIDEWindowCreatorList.Add(aFormName: string;
CreateFormProc: TCreateIDEWindowProc;
CreateFormMethod: TCreateIDEWindowMethod;
aLeft, aTop, aRight, aBottom: string;
aDockSibling: string; aDockAlign: TAlign; aMulti: boolean;
GetLayoutEvent: TGetDefaultIDEWindowLayoutEvent): TIDEWindowCreator;
begin
ErrorIfFormExists(aFormName);
Result:=TIDEWindowCreator.Create(aFormName,CreateFormProc,CreateFormMethod,
aLeft,aTop,aRight,aBottom,aDockSibling,aDockAlign,aMulti,GetLayoutEvent);
Add(Result);
end;
procedure TIDEWindowCreatorList.Delete(Index: integer);
begin
TObject(fItems[Index]).Free;
fItems.Delete(Index);
end;
function TIDEWindowCreatorList.IndexOfName(FormName: string): integer;
begin
Result:=Count-1;
while (Result>=0) and not Items[Result].NameFits(FormName) do
dec(Result);
end;
procedure TIDEWindowCreatorList.LayoutChanged;
var
I: Integer;
xEvent: TNotifyEvent;
begin
for I := 0 to FOnLayoutChanged.Count-1 do
begin
xEvent := TNotifyEvent(FOnLayoutChanged[I]);
xEvent(Self);
end;
end;
procedure TIDEWindowCreatorList.RemoveLayoutChangedHandler(
const aEvent: TNotifyEvent);
begin
FOnLayoutChanged.Remove(TMethod(aEvent));
end;
function TIDEWindowCreatorList.FindWithName(FormName: string): TIDEWindowCreator;
var
i: LongInt;
begin
i:=IndexOfName(FormName);
if i>=0 then
Result:=Items[i]
else
Result:=nil;
end;
function TIDEWindowCreatorList.GetForm(aFormName: string; AutoCreate: boolean;
DisableAutoSizing: boolean): TCustomForm;
var
Item: TIDEWindowCreator;
begin
Result:=Screen.FindForm(aFormName);
if Result<>nil then begin
if DisableAutoSizing then
Result.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster Delayed'){$ENDIF};
exit;
end;
if AutoCreate then begin
Item:=FindWithName(aFormName);
if Item=nil then begin
debugln(['TIDEWindowCreatorList.GetForm no creator for ',aFormName]);
exit;
end;
if Assigned(Item.OnCreateFormProc) then begin
Item.OnCreateFormProc(Self,aFormName,Result,DisableAutoSizing);
end else if Assigned(Item.OnCreateFormMethod) then begin
Item.OnCreateFormMethod(Self,aFormName,Result,DisableAutoSizing);
end else begin
debugln(['TIDEWindowCreatorList.GetForm no OnCreateForm for ',aFormName]);
exit;
end;
if Result=nil then begin
debugln(['TIDEWindowCreatorList.GetForm create failed for ',aFormName]);
exit;
end;
SimpleLayoutStorage.SetDefaultPosition(Result);
end;
end;
procedure TIDEWindowCreatorList.ShowForm(AForm: TCustomForm; BringToFront: boolean;
AMoveToVisbleMode: TLayoutMoveToVisbleMode);
var
Layout: TSimpleWindowLayout;
begin
if not IsValidIdent(AForm.Name) then
raise Exception.Create('TIDEWindowCreatorList.ShowForm invalid form name '+AForm.Name);
// auto create a layout storage for every shown form
Layout:=SimpleLayoutStorage.ItemByFormID(AForm.Name);
if Layout=nil then begin
if not IsFormDesign(AForm) then
SimpleLayoutStorage.CreateWindowLayout(AForm);
end
else
Layout.Form:=AForm;
if (IDEDockMaster<>nil) and (not IsFormDesign(AForm))
and (FindWithName(AForm.Name)<>nil) then
// show dockable if it has a creator and is not a designer form
IDEDockMaster.ShowForm(AForm,BringToFront)
else
if (IDETabMaster <> nil) and IsFormDesign(AForm) then
IDETabMaster.ShowForm(AForm)
else
SimpleLayoutStorage.ApplyAndShow(Self,AForm,BringToFront,AMoveToVisbleMode);
end;
function TIDEWindowCreatorList.ShowForm(AFormName: string; BringToFront: boolean): TCustomForm;
begin
Result:=GetForm(AFormName,true,false);
if Result<>nil then
ShowForm(Result,BringToFront);
end;
procedure TIDEWindowCreatorList.CreateForm(var AForm;
AFormClass: TCustomFormClass; DoDisableAutoSizing: boolean;
TheOwner: TComponent);
begin
if TCustomForm(AForm)=nil then begin
TCustomForm(AForm):=TCustomForm(AFormClass.NewInstance);
{$IFDEF DebugDisableAutoSizing}
if DoDisableAutoSizing then
TCustomForm(AForm).DisableAutoSizing('TAnchorDockMaster Delayed')
else
TCustomForm(AForm).DisableAutoSizing('TIDEWindowCreatorList.CreateForm');
{$ELSE}
TCustomForm(AForm).DisableAutoSizing;
{$ENDIF};
try
TCustomForm(AForm).Create(TheOwner);
finally
if not DoDisableAutoSizing then
TCustomForm(AForm).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TIDEWindowCreatorList.CreateForm'){$ENDIF};
end;
SimpleLayoutStorage.SetDefaultPosition(TCustomForm(AForm));
end else if DoDisableAutoSizing then
TCustomForm(AForm).DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster Delayed'){$ENDIF};
end;
procedure TIDEWindowCreatorList.RestoreSimpleLayout;
var
i: Integer;
ALayout: TSimpleWindowLayout;
AForm: TCustomForm;
HasChanged: Boolean;
AChangeVisibility: Boolean;
begin
if IDEDockMaster=nil then
begin
HasChanged:=false;
for i:=SimpleLayoutStorage.Count-1 downto 0 do//loop down in order to keep z-order of the forms
begin
ALayout:=SimpleLayoutStorage[i];
AChangeVisibility := IDEWindowsGlobalOptions.CanSetVisibility(ALayout.FormID);
AForm:=GetForm(ALayout.FormID,AChangeVisibility and ALayout.Visible);
if AForm=nil then Continue;
HasChanged:=true;
ALayout.Apply(AChangeVisibility);
if AChangeVisibility then
begin
if ALayout.Visible or (AForm=Application.MainForm) then
ShowForm(AForm,true,vmOnlyMoveOffScreenToVisible)
else if AForm.Visible then
AForm.Close;
end else
begin//do not change visibility
if AForm.Visible then//Only make sure their z-index is OK if they are already visible
ShowForm(AForm,true)
end;
end;
if HasChanged then
LayoutChanged;
end;
end;
function TIDEWindowCreatorList.GetScreenrectForDefaults: TRect;
begin
Result:=Screen.WorkAreaRect;
if (Result.Right-Result.Left<10)
or (Result.Bottom-Result.Top<10) then begin
// screen not recognized
Result:=Rect(0,0,
Max(Screen.Width,MulDiv(600, Screen.PixelsPerInch, 96)),
Max(Screen.Height,MulDiv(400, Screen.PixelsPerInch, 96)));
end;
end;
{ TIDEDockMaster }
function TIDEDockMaster.AddableInWindowMenu(AForm: TCustomForm): boolean;
begin
Result:=true;
end;
procedure TIDEDockMaster.AdjustMainIDEWindowHeight(
const AIDEWindow: TCustomForm; const AAdjustHeight: Boolean;
const ANewHeight: Integer);
begin
end;
procedure TIDEDockMaster.CloseAll;
begin
CloseAllForms;
end;
initialization
IDEWindowCreators:=TIDEWindowCreatorList.Create;
IDEDialogLayoutList:=TIDEDialogLayoutList.Create;
finalization
FreeAndNil(IDEWindowCreators);
FreeAndNil(IDEDialogLayoutList);
FreeAndNil(FIDEWindowsGlobalOptions);
end.
|