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
|
//
// ToolStrip.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.Runtime.InteropServices;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms.Layout;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
namespace System.Windows.Forms
{
[ComVisible (true)]
[ClassInterface (ClassInterfaceType.AutoDispatch)]
[DefaultEvent ("ItemClicked")]
[DefaultProperty ("Items")]
[Designer ("System.Windows.Forms.Design.ToolStripDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
[DesignerSerializer ("System.Windows.Forms.Design.ToolStripCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
public class ToolStrip : ScrollableControl, IComponent, IDisposable, IToolStripData
{
#region Private Variables
private bool allow_item_reorder;
private bool allow_merge;
private Color back_color;
private bool can_overflow;
private ToolStrip currently_merged_with;
private ToolStripDropDownDirection default_drop_down_direction;
internal ToolStripItemCollection displayed_items;
private Color fore_color;
private Padding grip_margin;
private ToolStripGripStyle grip_style;
private List<ToolStripItem> hidden_merged_items;
private ImageList image_list;
private Size image_scaling_size;
private bool is_currently_merged;
private ToolStripItemCollection items;
private bool keyboard_active;
private LayoutEngine layout_engine;
private LayoutSettings layout_settings;
private ToolStripLayoutStyle layout_style;
private Orientation orientation;
private ToolStripOverflowButton overflow_button;
private List<ToolStripItem> pre_merge_items;
private ToolStripRenderer renderer;
private ToolStripRenderMode render_mode;
private ToolStripTextDirection text_direction;
private Timer tooltip_timer;
private ToolTip tooltip_window;
private bool show_item_tool_tips;
private bool stretch;
private ToolStripItem mouse_currently_over;
internal bool menu_selected;
private ToolStripItem tooltip_currently_showing;
private ToolTip.TipState tooltip_state;
const int InitialToolTipDelay = 500;
const int ToolTipDelay = 5000;
#endregion
#region Public Constructors
public ToolStrip () : this (null)
{
}
public ToolStrip (params ToolStripItem[] items) : base ()
{
SetStyle (ControlStyles.AllPaintingInWmPaint, true);
SetStyle (ControlStyles.OptimizedDoubleBuffer, true);
SetStyle (ControlStyles.Selectable, false);
SetStyle (ControlStyles.SupportsTransparentBackColor, true);
this.SuspendLayout ();
this.items = new ToolStripItemCollection (this, items, true);
this.allow_merge = true;
base.AutoSize = true;
this.SetAutoSizeMode (AutoSizeMode.GrowAndShrink);
this.back_color = Control.DefaultBackColor;
this.can_overflow = true;
base.CausesValidation = false;
this.default_drop_down_direction = ToolStripDropDownDirection.BelowRight;
this.displayed_items = new ToolStripItemCollection (this, null, true);
this.Dock = this.DefaultDock;
base.Font = new Font ("Tahoma", 8.25f);
this.fore_color = Control.DefaultForeColor;
this.grip_margin = this.DefaultGripMargin;
this.grip_style = ToolStripGripStyle.Visible;
this.image_scaling_size = new Size (16, 16);
this.layout_style = ToolStripLayoutStyle.HorizontalStackWithOverflow;
this.orientation = Orientation.Horizontal;
if (!(this is ToolStripDropDown))
this.overflow_button = new ToolStripOverflowButton (this);
this.renderer = null;
this.render_mode = ToolStripRenderMode.ManagerRenderMode;
this.show_item_tool_tips = this.DefaultShowItemToolTips;
base.TabStop = false;
this.text_direction = ToolStripTextDirection.Horizontal;
this.ResumeLayout ();
// Register with the ToolStripManager
ToolStripManager.AddToolStrip (this);
}
#endregion
#region Public Properties
[MonoTODO ("Stub, does nothing")]
public override bool AllowDrop {
get { return base.AllowDrop; }
set { base.AllowDrop = value; }
}
[MonoTODO ("Stub, does nothing")]
[DefaultValue (false)]
public bool AllowItemReorder {
get { return this.allow_item_reorder; }
set { this.allow_item_reorder = value; }
}
[DefaultValue (true)]
public bool AllowMerge {
get { return this.allow_merge; }
set { this.allow_merge = value; }
}
public override AnchorStyles Anchor {
get { return base.Anchor; }
set { base.Anchor = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override bool AutoScroll {
get { return base.AutoScroll; }
set { base.AutoScroll = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Size AutoScrollMargin {
get { return base.AutoScrollMargin; }
set { base.AutoScrollMargin = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Size AutoScrollMinSize {
get { return base.AutoScrollMinSize; }
set { base.AutoScrollMinSize = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Point AutoScrollPosition {
get { return base.AutoScrollPosition; }
set { base.AutoScrollPosition = value; }
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
[Browsable (true)]
[EditorBrowsable (EditorBrowsableState.Always)]
[DefaultValue (true)]
public override bool AutoSize {
get { return base.AutoSize; }
set { base.AutoSize = value; }
}
new public Color BackColor {
get { return this.back_color; }
set { this.back_color = value; }
}
public override BindingContext BindingContext {
get { return base.BindingContext; }
set { base.BindingContext = value; }
}
[DefaultValue (true)]
public bool CanOverflow {
get { return this.can_overflow; }
set { this.can_overflow = value; }
}
[Browsable (false)]
[DefaultValue (false)]
public new bool CausesValidation {
get { return base.CausesValidation; }
set { base.CausesValidation = value; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new ControlCollection Controls {
get { return base.Controls; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override Cursor Cursor {
get { return base.Cursor; }
set { base.Cursor = value; }
}
[Browsable (false)]
public virtual ToolStripDropDownDirection DefaultDropDownDirection {
get { return this.default_drop_down_direction; }
set {
if (!Enum.IsDefined (typeof (ToolStripDropDownDirection), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripDropDownDirection", value));
this.default_drop_down_direction = value;
}
}
public override Rectangle DisplayRectangle {
get {
if (this.orientation == Orientation.Horizontal)
if (this.grip_style == ToolStripGripStyle.Hidden || this.layout_style == ToolStripLayoutStyle.Flow || this.layout_style == ToolStripLayoutStyle.Table)
return new Rectangle (this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical);
else
return new Rectangle (this.GripRectangle.Right + this.GripMargin.Right, this.Padding.Top, this.Width - this.Padding.Horizontal - this.GripRectangle.Right - this.GripMargin.Right, this.Height - this.Padding.Vertical);
else
if (this.grip_style == ToolStripGripStyle.Hidden || this.layout_style == ToolStripLayoutStyle.Flow || this.layout_style == ToolStripLayoutStyle.Table)
return new Rectangle (this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical);
else
return new Rectangle (this.Padding.Left, this.GripRectangle.Bottom + this.GripMargin.Bottom + this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical - this.GripRectangle.Bottom - this.GripMargin.Bottom);
}
}
[DefaultValue (DockStyle.Top)]
public override DockStyle Dock {
get { return base.Dock; }
set {
if (base.Dock != value) {
base.Dock = value;
switch (value) {
case DockStyle.Top:
case DockStyle.Bottom:
case DockStyle.None:
this.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
break;
case DockStyle.Left:
case DockStyle.Right:
this.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
break;
}
}
}
}
public override Font Font {
get { return base.Font; }
set {
if (base.Font != value) {
base.Font = value;
foreach (ToolStripItem tsi in this.Items)
tsi.OnOwnerFontChanged (EventArgs.Empty);
}
}
}
[Browsable (false)]
public new Color ForeColor {
get { return this.fore_color; }
set {
if (this.fore_color != value) {
this.fore_color = value;
this.OnForeColorChanged (EventArgs.Empty);
}
}
}
[Browsable (false)]
public ToolStripGripDisplayStyle GripDisplayStyle {
get { return this.orientation == Orientation.Vertical ? ToolStripGripDisplayStyle.Horizontal : ToolStripGripDisplayStyle.Vertical; }
}
public Padding GripMargin {
get { return this.grip_margin; }
set {
if (this.grip_margin != value) {
this.grip_margin = value;
this.PerformLayout ();
}
}
}
[Browsable (false)]
public Rectangle GripRectangle {
get {
if (this.grip_style == ToolStripGripStyle.Hidden)
return Rectangle.Empty;
if (this.orientation == Orientation.Horizontal)
return new Rectangle (this.grip_margin.Left + this.Padding.Left, this.Padding.Top, 3, this.Height);
else
return new Rectangle (this.Padding.Left, this.grip_margin.Top + this.Padding.Top, this.Width, 3);
}
}
[DefaultValue (ToolStripGripStyle.Visible)]
public ToolStripGripStyle GripStyle {
get { return this.grip_style; }
set {
if (this.grip_style != value) {
if (!Enum.IsDefined (typeof (ToolStripGripStyle), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripGripStyle", value));
this.grip_style = value;
this.PerformLayout (this, "GripStyle");
}
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new bool HasChildren {
get { return base.HasChildren; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new HScrollProperties HorizontalScroll {
get { return base.HorizontalScroll; }
}
[Browsable (false)]
[DefaultValue (null)]
public ImageList ImageList {
get { return this.image_list; }
set { this.image_list = value; }
}
[DefaultValue ("{Width=16, Height=16}")]
public Size ImageScalingSize {
get { return this.image_scaling_size; }
set { this.image_scaling_size = value; }
}
[MonoTODO ("Always returns false, dragging not implemented yet.")]
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public bool IsCurrentlyDragging {
get { return false; }
}
[Browsable (false)]
public bool IsDropDown {
get {
if (this is ToolStripDropDown)
return true;
return false;
}
}
[MergableProperty (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
public virtual ToolStripItemCollection Items {
get { return this.items; }
}
public override LayoutEngine LayoutEngine {
get {
if (layout_engine == null)
this.layout_engine = new ToolStripSplitStackLayout ();
return this.layout_engine;
}
}
[Browsable (false)]
[DefaultValue (null)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public LayoutSettings LayoutSettings {
get { return this.layout_settings; }
set {
if (this.layout_settings != value) {
this.layout_settings = value;
PerformLayout (this, "LayoutSettings");
}
}
}
[AmbientValue (ToolStripLayoutStyle.StackWithOverflow)]
public ToolStripLayoutStyle LayoutStyle {
get { return layout_style; }
set {
if (this.layout_style != value) {
if (!Enum.IsDefined (typeof (ToolStripLayoutStyle), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripLayoutStyle", value));
this.layout_style = value;
if (this.layout_style == ToolStripLayoutStyle.Flow)
this.layout_engine = new FlowLayout ();
else
this.layout_engine = new ToolStripSplitStackLayout ();
if (this.layout_style == ToolStripLayoutStyle.StackWithOverflow) {
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right)
this.layout_style = ToolStripLayoutStyle.VerticalStackWithOverflow;
else
this.layout_style = ToolStripLayoutStyle.HorizontalStackWithOverflow;
}
if (this.layout_style == ToolStripLayoutStyle.HorizontalStackWithOverflow)
this.orientation = Orientation.Horizontal;
else if (this.layout_style == ToolStripLayoutStyle.VerticalStackWithOverflow)
this.orientation = Orientation.Vertical;
this.layout_settings = this.CreateLayoutSettings (value);
this.PerformLayout (this, "LayoutStyle");
this.OnLayoutStyleChanged (EventArgs.Empty);
}
}
}
[Browsable (false)]
public Orientation Orientation {
get { return this.orientation; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
public ToolStripOverflowButton OverflowButton {
get { return this.overflow_button; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public ToolStripRenderer Renderer {
get {
if (this.render_mode == ToolStripRenderMode.ManagerRenderMode)
return ToolStripManager.Renderer;
return this.renderer;
}
set {
if (this.renderer != value) {
this.renderer = value;
this.render_mode = ToolStripRenderMode.Custom;
this.PerformLayout (this, "Renderer");
this.OnRendererChanged (EventArgs.Empty);
}
}
}
public ToolStripRenderMode RenderMode {
get { return this.render_mode; }
set {
if (!Enum.IsDefined (typeof (ToolStripRenderMode), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripRenderMode", value));
if (value == ToolStripRenderMode.Custom && this.renderer == null)
throw new NotSupportedException ("Must set Renderer property before setting RenderMode to Custom");
else if (value == ToolStripRenderMode.Professional)
this.Renderer = new ToolStripProfessionalRenderer ();
else if (value == ToolStripRenderMode.System)
this.Renderer = new ToolStripSystemRenderer ();
this.render_mode = value;
}
}
[DefaultValue (true)]
public bool ShowItemToolTips {
get { return this.show_item_tool_tips; }
set { this.show_item_tool_tips = value; }
}
[DefaultValue (false)]
public bool Stretch {
get { return this.stretch; }
set { this.stretch = value; }
}
[DefaultValue (false)]
[DispId(-516)]
public new bool TabStop {
get { return base.TabStop; }
set {
base.TabStop = value;
SetStyle (ControlStyles.Selectable, value);
}
}
[DefaultValue (ToolStripTextDirection.Horizontal)]
public virtual ToolStripTextDirection TextDirection {
get { 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.PerformLayout (this, "TextDirection");
this.Invalidate ();
}
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new VScrollProperties VerticalScroll {
get { return base.VerticalScroll; }
}
#endregion
#region Protected Properties
protected virtual DockStyle DefaultDock { get { return DockStyle.Top; } }
protected virtual Padding DefaultGripMargin { get { return new Padding (2); } }
protected override Padding DefaultMargin { get { return Padding.Empty; } }
protected override Padding DefaultPadding { get { return new Padding (0, 0, 1, 0); } }
protected virtual bool DefaultShowItemToolTips { get { return true; } }
protected override Size DefaultSize { get { return new Size (100, 25); } }
protected internal virtual ToolStripItemCollection DisplayedItems { get { return this.displayed_items; } }
protected internal virtual Size MaxItemSize {
get { return new Size (Width - (GripStyle == ToolStripGripStyle.Hidden ? 1 : 8), Height); }
}
#endregion
#region Public Methods
[EditorBrowsable (EditorBrowsableState.Never)]
public new Control GetChildAtPoint (Point point)
{
return base.GetChildAtPoint (point);
}
[EditorBrowsable (EditorBrowsableState.Never)]
public new Control GetChildAtPoint (Point pt, GetChildAtPointSkip skipValue)
{
return base.GetChildAtPoint (pt, skipValue);
}
public ToolStripItem GetItemAt (Point point)
{
foreach (ToolStripItem tsi in this.displayed_items)
if (tsi.Visible && tsi.Bounds.Contains (point))
return tsi;
return null;
}
public ToolStripItem GetItemAt (int x, int y)
{
return GetItemAt (new Point (x, y));
}
public virtual ToolStripItem GetNextItem (ToolStripItem start, ArrowDirection direction)
{
if (!Enum.IsDefined (typeof (ArrowDirection), direction))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ArrowDirection", direction));
ToolStripItem current_best = null;
int current_best_point;
switch (direction) {
case ArrowDirection.Right:
current_best_point = int.MaxValue;
if (start != null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Left >= start.Right && loop_tsi.Left < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Left;
}
if (current_best == null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Left < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Left;
}
break;
case ArrowDirection.Up:
current_best_point = int.MinValue;
if (start != null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Bottom <= start.Top && loop_tsi.Top > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Top;
}
if (current_best == null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Top > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Top;
}
break;
case ArrowDirection.Left:
current_best_point = int.MinValue;
if (start != null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Right <= start.Left && loop_tsi.Left > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Left;
}
if (current_best == null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Left > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Left;
}
break;
case ArrowDirection.Down:
current_best_point = int.MaxValue;
if (start != null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Top >= start.Bottom && loop_tsi.Bottom < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Top;
}
if (current_best == null)
foreach (ToolStripItem loop_tsi in this.DisplayedItems)
if (loop_tsi.Top < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
current_best = loop_tsi;
current_best_point = loop_tsi.Top;
}
break;
}
return current_best;
}
[EditorBrowsable (EditorBrowsableState.Never)]
public void ResetMinimumSize ()
{
this.MinimumSize = new Size (-1, -1);
}
[EditorBrowsable (EditorBrowsableState.Never)]
public new void SetAutoScrollMargin (int x, int y)
{
base.SetAutoScrollMargin (x, y);
}
public override string ToString ()
{
return String.Format ("{0}, Name: {1}, Items: {2}", base.ToString(), this.Name, this.items.Count.ToString ());
}
#endregion
#region Protected Methods
protected override AccessibleObject CreateAccessibilityInstance ()
{
return new ToolStripAccessibleObject (this);
}
protected override ControlCollection CreateControlsInstance ()
{
return base.CreateControlsInstance ();
}
protected internal virtual ToolStripItem CreateDefaultItem (string text, Image image, EventHandler onClick)
{
if (text == "-")
return new ToolStripSeparator ();
if (this is ToolStripDropDown)
return new ToolStripMenuItem (text, image, onClick);
return new ToolStripButton (text, image, onClick);
}
protected virtual LayoutSettings CreateLayoutSettings (ToolStripLayoutStyle layoutStyle)
{
switch (layoutStyle) {
case ToolStripLayoutStyle.Flow:
return new FlowLayoutSettings (this);
case ToolStripLayoutStyle.Table:
//return new TableLayoutSettings ();
case ToolStripLayoutStyle.StackWithOverflow:
case ToolStripLayoutStyle.HorizontalStackWithOverflow:
case ToolStripLayoutStyle.VerticalStackWithOverflow:
default:
return null;
}
}
protected override void Dispose (bool disposing)
{
if (!IsDisposed) {
if(disposing) {
// Event Handler must be stopped before disposing Items.
Events.Dispose();
CloseToolTip (null);
// ToolStripItem.Dispose modifes the collection,
// so we iterate it in reverse order
for (int i = Items.Count - 1; i >= 0; i--)
Items [i].Dispose ();
if (this.overflow_button != null && this.overflow_button.drop_down != null)
this.overflow_button.drop_down.Dispose ();
ToolStripManager.RemoveToolStrip (this);
}
base.Dispose (disposing);
}
}
[MonoTODO ("Stub, never called")]
protected virtual void OnBeginDrag (EventArgs e)
{
EventHandler eh = (EventHandler)(Events[BeginDragEvent]);
if (eh != null)
eh (this, e);
}
protected override void OnDockChanged (EventArgs e)
{
base.OnDockChanged (e);
}
[MonoTODO ("Stub, never called")]
protected virtual void OnEndDrag (EventArgs e)
{
EventHandler eh = (EventHandler)(Events[EndDragEvent]);
if (eh != null)
eh (this, e);
}
protected override bool IsInputChar (char charCode)
{
return base.IsInputChar (charCode);
}
protected override bool IsInputKey (Keys keyData)
{
return base.IsInputKey (keyData);
}
protected override void OnEnabledChanged (EventArgs e)
{
base.OnEnabledChanged (e);
foreach (ToolStripItem tsi in this.Items)
tsi.OnParentEnabledChanged (EventArgs.Empty);
}
protected override void OnFontChanged (EventArgs e)
{
base.OnFontChanged (e);
}
protected override void OnHandleCreated (EventArgs e)
{
base.OnHandleCreated (e);
}
protected override void OnHandleDestroyed (EventArgs e)
{
base.OnHandleDestroyed (e);
}
protected override void OnInvalidated (InvalidateEventArgs e)
{
base.OnInvalidated (e);
}
protected internal virtual void OnItemAdded (ToolStripItemEventArgs e)
{
if (e.Item.InternalVisible)
e.Item.Available = true;
e.Item.SetPlacement (ToolStripItemPlacement.Main);
if (this.Created)
this.PerformLayout ();
ToolStripItemEventHandler eh = (ToolStripItemEventHandler)(Events [ItemAddedEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnItemClicked (ToolStripItemClickedEventArgs e)
{
if (this.KeyboardActive)
ToolStripManager.SetActiveToolStrip (null, false);
ToolStripItemClickedEventHandler eh = (ToolStripItemClickedEventHandler)(Events [ItemClickedEvent]);
if (eh != null)
eh (this, e);
}
protected internal virtual void OnItemRemoved (ToolStripItemEventArgs e)
{
ToolStripItemEventHandler eh = (ToolStripItemEventHandler)(Events [ItemRemovedEvent]);
if (eh != null)
eh (this, e);
}
protected override void OnLayout (LayoutEventArgs e)
{
base.OnLayout (e);
this.SetDisplayedItems ();
this.OnLayoutCompleted (EventArgs.Empty);
this.Invalidate ();
}
protected virtual void OnLayoutCompleted (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [LayoutCompletedEvent]);
if (eh != null)
eh (this, e);
}
protected virtual void OnLayoutStyleChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events[LayoutStyleChangedEvent]);
if (eh != null)
eh (this, e);
}
protected override void OnLeave (EventArgs e)
{
base.OnLeave (e);
}
protected override void OnLostFocus (EventArgs e)
{
base.OnLostFocus (e);
}
protected override void OnMouseCaptureChanged (EventArgs e)
{
base.OnMouseCaptureChanged (e);
}
protected override void OnMouseDown (MouseEventArgs mea)
{
if (mouse_currently_over != null)
{
ToolStripItem focused = GetCurrentlyFocusedItem ();
if (focused != null && focused != mouse_currently_over)
this.FocusInternal (true);
if (this is MenuStrip && !menu_selected) {
(this as MenuStrip).FireMenuActivate ();
menu_selected = true;
}
mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseDown);
if (this is MenuStrip && mouse_currently_over is ToolStripMenuItem && !(mouse_currently_over as ToolStripMenuItem).HasDropDownItems)
return;
} else {
this.Dismiss (ToolStripDropDownCloseReason.AppClicked);
}
if (this is MenuStrip)
this.Capture = false;
base.OnMouseDown (mea);
}
protected override void OnMouseLeave (EventArgs e)
{
if (mouse_currently_over != null) {
MouseLeftItem (mouse_currently_over);
mouse_currently_over.FireEvent (e, ToolStripItemEventType.MouseLeave);
mouse_currently_over = null;
}
base.OnMouseLeave (e);
}
protected override void OnMouseMove (MouseEventArgs mea)
{
ToolStripItem tsi;
// Find the item we are now
if (this.overflow_button != null && this.overflow_button.Visible && this.overflow_button.Bounds.Contains (mea.Location))
tsi = this.overflow_button;
else
tsi = this.GetItemAt (mea.X, mea.Y);
if (tsi != null) {
// If we were already hovering on this item, just send a mouse move
if (tsi == mouse_currently_over)
tsi.FireEvent (mea, ToolStripItemEventType.MouseMove);
else {
// If we were over a different item, fire a mouse leave on it
if (mouse_currently_over != null) {
MouseLeftItem (tsi);
mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseLeave);
}
// Set the new item we are currently over
mouse_currently_over = tsi;
// Fire mouse enter and mouse move
tsi.FireEvent (mea, ToolStripItemEventType.MouseEnter);
MouseEnteredItem (tsi);
tsi.FireEvent (mea, ToolStripItemEventType.MouseMove);
// If we're over something with a drop down, show it
if (menu_selected && mouse_currently_over.Enabled && mouse_currently_over is ToolStripDropDownItem && (mouse_currently_over as ToolStripDropDownItem).HasDropDownItems)
(mouse_currently_over as ToolStripDropDownItem).ShowDropDown ();
}
} else {
// We're not over anything now, just fire the mouse leave on what we used to be over
if (mouse_currently_over != null) {
MouseLeftItem (tsi);
mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseLeave);
mouse_currently_over = null;
}
}
base.OnMouseMove (mea);
}
protected override void OnMouseUp (MouseEventArgs mea)
{
// If we're currently over an item (set in MouseMove)
if (mouse_currently_over != null && !(mouse_currently_over is ToolStripControlHost) && mouse_currently_over.Enabled) {
// Fire our ItemClicked event
OnItemClicked (new ToolStripItemClickedEventArgs (mouse_currently_over));
// Fire the item's MouseUp event
if (mouse_currently_over != null)
mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseUp);
// The event handler may have blocked until the mouse moved off of the ToolStripItem
if (mouse_currently_over == null)
return;
}
base.OnMouseUp (mea);
}
protected override void OnPaint (PaintEventArgs e)
{
base.OnPaint (e);
// Draw the grip
this.OnPaintGrip (e);
// Make each item draw itself
for (int i = 0; i < displayed_items.Count; i++) {
ToolStripItem tsi = displayed_items[i];
if (tsi.Visible) {
e.Graphics.TranslateTransform (tsi.Bounds.Left, tsi.Bounds.Top);
tsi.FireEvent (e, ToolStripItemEventType.Paint);
e.Graphics.ResetTransform ();
}
}
// Paint the Overflow button if it's visible
if (this.overflow_button != null && this.overflow_button.Visible) {
e.Graphics.TranslateTransform (this.overflow_button.Bounds.Left, this.overflow_button.Bounds.Top);
this.overflow_button.FireEvent (e, ToolStripItemEventType.Paint);
e.Graphics.ResetTransform ();
}
Rectangle affected_bounds = new Rectangle (Point.Empty, this.Size);
ToolStripRenderEventArgs pevent = new ToolStripRenderEventArgs (e.Graphics, this, affected_bounds, Color.Empty);
pevent.InternalConnectedArea = CalculateConnectedArea ();
this.Renderer.DrawToolStripBorder (pevent);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void OnPaintBackground (PaintEventArgs e)
{
base.OnPaintBackground (e);
Rectangle affected_bounds = new Rectangle (Point.Empty, this.Size);
ToolStripRenderEventArgs tsrea = new ToolStripRenderEventArgs (e.Graphics, this, affected_bounds, SystemColors.Control);
this.Renderer.DrawToolStripBackground (tsrea);
}
protected internal virtual void OnPaintGrip (PaintEventArgs e)
{
// Never draw a grip with these two layouts
if (this.layout_style == ToolStripLayoutStyle.Flow || this.layout_style == ToolStripLayoutStyle.Table)
return;
PaintEventHandler eh = (PaintEventHandler)(Events [PaintGripEvent]);
if (eh != null)
eh (this, e);
if (!(this is MenuStrip)) {
if (this.orientation == Orientation.Horizontal)
e.Graphics.TranslateTransform (2, 0);
else
e.Graphics.TranslateTransform (0, 2);
}
this.Renderer.DrawGrip (new ToolStripGripRenderEventArgs (e.Graphics, this, this.GripRectangle, this.GripDisplayStyle, this.grip_style));
e.Graphics.ResetTransform ();
}
protected virtual void OnRendererChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [RendererChangedEvent]);
if (eh != null)
eh (this, e);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void OnRightToLeftChanged (EventArgs e)
{
base.OnRightToLeftChanged (e);
foreach (ToolStripItem tsi in this.Items)
tsi.OnParentRightToLeftChanged (e);
}
protected override void OnScroll (ScrollEventArgs se)
{
base.OnScroll (se);
}
protected override void OnTabStopChanged (EventArgs e)
{
base.OnTabStopChanged (e);
}
protected override void OnVisibleChanged (EventArgs e)
{
if (!Visible)
CloseToolTip (null);
base.OnVisibleChanged (e);
}
protected override bool ProcessCmdKey (ref Message m, Keys keyData)
{
return base.ProcessCmdKey (ref m, keyData);
}
protected override bool ProcessDialogKey (Keys keyData)
{
if (!this.KeyboardActive)
return false;
// Give each item a chance to handle the key
foreach (ToolStripItem tsi in this.Items)
if (tsi.ProcessDialogKey (keyData))
return true;
// See if I want to handle it
if (this.ProcessArrowKey (keyData))
return true;
ToolStrip ts = null;
switch (keyData) {
case Keys.Escape:
this.Dismiss (ToolStripDropDownCloseReason.Keyboard);
return true;
case Keys.Control | Keys.Tab:
ts = ToolStripManager.GetNextToolStrip (this, true);
if (ts != null) {
foreach (ToolStripItem tsi in this.Items)
tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
ToolStripManager.SetActiveToolStrip (ts, true);
ts.SelectNextToolStripItem (null, true);
}
return true;
case Keys.Control | Keys.Shift | Keys.Tab:
ts = ToolStripManager.GetNextToolStrip (this, false);
if (ts != null) {
foreach (ToolStripItem tsi in this.Items)
tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
ToolStripManager.SetActiveToolStrip (ts, true);
ts.SelectNextToolStripItem (null, true);
}
return true;
case Keys.Down:
case Keys.Up:
case Keys.Left:
case Keys.Right:
if (GetCurrentlySelectedItem () is ToolStripControlHost)
return false;
break;
}
return base.ProcessDialogKey (keyData);
}
protected override bool ProcessMnemonic (char charCode)
{
// If any item has an explicit mnemonic, it gets the message
foreach (ToolStripItem tsi in this.Items)
if (tsi.Enabled && tsi.Visible && !string.IsNullOrEmpty (tsi.Text) && Control.IsMnemonic (charCode, tsi.Text))
return tsi.ProcessMnemonic (charCode);
string code = Char.ToUpper (charCode).ToString ();
// If any item's text starts with our letter, it gets the message
if ((Control.ModifierKeys & Keys.Alt) != 0 || this is ToolStripDropDownMenu)
foreach (ToolStripItem tsi in this.Items)
if (tsi.Enabled && tsi.Visible && !string.IsNullOrEmpty (tsi.Text) && tsi.Text.ToUpper ().StartsWith (code) && !(tsi is ToolStripControlHost))
return tsi.ProcessMnemonic (charCode);
return base.ProcessMnemonic (charCode);
}
[MonoTODO ("Stub, does nothing")]
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void RestoreFocus ()
{
}
protected override void Select (bool directed, bool forward)
{
foreach (ToolStripItem tsi in this.DisplayedItems)
if (tsi.CanSelect) {
tsi.Select ();
break;
}
}
protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore (x, y, width, height, specified);
}
protected virtual void SetDisplayedItems ()
{
this.displayed_items.ClearInternal ();
foreach (ToolStripItem tsi in this.items)
if (tsi.Placement == ToolStripItemPlacement.Main && tsi.Available) {
this.displayed_items.AddNoOwnerOrLayout (tsi);
tsi.Parent = this;
}
else if (tsi.Placement == ToolStripItemPlacement.Overflow)
tsi.Parent = this.OverflowButton.DropDown;
if (this.OverflowButton != null)
this.OverflowButton.DropDown.SetDisplayedItems ();
}
protected internal void SetItemLocation (ToolStripItem item, Point location)
{
if (item == null)
throw new ArgumentNullException ("item");
if (item.Owner != this)
throw new NotSupportedException ("The item is not owned by this ToolStrip");
item.SetBounds (new Rectangle (location, item.Size));
}
protected internal static void SetItemParent (ToolStripItem item, ToolStrip parent)
{
if (item.Owner != null) {
item.Owner.Items.RemoveNoOwnerOrLayout (item);
if (item.Owner is ToolStripOverflow)
(item.Owner as ToolStripOverflow).ParentToolStrip.Items.RemoveNoOwnerOrLayout (item);
}
parent.Items.AddNoOwnerOrLayout (item);
item.Parent = parent;
}
protected override void SetVisibleCore (bool visible)
{
base.SetVisibleCore (visible);
}
protected override void WndProc (ref Message m)
{
base.WndProc (ref m);
}
#endregion
#region Public Events
static object BeginDragEvent = new object ();
static object EndDragEvent = new object ();
static object ItemAddedEvent = new object ();
static object ItemClickedEvent = new object ();
static object ItemRemovedEvent = new object ();
static object LayoutCompletedEvent = new object ();
static object LayoutStyleChangedEvent = new object ();
static object PaintGripEvent = new object ();
static object RendererChangedEvent = new object ();
[Browsable (true)]
[EditorBrowsable (EditorBrowsableState.Always)]
public new event EventHandler AutoSizeChanged {
add { base.AutoSizeChanged += value; }
remove { base.AutoSizeChanged -= value; }
}
[MonoTODO ("Event never raised")]
public event EventHandler BeginDrag {
add { Events.AddHandler (BeginDragEvent, value); }
remove { Events.RemoveHandler (BeginDragEvent, value); }
}
[Browsable (false)]
public new event EventHandler CausesValidationChanged {
add { base.CausesValidationChanged += value; }
remove { base.CausesValidationChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event ControlEventHandler ControlAdded {
add { base.ControlAdded += value; }
remove { base.ControlAdded -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event ControlEventHandler ControlRemoved {
add { base.ControlRemoved += value; }
remove { base.ControlRemoved -= value; }
}
[Browsable (false)]
public new event EventHandler CursorChanged {
add { base.CursorChanged += value; }
remove { base.CursorChanged -= value; }
}
[MonoTODO ("Event never raised")]
public event EventHandler EndDrag {
add { Events.AddHandler (EndDragEvent, value); }
remove { Events.RemoveHandler (EndDragEvent, value); }
}
[Browsable (false)]
public new event EventHandler ForeColorChanged {
add { base.ForeColorChanged += value; }
remove { base.ForeColorChanged -= value; }
}
public event ToolStripItemEventHandler ItemAdded {
add { Events.AddHandler (ItemAddedEvent, value); }
remove { Events.RemoveHandler (ItemAddedEvent, value); }
}
public event ToolStripItemClickedEventHandler ItemClicked {
add { Events.AddHandler (ItemClickedEvent, value); }
remove { Events.RemoveHandler (ItemClickedEvent, value); }
}
public event ToolStripItemEventHandler ItemRemoved {
add { Events.AddHandler (ItemRemovedEvent, value); }
remove { Events.RemoveHandler (ItemRemovedEvent, value); }
}
public event EventHandler LayoutCompleted {
add { Events.AddHandler (LayoutCompletedEvent, value); }
remove { Events.RemoveHandler (LayoutCompletedEvent, value); }
}
public event EventHandler LayoutStyleChanged {
add { Events.AddHandler (LayoutStyleChangedEvent, value); }
remove { Events.RemoveHandler (LayoutStyleChangedEvent, value); }
}
public event PaintEventHandler PaintGrip {
add { Events.AddHandler (PaintGripEvent, value); }
remove { Events.RemoveHandler (PaintGripEvent, value); }
}
public event EventHandler RendererChanged {
add { Events.AddHandler (RendererChangedEvent, value); }
remove { Events.RemoveHandler (RendererChangedEvent, value); }
}
#endregion
#region Internal Properties
internal virtual bool KeyboardActive
{
get { return this.keyboard_active; }
set {
if (this.keyboard_active != value) {
this.keyboard_active = value;
if (value)
Application.KeyboardCapture = this;
else if (Application.KeyboardCapture == this) {
Application.KeyboardCapture = null;
ToolStripManager.ActivatedByKeyboard = false;
}
// Redraw for mnemonic underlines
this.Invalidate ();
}
}
}
#endregion
#region Private Methods
internal virtual Rectangle CalculateConnectedArea ()
{
return Rectangle.Empty;
}
internal void ChangeSelection (ToolStripItem nextItem)
{
if (Application.KeyboardCapture != this)
ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard);
foreach (ToolStripItem tsi in this.Items)
if (tsi != nextItem)
tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
ToolStripItem current = GetCurrentlySelectedItem ();
if (current != null && !(current is ToolStripControlHost))
this.FocusInternal (true);
if (nextItem is ToolStripControlHost)
(nextItem as ToolStripControlHost).Focus ();
nextItem.Select ();
if (nextItem.Parent is MenuStrip && (nextItem.Parent as MenuStrip).MenuDroppedDown)
(nextItem as ToolStripMenuItem).HandleAutoExpansion ();
}
internal virtual void Dismiss ()
{
this.Dismiss (ToolStripDropDownCloseReason.AppClicked);
}
internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
{
// Release our stranglehold on the keyboard
this.KeyboardActive = false;
// Set our drop down flag to false;
this.menu_selected = false;
// Make sure all of our items are deselected and repainted
foreach (ToolStripItem tsi in this.Items)
tsi.Dismiss (reason);
// We probably need to redraw for mnemonic underlines
this.Invalidate ();
}
internal ToolStripItem GetCurrentlySelectedItem ()
{
foreach (ToolStripItem tsi in this.DisplayedItems)
if (tsi.Selected)
return tsi;
return null;
}
internal ToolStripItem GetCurrentlyFocusedItem ()
{
foreach (ToolStripItem tsi in this.DisplayedItems)
if ((tsi is ToolStripControlHost) && (tsi as ToolStripControlHost).Control.Focused)
return tsi;
return null;
}
internal override Size GetPreferredSizeCore (Size proposedSize)
{
return GetToolStripPreferredSize (proposedSize);
}
internal virtual Size GetToolStripPreferredSize (Size proposedSize)
{
Size new_size = Size.Empty;
// TODO: This is total duct tape. We really have to call into the correct
// layout engine, do a dry run of the layout, and find out our true
// preferred dimensions.
if (this.LayoutStyle == ToolStripLayoutStyle.Flow) {
Point currentLocation = Point.Empty;
int tallest = 0;
foreach (ToolStripItem tsi in items)
if (tsi.Available) {
Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);
if ((DisplayRectangle.Width - currentLocation.X) < (tsi_preferred.Width + tsi.Margin.Horizontal)) {
currentLocation.Y += tallest;
tallest = 0;
currentLocation.X = DisplayRectangle.Left;
}
// Offset the left margin and set the control to our point
currentLocation.Offset (tsi.Margin.Left, 0);
tallest = Math.Max (tallest, tsi_preferred.Height + tsi.Margin.Vertical);
// Update our location pointer
currentLocation.X += tsi_preferred.Width + tsi.Margin.Right;
}
currentLocation.Y += tallest;
return new Size (currentLocation.X + this.Padding.Horizontal, currentLocation.Y + this.Padding.Vertical);
}
if (this.orientation == Orientation.Vertical) {
foreach (ToolStripItem tsi in this.items)
if (tsi.Available) {
Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);
new_size.Height += tsi_preferred.Height + tsi.Margin.Top + tsi.Margin.Bottom;
if (new_size.Width < (this.Padding.Horizontal + tsi_preferred.Width + tsi.Margin.Horizontal))
new_size.Width = (this.Padding.Horizontal + tsi_preferred.Width + tsi.Margin.Horizontal);
}
new_size.Height += (this.GripRectangle.Height + this.GripMargin.Vertical + this.Padding.Vertical + 4);
if (new_size.Width == 0)
new_size.Width = ExplicitBounds.Width;
return new_size;
} else {
foreach (ToolStripItem tsi in this.items)
if (tsi.Available) {
Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);
new_size.Width += tsi_preferred.Width + tsi.Margin.Left + tsi.Margin.Right;
if (new_size.Height < (this.Padding.Vertical + tsi_preferred.Height + tsi.Margin.Vertical))
new_size.Height = (this.Padding.Vertical + tsi_preferred.Height + tsi.Margin.Vertical);
}
new_size.Width += (this.GripRectangle.Width + this.GripMargin.Horizontal + this.Padding.Horizontal + 4);
if (new_size.Height == 0)
new_size.Height = ExplicitBounds.Height;
if (this is StatusStrip)
new_size.Height = Math.Max (new_size.Height, 22);
return new_size;
}
}
internal virtual ToolStrip GetTopLevelToolStrip ()
{
return this;
}
internal virtual void HandleItemClick (ToolStripItem dismissingItem)
{
this.GetTopLevelToolStrip ().Dismiss (ToolStripDropDownCloseReason.ItemClicked);
}
internal void NotifySelectedChanged (ToolStripItem tsi)
{
foreach (ToolStripItem tsi2 in this.DisplayedItems)
if (tsi != tsi2)
if (tsi2 is ToolStripDropDownItem)
(tsi2 as ToolStripDropDownItem).HideDropDown (ToolStripDropDownCloseReason.Keyboard);
if (this.OverflowButton != null) {
ToolStripItemCollection tsic = this.OverflowButton.DropDown.DisplayedItems;
foreach (ToolStripItem tsi2 in tsic)
if (tsi != tsi2)
if (tsi2 is ToolStripDropDownItem)
(tsi2 as ToolStripDropDownItem).HideDropDown (ToolStripDropDownCloseReason.Keyboard);
this.OverflowButton.HideDropDown ();
}
foreach (ToolStripItem tsi2 in this.Items)
if (tsi != tsi2)
tsi2.Dismiss (ToolStripDropDownCloseReason.Keyboard);
}
internal virtual bool OnMenuKey ()
{
return false;
}
internal virtual bool ProcessArrowKey (Keys keyData)
{
ToolStripItem tsi;
switch (keyData) {
case Keys.Right:
tsi = this.GetCurrentlySelectedItem ();
if (tsi is ToolStripControlHost)
return false;
tsi = this.SelectNextToolStripItem (tsi, true);
if (tsi is ToolStripControlHost)
(tsi as ToolStripControlHost).Focus ();
return true;
case Keys.Tab:
tsi = this.GetCurrentlySelectedItem ();
tsi = this.SelectNextToolStripItem (tsi, true);
if (tsi is ToolStripControlHost)
(tsi as ToolStripControlHost).Focus ();
return true;
case Keys.Left:
tsi = this.GetCurrentlySelectedItem ();
if (tsi is ToolStripControlHost)
return false;
tsi = this.SelectNextToolStripItem (tsi, false);
if (tsi is ToolStripControlHost)
(tsi as ToolStripControlHost).Focus ();
return true;
case Keys.Shift | Keys.Tab:
tsi = this.GetCurrentlySelectedItem ();
tsi = this.SelectNextToolStripItem (tsi, false);
if (tsi is ToolStripControlHost)
(tsi as ToolStripControlHost).Focus ();
return true;
}
return false;
}
internal virtual ToolStripItem SelectNextToolStripItem (ToolStripItem start, bool forward)
{
ToolStripItem next_item = this.GetNextItem (start, forward ? ArrowDirection.Right : ArrowDirection.Left);
if (next_item == null)
return next_item;
this.ChangeSelection (next_item);
if (next_item is ToolStripControlHost)
(next_item as ToolStripControlHost).Focus ();
return next_item;
}
#region Stuff for ToolTips
private void MouseEnteredItem (ToolStripItem item)
{
if (this.show_item_tool_tips && !(item is ToolStripTextBox)) {
ToolTipTimer.Interval = InitialToolTipDelay;
tooltip_state = ToolTip.TipState.Initial;
tooltip_currently_showing = item;
ToolTipTimer.Start ();
}
}
private void CloseToolTip (ToolStripItem item)
{
ToolTipTimer.Stop ();
ToolTipWindow.Hide (this);
tooltip_currently_showing = null;
tooltip_state = ToolTip.TipState.Down;
}
private void MouseLeftItem (ToolStripItem item)
{
CloseToolTip (item);
}
private Timer ToolTipTimer {
get {
if (tooltip_timer == null) {
tooltip_timer = new Timer ();
tooltip_timer.Enabled = false;
tooltip_timer.Interval = InitialToolTipDelay;
tooltip_timer.Tick += new EventHandler (ToolTipTimer_Tick);
}
return tooltip_timer;
}
}
private ToolTip ToolTipWindow {
get {
if (tooltip_window == null)
tooltip_window = new ToolTip ();
return tooltip_window;
}
}
private void ShowToolTip ()
{
string tooltip = tooltip_currently_showing.GetToolTip ();
if (!string.IsNullOrEmpty (tooltip)) {
ToolTipWindow.Present (this, tooltip);
ToolTipTimer.Interval = ToolTipDelay;
ToolTipTimer.Start ();
tooltip_state = ToolTip.TipState.Show;
}
tooltip_currently_showing.FireEvent (EventArgs.Empty, ToolStripItemEventType.MouseHover);
}
private void ToolTipTimer_Tick (object o, EventArgs args)
{
ToolTipTimer.Stop ();
switch (tooltip_state) {
case ToolTip.TipState.Initial:
ShowToolTip ();
break;
case ToolTip.TipState.Show:
CloseToolTip (null);
break;
}
}
#endregion
#region Stuff for Merging
internal ToolStrip CurrentlyMergedWith {
get { return this.currently_merged_with; }
set { this.currently_merged_with = value; }
}
internal List<ToolStripItem> HiddenMergedItems {
get {
if (this.hidden_merged_items == null)
this.hidden_merged_items = new List<ToolStripItem> ();
return this.hidden_merged_items;
}
}
internal bool IsCurrentlyMerged {
get { return this.is_currently_merged; }
set {
this.is_currently_merged = value;
if (!value && this is MenuStrip)
foreach (ToolStripMenuItem tsmi in this.Items)
tsmi.DropDown.IsCurrentlyMerged = value;
}
}
internal void BeginMerge ()
{
if (!IsCurrentlyMerged) {
IsCurrentlyMerged = true;
if (this.pre_merge_items == null) {
this.pre_merge_items = new List<ToolStripItem> ();
foreach (ToolStripItem tsi in this.Items)
this.pre_merge_items.Add (tsi);
}
}
}
internal void RevertMergeItem (ToolStripItem item)
{
int index = 0;
// Remove it from it's current Parent
if (item.Parent != null && item.Parent != this) {
if (item.Parent is ToolStripOverflow)
(item.Parent as ToolStripOverflow).ParentToolStrip.Items.RemoveNoOwnerOrLayout (item);
else
item.Parent.Items.RemoveNoOwnerOrLayout (item);
item.Parent = item.Owner;
}
// Find where the item was before the merge
index = item.Owner.pre_merge_items.IndexOf (item);
// Find the first pre-merge item that was after this item, that
// is currently in the Items collection. Insert our item before
// that one.
for (int i = index; i < this.pre_merge_items.Count; i++) {
if (this.Items.Contains (this.pre_merge_items[i])) {
item.Owner.Items.InsertNoOwnerOrLayout (this.Items.IndexOf (this.pre_merge_items[i]), item);
return;
}
}
// There aren't any items that are supposed to be after this item,
// so just append it to the end.
item.Owner.Items.AddNoOwnerOrLayout (item);
}
#endregion
#endregion
#region ToolStripAccessibleObject
[ComVisible (true)]
public class ToolStripAccessibleObject : ControlAccessibleObject
{
#region Public Constructor
public ToolStripAccessibleObject (ToolStrip owner) : base (owner)
{
}
#endregion
#region Public Properties
public override AccessibleRole Role {
get { return AccessibleRole.ToolBar; }
}
#endregion
#region Public Methods
public override AccessibleObject GetChild (int index)
{
return base.GetChild (index);
}
public override int GetChildCount ()
{
return (owner as ToolStrip).Items.Count;
}
public override AccessibleObject HitTest (int x, int y)
{
return base.HitTest (x, y);
}
#endregion
}
#endregion
}
}
|