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
|
//
// ToolStripItem.cs
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2006 Jonathan Pobst
//
// Authors:
// Jonathan Pobst (monkey@jpobst.com)
//
using System;
using System.Drawing;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace System.Windows.Forms
{
[DefaultEvent ("Click")]
[DefaultProperty ("Text")]
[DesignTimeVisible (false)]
[ToolboxItem (false)]
[Designer ("System.Windows.Forms.Design.ToolStripItemDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
public abstract class ToolStripItem : Component, IDropTarget, IComponent, IDisposable
{
#region Private Variables
private AccessibleObject accessibility_object;
private string accessible_default_action_description;
private bool allow_drop;
private ToolStripItemAlignment alignment;
private AnchorStyles anchor;
private bool available;
private bool auto_size;
private bool auto_tool_tip;
private Color back_color;
private Image background_image;
private ImageLayout background_image_layout;
private Rectangle bounds;
private bool can_select;
private ToolStripItemDisplayStyle display_style;
private DockStyle dock;
private bool double_click_enabled;
private bool enabled;
private Size explicit_size;
private Font font;
private Color fore_color;
private Image image;
private ContentAlignment image_align;
private int image_index;
private string image_key;
private ToolStripItemImageScaling image_scaling;
private Color image_transparent_color;
private bool is_disposed;
internal bool is_pressed;
private bool is_selected;
private Padding margin;
private MergeAction merge_action;
private int merge_index;
private string name;
private ToolStripItemOverflow overflow;
private ToolStrip owner;
internal ToolStripItem owner_item;
private Padding padding;
private ToolStripItemPlacement placement;
private RightToLeft right_to_left;
private bool right_to_left_auto_mirror_image;
private Object tag;
private string text;
private ContentAlignment text_align;
private ToolStripTextDirection text_direction;
private TextImageRelation text_image_relation;
private string tool_tip_text;
private bool visible;
private EventHandler frame_handler; // For animating images
private ToolStrip parent;
private Size text_size;
#endregion
#region Public Constructors
protected ToolStripItem ()
: this (String.Empty, null, null, String.Empty)
{
}
protected ToolStripItem (string text, Image image, EventHandler onClick)
: this (text, image, onClick, String.Empty)
{
}
protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
{
this.alignment = ToolStripItemAlignment.Left;
this.anchor = AnchorStyles.Left | AnchorStyles.Top;
this.auto_size = true;
this.auto_tool_tip = this.DefaultAutoToolTip;
this.available = true;
this.back_color = Color.Empty;
this.background_image_layout = ImageLayout.Tile;
this.can_select = true;
this.display_style = this.DefaultDisplayStyle;
this.dock = DockStyle.None;
this.enabled = true;
this.fore_color = Color.Empty;
this.image = image;
this.image_align = ContentAlignment.MiddleCenter;
this.image_index = -1;
this.image_key = string.Empty;
this.image_scaling = ToolStripItemImageScaling.SizeToFit;
this.image_transparent_color = Color.Empty;
this.margin = this.DefaultMargin;
this.merge_action = MergeAction.Append;
this.merge_index = -1;
this.name = name;
this.overflow = ToolStripItemOverflow.AsNeeded;
this.padding = this.DefaultPadding;
this.placement = ToolStripItemPlacement.None;
this.right_to_left = RightToLeft.Inherit;
this.bounds.Size = this.DefaultSize;
this.text = text;
this.text_align = ContentAlignment.MiddleCenter;
this.text_direction = DefaultTextDirection;
this.text_image_relation = TextImageRelation.ImageBeforeText;
this.visible = true;
this.Click += onClick;
OnLayout (new LayoutEventArgs (null, string.Empty));
}
#endregion
#region Public Properties
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public AccessibleObject AccessibilityObject {
get {
if (this.accessibility_object == null)
this.accessibility_object = CreateAccessibilityInstance ();
return this.accessibility_object;
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public string AccessibleDefaultActionDescription {
get {
if (this.accessibility_object == null)
return null;
return this.accessible_default_action_description;
}
set { this.accessible_default_action_description = value; }
}
[Localizable (true)]
[DefaultValue (null)]
public string AccessibleDescription {
get {
if (this.accessibility_object == null)
return null;
return this.AccessibilityObject.Description;
}
set { this.AccessibilityObject.description = value; }
}
[Localizable (true)]
[DefaultValue (null)]
public string AccessibleName {
get {
if (this.accessibility_object == null)
return null;
return this.AccessibilityObject.Name;
}
set { this.AccessibilityObject.Name = value; }
}
[DefaultValue (AccessibleRole.Default)]
public AccessibleRole AccessibleRole {
get
{
if (this.accessibility_object == null)
return AccessibleRole.Default;
return this.AccessibilityObject.Role;
}
set { this.AccessibilityObject.role = value; }
}
[DefaultValue (ToolStripItemAlignment.Left)]
public ToolStripItemAlignment Alignment {
get { return this.alignment; }
set {
if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
if (this.alignment != value) {
this.alignment = value;
this.CalculateAutoSize ();
}
}
}
[MonoTODO ("Stub, does nothing")]
[Browsable (false)]
[DefaultValue (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public virtual bool AllowDrop {
get { return this.allow_drop; }
set { this.allow_drop = value; }
}
[Browsable (false)]
[DefaultValue (AnchorStyles.Top | AnchorStyles.Left)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public AnchorStyles Anchor {
get { return this.anchor; }
set { this.anchor = value; }
}
[Localizable (true)]
[DefaultValue (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
[RefreshProperties (RefreshProperties.All)]
public bool AutoSize {
get { return this.auto_size; }
set {
this.auto_size = value;
this.CalculateAutoSize ();
}
}
[DefaultValue (false)]
public bool AutoToolTip {
get { return this.auto_tool_tip; }
set { this.auto_tool_tip = value; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public bool Available {
get { return this.available; }
set {
if (this.available != value) {
available = value;
visible = value;
if (this.parent != null)
parent.PerformLayout ();
OnAvailableChanged (EventArgs.Empty);
OnVisibleChanged (EventArgs.Empty);
}
}
}
public virtual Color BackColor {
get {
if (back_color != Color.Empty)
return back_color;
if (Parent != null)
return parent.BackColor;
return Control.DefaultBackColor;
}
set {
if (this.back_color != value) {
back_color = value;
OnBackColorChanged (EventArgs.Empty);
this.Invalidate ();
}
}
}
[Localizable (true)]
[DefaultValue (null)]
public virtual Image BackgroundImage {
get { return this.background_image; }
set {
if (this.background_image != value) {
this.background_image = value;
this.Invalidate ();
}
}
}
[Localizable (true)]
[DefaultValue (ImageLayout.Tile)]
public virtual ImageLayout BackgroundImageLayout {
get { return this.background_image_layout; }
set {
if (this.background_image_layout != value) {
this.background_image_layout = value;
this.Invalidate ();
}
}
}
[Browsable (false)]
public virtual Rectangle Bounds {
get { return this.bounds; }
}
[Browsable (false)]
public virtual bool CanSelect {
get { return this.can_select; }
}
[Browsable (false)]
public Rectangle ContentRectangle {
get {
// ToolStripLabels don't have a border
if (this is ToolStripLabel || this is ToolStripStatusLabel)
return new Rectangle (0, 0, this.bounds.Width, this.bounds.Height);
if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
return new Rectangle (2, 2, this.bounds.Width - 13, this.bounds.Height - 4);
return new Rectangle (2, 2, this.bounds.Width - 4, this.bounds.Height - 4);
}
}
public virtual ToolStripItemDisplayStyle DisplayStyle {
get { return this.display_style; }
set {
if (this.display_style != value) {
this.display_style = value;
this.CalculateAutoSize ();
OnDisplayStyleChanged (EventArgs.Empty);
}
}
}
[Browsable (false)]
public bool IsDisposed {
get { return this.is_disposed; }
}
[Browsable (false)]
[DefaultValue (DockStyle.None)]
public DockStyle Dock {
get { return this.dock; }
set {
if (this.dock != value) {
if (!Enum.IsDefined (typeof (DockStyle), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for DockStyle", value));
this.dock = value;
this.CalculateAutoSize ();
}
}
}
[DefaultValue (false)]
public bool DoubleClickEnabled {
get { return this.double_click_enabled; }
set { this.double_click_enabled = value; }
}
[Localizable (true)]
[DefaultValue (true)]
public virtual bool Enabled {
get {
if (Parent != null)
if (!Parent.Enabled)
return false;
if (Owner != null)
if (!Owner.Enabled)
return false;
return enabled;
}
set {
if (this.enabled != value) {
this.enabled = value;
OnEnabledChanged (EventArgs.Empty);
this.Invalidate ();
}
}
}
[Localizable (true)]
public virtual Font Font {
get {
if (font != null)
return font;
if (Parent != null)
return Parent.Font;
return DefaultFont;
}
set {
if (this.font != value) {
this.font = value;
this.CalculateAutoSize ();
this.OnFontChanged (EventArgs.Empty);
this.Invalidate ();
}
}
}
public virtual Color ForeColor {
get {
if (fore_color != Color.Empty)
return fore_color;
if (Parent != null)
return parent.ForeColor;
return Control.DefaultForeColor;
}
set {
if (this.fore_color != value) {
this.fore_color = value;
this.OnForeColorChanged (EventArgs.Empty);
this.Invalidate ();
}
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Always)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public int Height {
get { return this.Size.Height; }
set {
this.Size = new Size (this.Size.Width, value);
this.explicit_size.Height = value;
if (this.Visible) {
this.CalculateAutoSize ();
this.OnBoundsChanged ();
this.Invalidate ();
}
}
}
[Localizable (true)]
public virtual Image Image {
get {
if (this.image != null)
return this.image;
if (this.image_index >= 0)
if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
return this.owner.ImageList.Images[this.image_index];
if (!string.IsNullOrEmpty (this.image_key))
if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
return this.owner.ImageList.Images[this.image_key];
return null;
}
set {
if (this.image != value) {
StopAnimation ();
this.image = value;
this.image_index = -1;
this.image_key = string.Empty;
this.CalculateAutoSize ();
this.Invalidate ();
BeginAnimation ();
}
}
}
[Localizable (true)]
[DefaultValue (ContentAlignment.MiddleCenter)]
public ContentAlignment ImageAlign {
get { return this.image_align; }
set {
if (!Enum.IsDefined (typeof (ContentAlignment), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
if (image_align != value) {
this.image_align = value;
this.CalculateAutoSize ();
}
}
}
[Localizable (true)]
[Browsable (false)]
[RelatedImageList ("Owner.ImageList")]
[TypeConverter (typeof (NoneExcludedImageIndexConverter))]
[RefreshProperties (RefreshProperties.Repaint)]
[Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
public int ImageIndex {
get { return this.image_index; }
set {
if (this.image_index != value) {
// Lamespec: MSDN says ArgumentException, tests say otherwise
if (value < -1)
throw new ArgumentOutOfRangeException ("ImageIndex cannot be less than -1");
this.image_index = value;
this.image = null;
this.image_key = string.Empty;
this.CalculateAutoSize ();
this.Invalidate ();
}
}
}
[Localizable (true)]
[Browsable (false)]
[RelatedImageList ("Owner.ImageList")]
[TypeConverter (typeof (ImageKeyConverter))]
[RefreshProperties (RefreshProperties.Repaint)]
[Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
public string ImageKey {
get { return this.image_key; }
set {
if (this.image_key != value) {
this.image = null;
this.image_index = -1;
this.image_key = value;
this.CalculateAutoSize ();
this.Invalidate ();
}
}
}
[Localizable (true)]
[DefaultValue (ToolStripItemImageScaling.SizeToFit)]
public ToolStripItemImageScaling ImageScaling {
get { return this.image_scaling; }
set {
if (image_scaling != value) {
this.image_scaling = value;
this.CalculateAutoSize ();
}
}
}
[Localizable (true)]
public Color ImageTransparentColor {
get { return this.image_transparent_color; }
set { this.image_transparent_color = value; }
}
[Browsable (false)]
public bool IsOnDropDown {
get {
if (this.parent != null && this.parent is ToolStripDropDown)
return true;
return false;
}
}
[Browsable (false)]
public bool IsOnOverflow {
get { return this.placement == ToolStripItemPlacement.Overflow; }
}
public Padding Margin {
get { return this.margin; }
set {
this.margin = value;
this.CalculateAutoSize ();
}
}
[DefaultValue (MergeAction.Append)]
public MergeAction MergeAction {
get { return this.merge_action; }
set {
if (!Enum.IsDefined (typeof (MergeAction), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for MergeAction", value));
this.merge_action = value;
}
}
[DefaultValue (-1)]
public int MergeIndex {
get { return this.merge_index; }
set { this.merge_index = value; }
}
[DefaultValue (null)]
[Browsable (false)]
public string Name {
get { return this.name; }
set { this.name = value; }
}
[DefaultValue (ToolStripItemOverflow.AsNeeded)]
public ToolStripItemOverflow Overflow {
get { return this.overflow; }
set {
if (this.overflow != value) {
if (!Enum.IsDefined (typeof (ToolStripItemOverflow), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemOverflow", value));
this.overflow = value;
if (owner != null)
owner.PerformLayout ();
}
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public ToolStrip Owner {
get { return this.owner; }
set {
if (this.owner != value) {
if (this.owner != null)
this.owner.Items.Remove (this);
if (value != null)
value.Items.Add (this);
else
this.owner = null;
}
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public ToolStripItem OwnerItem {
get { return this.owner_item; }
}
public virtual Padding Padding {
get { return this.padding; }
set {
this.padding = value;
this.CalculateAutoSize ();
this.Invalidate ();
}
}
[Browsable (false)]
public ToolStripItemPlacement Placement {
get { return this.placement; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public virtual bool Pressed { get { return this.is_pressed; } }
[MonoTODO ("RTL not implemented")]
[Localizable (true)]
public virtual RightToLeft RightToLeft {
get { return this.right_to_left; }
set {
if (this.right_to_left != value) {
this.right_to_left = value;
this.OnRightToLeftChanged (EventArgs.Empty);
}
}
}
[Localizable (true)]
[DefaultValue (false)]
public bool RightToLeftAutoMirrorImage {
get { return this.right_to_left_auto_mirror_image; }
set {
if (this.right_to_left_auto_mirror_image != value) {
this.right_to_left_auto_mirror_image = value;
this.Invalidate ();
}
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public virtual bool Selected { get { return this.is_selected; } }
[Localizable (true)]
public virtual Size Size {
get {
if (!this.AutoSize && this.explicit_size != Size.Empty)
return this.explicit_size;
return this.bounds.Size;
}
set {
this.bounds.Size = value;
this.explicit_size = value;
if (this.Visible) {
this.CalculateAutoSize ();
this.OnBoundsChanged ();
}
}
}
[Localizable (false)]
[Bindable (true)]
[DefaultValue (null)]
[TypeConverter (typeof (StringConverter))]
public Object Tag {
get { return this.tag; }
set { this.tag = value; }
}
[Localizable (true)]
[DefaultValue ("")]
public virtual string Text
{
get { return this.text; }
set {
if (this.text != value) {
this.text = value;
this.Invalidate ();
this.CalculateAutoSize ();
this.Invalidate ();
this.OnTextChanged (EventArgs.Empty);
}
}
}
[Localizable (true)]
[DefaultValue (ContentAlignment.MiddleCenter)]
public virtual ContentAlignment TextAlign {
get { return this.text_align; }
set {
if (!Enum.IsDefined (typeof (ContentAlignment), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
if (this.text_align != value) {
this.text_align = value;
this.CalculateAutoSize ();
}
}
}
public virtual ToolStripTextDirection TextDirection {
get {
if (this.text_direction == ToolStripTextDirection.Inherit) {
if (this.Parent != null)
return this.Parent.TextDirection;
else
return ToolStripTextDirection.Horizontal;
}
return this.text_direction;
}
set {
if (!Enum.IsDefined (typeof (ToolStripTextDirection), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripTextDirection", value));
if (this.text_direction != value) {
this.text_direction = value;
this.CalculateAutoSize ();
this.Invalidate ();
}
}
}
[Localizable (true)]
[DefaultValue (TextImageRelation.ImageBeforeText)]
public TextImageRelation TextImageRelation {
get { return this.text_image_relation; }
set {
this.text_image_relation = value;
this.CalculateAutoSize ();
this.Invalidate ();
}
}
[Localizable (true)]
[Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
"System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
public string ToolTipText {
get { return this.tool_tip_text; }
set { this.tool_tip_text = value; }
}
[Localizable (true)]
public bool Visible {
get {
if (this.parent == null)
return false;
return this.visible && this.parent.Visible;
}
set {
if (this.visible != value) {
this.available = value;
this.SetVisibleCore (value);
if (this.Owner != null)
this.Owner.PerformLayout ();
}
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Always)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public int Width {
get { return this.Size.Width; }
set {
this.Size = new Size (value, this.Size.Height);
this.explicit_size.Width = value;
if (this.Visible) {
this.CalculateAutoSize ();
this.OnBoundsChanged ();
this.Invalidate ();
}
}
}
#endregion
#region Protected Properties
protected virtual bool DefaultAutoToolTip { get { return false; } }
protected virtual ToolStripItemDisplayStyle DefaultDisplayStyle { get { return ToolStripItemDisplayStyle.ImageAndText; } }
protected internal virtual Padding DefaultMargin { get { return new Padding (0, 1, 0, 2); } }
protected virtual Padding DefaultPadding { get { return new Padding (); } }
protected virtual Size DefaultSize { get { return new Size (23, 23); } }
protected internal virtual bool DismissWhenClicked { get { return true; } }
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
protected internal ToolStrip Parent {
get { return this.parent; }
set {
if (this.parent != value) {
ToolStrip old_parent = this.parent;
this.parent = value;
OnParentChanged(old_parent, this.parent);
}
}
}
protected internal virtual bool ShowKeyboardCues { get { return false; } }
#endregion
#region Public Methods
[MonoTODO ("Stub, does nothing")]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public DragDropEffects DoDragDrop (Object data, DragDropEffects allowedEffects)
{
return allowedEffects;
}
public ToolStrip GetCurrentParent ()
{
return this.parent;
}
public virtual Size GetPreferredSize (Size constrainingSize)
{
return this.CalculatePreferredSize (constrainingSize);
}
public void Invalidate ()
{
if (parent != null)
parent.Invalidate (this.bounds);
}
public void Invalidate (Rectangle r)
{
if (parent != null)
parent.Invalidate (r);
}
public void PerformClick ()
{
this.OnClick (EventArgs.Empty);
}
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetBackColor () { this.BackColor = Color.Empty; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetFont () { this.font = null; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetForeColor () { this.ForeColor = Color.Empty; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetImage () { this.image = null; }
[EditorBrowsable (EditorBrowsableState.Never)]
public void ResetMargin () { this.margin = this.DefaultMargin; }
[EditorBrowsable (EditorBrowsableState.Never)]
public void ResetPadding () { this.padding = this.DefaultPadding; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetRightToLeft () { this.right_to_left = RightToLeft.Inherit; }
[EditorBrowsable (EditorBrowsableState.Never)]
public virtual void ResetTextDirection () { this.TextDirection = this.DefaultTextDirection; }
public void Select ()
{
if (!this.is_selected && this.CanSelect) {
this.is_selected = true;
if (this.Parent != null) {
if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
(this as ToolStripControlHost).Focus ();
this.Invalidate ();
this.Parent.NotifySelectedChanged (this);
}
OnUIASelectionChanged ();
}
}
public override string ToString ()
{
return this.text;
}
#endregion
#region Protected Methods
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual AccessibleObject CreateAccessibilityInstance ()
{
return new ToolStripItemAccessibleObject (this);
}
protected override void Dispose (bool disposing)
{
if (!is_disposed && disposing)
is_disposed = true;
if (image != null) {
StopAnimation ();
image = null;
}
if (owner != null && disposing)
owner.Items.Remove (this);
base.Dispose (disposing);
}
protected internal virtual bool IsInputChar (char charCode)
{
return false;
}
protected internal virtual bool IsInputKey (Keys keyData)
{
return false;
}
protected virtual void OnAvailableChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [AvailableChangedEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnBackColorChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnBoundsChanged ()
{
OnLayout (new LayoutEventArgs(null, string.Empty));
}
protected virtual void OnClick (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [ClickEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnDisplayStyleChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [DisplayStyleChangedEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnDoubleClick (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnDragDrop (DragEventArgs dragEvent)
{
DragEventHandler eh = (DragEventHandler)(Events[DragDropEvent]);
if (eh != null)
eh (this, dragEvent);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnDragEnter (DragEventArgs dragEvent)
{
DragEventHandler eh = (DragEventHandler)(Events[DragEnterEvent]);
if (eh != null)
eh (this, dragEvent);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnDragLeave (EventArgs e)
{
EventHandler eh = (EventHandler)(Events[DragLeaveEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnDragOver (DragEventArgs dragEvent)
{
DragEventHandler eh = (DragEventHandler)(Events[DragOverEvent]);
if (eh != null)
eh (this, dragEvent);
}
protected virtual void OnEnabledChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnFontChanged (EventArgs e)
{
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnForeColorChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnGiveFeedback (GiveFeedbackEventArgs giveFeedbackEvent)
{
GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events[GiveFeedbackEvent]);
if (eh != null)
eh (this, giveFeedbackEvent);
}
protected virtual void OnLayout (LayoutEventArgs e)
{
}
protected virtual void OnLocationChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnMouseDown (MouseEventArgs e)
{
if (this.Enabled) {
this.is_pressed = true;
this.Invalidate ();
MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
if (eh != null)
eh (this, e);
}
}
protected virtual void OnMouseEnter (EventArgs e)
{
this.Select ();
EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnMouseHover (EventArgs e)
{
if (this.Enabled) {
EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
if (eh != null)
eh (this, e);
}
}
protected virtual void OnMouseLeave (EventArgs e)
{
if (this.CanSelect) {
this.is_selected = false;
this.is_pressed = false;
this.Invalidate ();
OnUIASelectionChanged ();
}
EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnMouseMove (MouseEventArgs mea)
{
if (this.Enabled) {
MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
if (eh != null)
eh (this, mea);
}
}
protected virtual void OnMouseUp (MouseEventArgs e)
{
if (this.Enabled) {
this.is_pressed = false;
this.Invalidate ();
if (this.IsOnDropDown)
if (!(this is ToolStripDropDownItem) || !(this as ToolStripDropDownItem).HasDropDownItems || (this as ToolStripDropDownItem).DropDown.Visible == false) {
if ((this.Parent as ToolStripDropDown).OwnerItem != null)
((this.Parent as ToolStripDropDown).OwnerItem as ToolStripDropDownItem).HideDropDown ();
else
(this.Parent as ToolStripDropDown).Hide ();
}
MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
if (eh != null)
eh (this, e);
}
}
protected virtual void OnOwnerChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [OwnerChangedEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected internal virtual void OnOwnerFontChanged (EventArgs e)
{
this.CalculateAutoSize ();
OnFontChanged (EventArgs.Empty);
}
void OnPaintInternal (PaintEventArgs e)
{
// Have the background rendered independently from OnPaint
if (this.parent != null)
this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
OnPaint (e);
}
protected virtual void OnPaint (PaintEventArgs e)
{
PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
if (eh != null)
eh (this, e);
}
// This is never called.
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnParentBackColorChanged (EventArgs e)
{
}
protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
{
this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty : this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
if (oldParent != null)
oldParent.PerformLayout ();
if (newParent != null)
newParent.PerformLayout ();
}
protected internal virtual void OnParentEnabledChanged (EventArgs e)
{
this.OnEnabledChanged (e);
}
// This is never called.
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnParentForeColorChanged (EventArgs e)
{
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected internal virtual void OnParentRightToLeftChanged (EventArgs e)
{
this.OnRightToLeftChanged (e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs queryContinueDragEvent)
{
QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events[QueryContinueDragEvent]);
if (eh != null)
eh (this, queryContinueDragEvent);
}
protected virtual void OnRightToLeftChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events[RightToLeftChangedEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnTextChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnVisibleChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
if (eh != null)
eh (this, e);
}
protected internal virtual bool ProcessCmdKey (ref Message m, Keys keyData)
{
return false;
}
protected internal virtual bool ProcessDialogKey (Keys keyData)
{
if (this.Selected && keyData == Keys.Enter) {
this.FireEvent (EventArgs.Empty, ToolStripItemEventType.Click);
return true;
}
return false;
}
// ProcessMnemonic will only be called if we are supposed to handle
// it. None of that fancy "thinking" needed!
protected internal virtual bool ProcessMnemonic (char charCode)
{
ToolStripManager.SetActiveToolStrip (this.Parent, true);
this.PerformClick ();
return true;
}
protected internal virtual void SetBounds (Rectangle bounds)
{
if (this.bounds != bounds) {
this.bounds = bounds;
OnBoundsChanged ();
}
}
protected virtual void SetVisibleCore (bool visible)
{
this.visible = visible;
this.OnVisibleChanged (EventArgs.Empty);
if (this.visible)
BeginAnimation ();
else
StopAnimation ();
this.Invalidate ();
}
#endregion
#region Public Events
static object AvailableChangedEvent = new object ();
static object BackColorChangedEvent = new object ();
static object ClickEvent = new object ();
static object DisplayStyleChangedEvent = new object ();
static object DoubleClickEvent = new object ();
static object DragDropEvent = new object ();
static object DragEnterEvent = new object ();
static object DragLeaveEvent = new object ();
static object DragOverEvent = new object ();
static object EnabledChangedEvent = new object ();
static object ForeColorChangedEvent = new object ();
static object GiveFeedbackEvent = new object ();
static object LocationChangedEvent = new object ();
static object MouseDownEvent = new object ();
static object MouseEnterEvent = new object ();
static object MouseHoverEvent = new object ();
static object MouseLeaveEvent = new object ();
static object MouseMoveEvent = new object ();
static object MouseUpEvent = new object ();
static object OwnerChangedEvent = new object ();
static object PaintEvent = new object ();
static object QueryAccessibilityHelpEvent = new object ();
static object QueryContinueDragEvent = new object ();
static object RightToLeftChangedEvent = new object ();
static object TextChangedEvent = new object ();
static object VisibleChangedEvent = new object ();
[Browsable (false)]
public event EventHandler AvailableChanged {
add { Events.AddHandler (AvailableChangedEvent, value); }
remove {Events.RemoveHandler (AvailableChangedEvent, value); }
}
public event EventHandler BackColorChanged {
add { Events.AddHandler (BackColorChangedEvent, value); }
remove {Events.RemoveHandler (BackColorChangedEvent, value); }
}
public event EventHandler Click {
add { Events.AddHandler (ClickEvent, value); }
remove {Events.RemoveHandler (ClickEvent, value); }
}
public event EventHandler DisplayStyleChanged {
add { Events.AddHandler (DisplayStyleChangedEvent, value); }
remove {Events.RemoveHandler (DisplayStyleChangedEvent, value); }
}
public event EventHandler DoubleClick {
add { Events.AddHandler (DoubleClickEvent, value); }
remove {Events.RemoveHandler (DoubleClickEvent, value); }
}
[MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event DragEventHandler DragDrop {
add { Events.AddHandler (DragDropEvent, value); }
remove { Events.RemoveHandler (DragDropEvent, value); }
}
[MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event DragEventHandler DragEnter {
add { Events.AddHandler (DragEnterEvent, value); }
remove { Events.RemoveHandler (DragEnterEvent, value); }
}
[MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event EventHandler DragLeave {
add { Events.AddHandler (DragLeaveEvent, value); }
remove { Events.RemoveHandler (DragLeaveEvent, value); }
}
[MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event DragEventHandler DragOver {
add { Events.AddHandler (DragOverEvent, value); }
remove { Events.RemoveHandler (DragOverEvent, value); }
}
public event EventHandler EnabledChanged {
add { Events.AddHandler (EnabledChangedEvent, value); }
remove {Events.RemoveHandler (EnabledChangedEvent, value); }
}
public event EventHandler ForeColorChanged {
add { Events.AddHandler (ForeColorChangedEvent, value); }
remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
}
[MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event GiveFeedbackEventHandler GiveFeedback {
add { Events.AddHandler (GiveFeedbackEvent, value); }
remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
}
public event EventHandler LocationChanged {
add { Events.AddHandler (LocationChangedEvent, value); }
remove {Events.RemoveHandler (LocationChangedEvent, value); }
}
public event MouseEventHandler MouseDown {
add { Events.AddHandler (MouseDownEvent, value); }
remove {Events.RemoveHandler (MouseDownEvent, value); }
}
public event EventHandler MouseEnter {
add { Events.AddHandler (MouseEnterEvent, value); }
remove {Events.RemoveHandler (MouseEnterEvent, value); }
}
public event EventHandler MouseHover {
add { Events.AddHandler (MouseHoverEvent, value); }
remove {Events.RemoveHandler (MouseHoverEvent, value); }
}
public event EventHandler MouseLeave {
add { Events.AddHandler (MouseLeaveEvent, value); }
remove {Events.RemoveHandler (MouseLeaveEvent, value); }
}
public event MouseEventHandler MouseMove {
add { Events.AddHandler (MouseMoveEvent, value); }
remove {Events.RemoveHandler (MouseMoveEvent, value); }
}
public event MouseEventHandler MouseUp {
add { Events.AddHandler (MouseUpEvent, value); }
remove {Events.RemoveHandler (MouseUpEvent, value); }
}
public event EventHandler OwnerChanged {
add { Events.AddHandler (OwnerChangedEvent, value); }
remove {Events.RemoveHandler (OwnerChangedEvent, value); }
}
public event PaintEventHandler Paint {
add { Events.AddHandler (PaintEvent, value); }
remove {Events.RemoveHandler (PaintEvent, value); }
}
[MonoTODO ("Event never raised")]
public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
}
[MonoTODO ("Event never raised")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public event QueryContinueDragEventHandler QueryContinueDrag {
add { Events.AddHandler (QueryContinueDragEvent, value); }
remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
}
public event EventHandler RightToLeftChanged {
add { Events.AddHandler (RightToLeftChangedEvent, value); }
remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
}
public event EventHandler TextChanged {
add { Events.AddHandler (TextChangedEvent, value); }
remove {Events.RemoveHandler (TextChangedEvent, value); }
}
public event EventHandler VisibleChanged {
add { Events.AddHandler (VisibleChangedEvent, value); }
remove {Events.RemoveHandler (VisibleChangedEvent, value); }
}
#endregion
#region Internal Methods
internal Rectangle AlignInRectangle (Rectangle outer, Size inner, ContentAlignment align)
{
int x = 0;
int y = 0;
if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft)
x = outer.X;
else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter)
x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
else if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight)
x = outer.Right - inner.Width;
if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight)
y = outer.Y;
else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight)
y = outer.Y + (outer.Height - inner.Height) / 2;
else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomRight || align == ContentAlignment.BottomLeft)
y = outer.Bottom - inner.Height;
return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
}
internal void CalculateAutoSize ()
{
this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty: this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
// If our text is rotated, flip the width and height
ToolStripTextDirection direction = this.TextDirection;
if (direction == ToolStripTextDirection.Vertical270 || direction == ToolStripTextDirection.Vertical90)
this.text_size = new Size (this.text_size.Height, this.text_size.Width);
if (!this.auto_size || this is ToolStripControlHost)
return;
//this.text_size.Width += 6;
Size final_size = this.CalculatePreferredSize (Size.Empty);
if (final_size != this.Size) {
this.bounds.Width = final_size.Width;
if (this.parent != null)
this.parent.PerformLayout ();
}
}
internal virtual Size CalculatePreferredSize (Size constrainingSize)
{
if (!this.auto_size)
return this.explicit_size;
Size preferred_size = this.DefaultSize;
switch (this.display_style) {
case ToolStripItemDisplayStyle.Text:
int width = text_size.Width + this.padding.Horizontal;
int height = text_size.Height + this.padding.Vertical;
preferred_size = new Size (width, height);
break;
case ToolStripItemDisplayStyle.Image:
if (this.GetImageSize () == Size.Empty)
preferred_size = this.DefaultSize;
else {
switch (this.image_scaling) {
case ToolStripItemImageScaling.None:
preferred_size = this.GetImageSize ();
break;
case ToolStripItemImageScaling.SizeToFit:
if (this.parent == null)
preferred_size = this.GetImageSize ();
else
preferred_size = this.parent.ImageScalingSize;
break;
}
}
break;
case ToolStripItemDisplayStyle.ImageAndText:
int width2 = text_size.Width + this.padding.Horizontal;
int height2 = text_size.Height + this.padding.Vertical;
if (this.GetImageSize () != Size.Empty) {
Size image_size = this.GetImageSize ();
if (this.image_scaling == ToolStripItemImageScaling.SizeToFit && this.parent != null)
image_size = this.parent.ImageScalingSize;
switch (this.text_image_relation) {
case TextImageRelation.Overlay:
width2 = Math.Max (width2, image_size.Width);
height2 = Math.Max (height2, image_size.Height);
break;
case TextImageRelation.ImageAboveText:
case TextImageRelation.TextAboveImage:
width2 = Math.Max (width2, image_size.Width);
height2 += image_size.Height;
break;
case TextImageRelation.ImageBeforeText:
case TextImageRelation.TextBeforeImage:
height2 = Math.Max (height2, image_size.Height);
width2 += image_size.Width;
break;
}
}
preferred_size = new Size (width2, height2);
break;
}
if (!(this is ToolStripLabel)) { // Everything but labels have a border
preferred_size.Height += 4;
preferred_size.Width += 4;
}
return preferred_size;
}
internal void CalculateTextAndImageRectangles (out Rectangle text_rect, out Rectangle image_rect)
{
this.CalculateTextAndImageRectangles (this.ContentRectangle, out text_rect, out image_rect);
}
internal void CalculateTextAndImageRectangles (Rectangle contentRectangle, out Rectangle text_rect, out Rectangle image_rect)
{
text_rect = Rectangle.Empty;
image_rect = Rectangle.Empty;
switch (this.display_style) {
case ToolStripItemDisplayStyle.None:
break;
case ToolStripItemDisplayStyle.Text:
if (this.text != string.Empty)
text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
break;
case ToolStripItemDisplayStyle.Image:
if (this.Image != null && this.UseImageMargin)
image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
break;
case ToolStripItemDisplayStyle.ImageAndText:
if (this.text != string.Empty && (this.Image == null || !this.UseImageMargin))
text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
else if (this.text == string.Empty && (this.Image == null || !this.UseImageMargin))
break;
else if (this.text == string.Empty && this.Image != null)
image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
else {
Rectangle text_area;
Rectangle image_area;
switch (this.text_image_relation) {
case TextImageRelation.Overlay:
text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
break;
case TextImageRelation.ImageAboveText:
text_area = new Rectangle (contentRectangle.Left, contentRectangle.Bottom - (text_size.Height - 4), contentRectangle.Width, text_size.Height - 4);
image_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, contentRectangle.Height - text_area.Height);
text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
break;
case TextImageRelation.TextAboveImage:
text_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, text_size.Height - 4);
image_area = new Rectangle (contentRectangle.Left, text_area.Bottom, contentRectangle.Width, contentRectangle.Height - text_area.Height);
text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
break;
case TextImageRelation.ImageBeforeText:
LayoutTextBeforeOrAfterImage (contentRectangle, false, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
break;
case TextImageRelation.TextBeforeImage:
LayoutTextBeforeOrAfterImage (contentRectangle, true, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
break;
}
}
break;
}
}
private static Font DefaultFont { get { return new Font ("Tahoma", 8.25f); } }
internal virtual ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Inherit; } }
internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
{
if (is_selected) {
this.is_selected = false;
this.Invalidate ();
OnUIASelectionChanged ();
}
}
internal virtual ToolStrip GetTopLevelToolStrip ()
{
if (this.Parent != null)
return this.Parent.GetTopLevelToolStrip ();
return null;
}
private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, ContentAlignment textAlign, ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
{
int element_spacing = 0; // Spacing between the Text and the Image
int total_width = textSize.Width + element_spacing + imageSize.Width;
int excess_width = totalArea.Width - total_width;
int offset = 0;
Rectangle final_text_rect;
Rectangle final_image_rect;
HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
if (h_image == HorizontalAlignment.Left)
offset = 0;
else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
offset = excess_width;
else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
offset += (int)(excess_width / 3);
else
offset += (int)(2 * (excess_width / 3));
if (textFirst) {
final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
} else {
final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
}
textRect = final_text_rect;
imageRect = final_image_rect;
}
private HorizontalAlignment GetHorizontalAlignment (ContentAlignment align)
{
switch (align) {
case ContentAlignment.BottomLeft:
case ContentAlignment.MiddleLeft:
case ContentAlignment.TopLeft:
return HorizontalAlignment.Left;
case ContentAlignment.BottomCenter:
case ContentAlignment.MiddleCenter:
case ContentAlignment.TopCenter:
return HorizontalAlignment.Center;
case ContentAlignment.BottomRight:
case ContentAlignment.MiddleRight:
case ContentAlignment.TopRight:
return HorizontalAlignment.Right;
}
return HorizontalAlignment.Left;
}
internal Size GetImageSize ()
{
// Get the actual size of our internal image -or-
// Get the ImageList.ImageSize if we are using ImageLists
if (this.image_scaling == ToolStripItemImageScaling.None) {
if (this.image != null)
return image.Size;
if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
if (this.owner != null && this.owner.ImageList != null)
return this.owner.ImageList.ImageSize;
} else {
// If we have an image and a parent, return ImageScalingSize
if (this.Parent == null)
return Size.Empty;
if (this.image != null)
return this.Parent.ImageScalingSize;
if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
if (this.owner != null && this.owner.ImageList != null)
return this.Parent.ImageScalingSize;
}
return Size.Empty;
}
internal string GetToolTip ()
{
if (this.auto_tool_tip && string.IsNullOrEmpty (this.tool_tip_text))
return this.Text;
return this.tool_tip_text;
}
internal void FireEvent (EventArgs e, ToolStripItemEventType met)
{
// If we're disabled, don't fire any of these events, except Paint
if (!this.Enabled && met != ToolStripItemEventType.Paint)
return;
switch (met) {
case ToolStripItemEventType.MouseUp:
this.HandleClick (((MouseEventArgs)e).Clicks, e);
this.OnMouseUp ((MouseEventArgs)e);
break;
case ToolStripItemEventType.MouseDown:
this.OnMouseDown ((MouseEventArgs)e);
break;
case ToolStripItemEventType.MouseEnter:
this.OnMouseEnter (e);
break;
case ToolStripItemEventType.MouseHover:
this.OnMouseHover (e);
break;
case ToolStripItemEventType.MouseLeave:
this.OnMouseLeave (e);
break;
case ToolStripItemEventType.MouseMove:
this.OnMouseMove ((MouseEventArgs)e);
break;
case ToolStripItemEventType.Paint:
this.OnPaintInternal ((PaintEventArgs)e);
break;
case ToolStripItemEventType.Click:
this.HandleClick (1, e);
break;
}
}
internal virtual void HandleClick (int mouse_clicks, EventArgs e)
{
if (Parent == null)
return;
this.Parent.HandleItemClick (this);
if (mouse_clicks == 2 && double_click_enabled)
this.OnDoubleClick (e);
else
this.OnClick (e);
}
internal virtual void SetPlacement (ToolStripItemPlacement placement)
{
this.placement = placement;
}
private void BeginAnimation ()
{
if (image != null && ImageAnimator.CanAnimate (image)) {
frame_handler = new EventHandler (OnAnimateImage);
ImageAnimator.Animate (image, frame_handler);
}
}
private void OnAnimateImage (object sender, EventArgs e)
{
// This is called from a worker thread,BeginInvoke is used
// so the control is updated from the correct thread
// Check if we have a handle again, since it may have gotten
// destroyed since the last time we checked.
if (Parent == null || !Parent.IsHandleCreated)
return;
Parent.BeginInvoke (new EventHandler (UpdateAnimatedImage), new object[] { this, e });
}
private void StopAnimation ()
{
if (frame_handler == null)
return;
ImageAnimator.StopAnimate (image, frame_handler);
frame_handler = null;
}
private void UpdateAnimatedImage (object sender, EventArgs e)
{
// Check if we have a handle again, since it may have gotten
// destroyed since the last time we checked.
if (Parent == null || !Parent.IsHandleCreated)
return;
ImageAnimator.UpdateFrames (image);
Invalidate ();
}
internal bool ShowMargin {
get {
if (!this.IsOnDropDown)
return true;
if (!(this.Owner is ToolStripDropDownMenu))
return false;
ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
return tsddm.ShowCheckMargin || tsddm.ShowImageMargin;
}
}
internal bool UseImageMargin {
get {
if (!this.IsOnDropDown)
return true;
if (!(this.Owner is ToolStripDropDownMenu))
return false;
ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
return tsddm.ShowImageMargin || tsddm.ShowCheckMargin;
}
}
internal virtual bool InternalVisible {
get { return this.visible; }
set { this.visible = value; Invalidate (); }
}
internal ToolStrip InternalOwner {
set {
if (this.owner != value) {
this.owner = value;
if (this.owner != null)
this.CalculateAutoSize ();
OnOwnerChanged (EventArgs.Empty);
}
}
}
internal Point Location {
get { return this.bounds.Location; }
set {
if (this.bounds.Location != value) {
this.bounds.Location = value;
this.OnLocationChanged (EventArgs.Empty);
}
}
}
internal int Top {
get { return this.bounds.Y; }
set {
if (this.bounds.Y != value) {
this.bounds.Y = value;
this.OnLocationChanged (EventArgs.Empty);
}
}
}
internal int Left {
get { return this.bounds.X; }
set {
if (this.bounds.X != value) {
this.bounds.X = value;
this.OnLocationChanged (EventArgs.Empty);
}
}
}
internal int Right { get { return this.bounds.Right; } }
internal int Bottom { get { return this.bounds.Bottom; } }
#endregion
#region IDropTarget Members
void IDropTarget.OnDragDrop (DragEventArgs dragEvent)
{
OnDragDrop (dragEvent);
}
void IDropTarget.OnDragEnter (DragEventArgs dragEvent)
{
OnDragEnter (dragEvent);
}
void IDropTarget.OnDragLeave (EventArgs e)
{
OnDragLeave (e);
}
void IDropTarget.OnDragOver (DragEventArgs dragEvent)
{
OnDragOver (dragEvent);
}
#endregion
#region UIA Framework: Methods, Properties and Events
static object UIASelectionChangedEvent = new object ();
internal event EventHandler UIASelectionChanged {
add { Events.AddHandler (UIASelectionChangedEvent, value); }
remove { Events.RemoveHandler (UIASelectionChangedEvent, value); }
}
internal void OnUIASelectionChanged ()
{
EventHandler eh = (EventHandler)(Events [UIASelectionChangedEvent]);
if (eh != null)
eh (this, EventArgs.Empty);
}
#endregion
[ComVisible (true)]
public class ToolStripItemAccessibleObject : AccessibleObject
{
internal ToolStripItem owner_item;
public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
{
if (ownerItem == null)
throw new ArgumentNullException ("ownerItem");
this.owner_item = ownerItem;
base.default_action = string.Empty;
base.keyboard_shortcut = string.Empty;
base.name = string.Empty;
base.value = string.Empty;
}
#region Public Properties
public override Rectangle Bounds {
get {
return owner_item.Visible ? owner_item.Bounds : Rectangle.Empty;
}
}
public override string DefaultAction {
get { return base.DefaultAction; }
}
public override string Description {
get { return base.Description; }
}
public override string Help {
get { return base.Help; }
}
public override string KeyboardShortcut {
get { return base.KeyboardShortcut; }
}
public override string Name {
get {
if (base.name == string.Empty)
return owner_item.Text;
return base.Name;
}
set { base.Name = value; }
}
public override AccessibleObject Parent {
get { return base.Parent; }
}
public override AccessibleRole Role {
get { return base.Role; }
}
public override AccessibleStates State {
get { return base.State; }
}
#endregion
#region Public Methods
public void AddState (AccessibleStates state)
{
base.state = state;
}
public override void DoDefaultAction ()
{
base.DoDefaultAction ();
}
public override int GetHelpTopic (out string fileName)
{
return base.GetHelpTopic (out fileName);
}
public override AccessibleObject Navigate (AccessibleNavigation navigationDirection)
{
return base.Navigate (navigationDirection);
}
public override string ToString ()
{
return string.Format ("ToolStripItemAccessibleObject: Owner = {0}", owner_item.ToString());
}
#endregion
}
}
internal class NoneExcludedImageIndexConverter : ImageIndexConverter
{
}
}
|