4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
31 using System.Runtime.InteropServices;
32 using System.ComponentModel;
34 using System.Windows.Forms.Layout;
35 using System.Collections.Generic;
36 using System.ComponentModel.Design.Serialization;
38 namespace System.Windows.Forms
41 [ClassInterface (ClassInterfaceType.AutoDispatch)]
42 [DefaultEvent ("ItemClicked")]
43 [DefaultProperty ("Items")]
44 [Designer ("System.Windows.Forms.Design.ToolStripDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
45 [DesignerSerializer ("System.Windows.Forms.Design.ToolStripCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
46 public class ToolStrip : ScrollableControl, IComponent, IDisposable
48 #region Private Variables
49 private bool allow_item_reorder;
50 private bool allow_merge;
51 private Color back_color;
52 private bool can_overflow;
53 private ToolStrip currently_merged_with;
54 private ToolStripDropDownDirection default_drop_down_direction;
55 internal ToolStripItemCollection displayed_items;
56 private Color fore_color;
57 private Padding grip_margin;
58 private ToolStripGripStyle grip_style;
59 private List<ToolStripItem> hidden_merged_items;
60 private ImageList image_list;
61 private Size image_scaling_size;
62 private bool is_currently_merged;
63 private ToolStripItemCollection items;
64 private bool keyboard_active;
65 private LayoutEngine layout_engine;
66 private LayoutSettings layout_settings;
67 private ToolStripLayoutStyle layout_style;
68 private Orientation orientation;
69 private ToolStripOverflowButton overflow_button;
70 private List<ToolStripItem> pre_merge_items;
71 private ToolStripRenderer renderer;
72 private ToolStripRenderMode render_mode;
73 private ToolStripTextDirection text_direction;
74 private Timer tooltip_timer;
75 private ToolTip tooltip_window;
76 private bool show_item_tool_tips;
79 private ToolStripItem mouse_currently_over;
80 internal bool menu_selected;
81 private ToolStripItem tooltip_currently_showing;
84 #region Public Constructors
85 public ToolStrip () : this (null)
89 public ToolStrip (params ToolStripItem[] items) : base ()
91 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
92 SetStyle (ControlStyles.OptimizedDoubleBuffer, true);
93 SetStyle (ControlStyles.Selectable, false);
94 SetStyle (ControlStyles.SupportsTransparentBackColor, true);
96 this.SuspendLayout ();
98 this.items = new ToolStripItemCollection (this, items, true);
99 this.allow_merge = true;
100 base.AutoSize = true;
101 this.back_color = Control.DefaultBackColor;
102 this.can_overflow = true;
103 base.CausesValidation = false;
104 this.default_drop_down_direction = ToolStripDropDownDirection.BelowRight;
105 this.displayed_items = new ToolStripItemCollection (this, null, true);
106 this.Dock = this.DefaultDock;
107 base.Font = new Font ("Tahoma", 8.25f);
108 this.fore_color = Control.DefaultForeColor;
109 this.grip_margin = this.DefaultGripMargin;
110 this.grip_style = ToolStripGripStyle.Visible;
111 this.image_scaling_size = new Size (16, 16);
112 this.layout_style = ToolStripLayoutStyle.HorizontalStackWithOverflow;
113 this.orientation = Orientation.Horizontal;
114 if (!(this is ToolStripDropDown))
115 this.overflow_button = new ToolStripOverflowButton (this);
116 this.renderer = null;
117 this.render_mode = ToolStripRenderMode.ManagerRenderMode;
118 this.show_item_tool_tips = this.DefaultShowItemToolTips;
119 base.TabStop = false;
120 this.text_direction = ToolStripTextDirection.Horizontal;
121 this.ResumeLayout ();
124 // Register with the ToolStripManager
125 ToolStripManager.AddToolStrip (this);
129 #region Public Properties
131 public override bool AllowDrop {
132 get { return base.AllowDrop; }
133 set { base.AllowDrop = value; }
137 [DefaultValue (false)]
138 public bool AllowItemReorder {
139 get { return this.allow_item_reorder; }
140 set { this.allow_item_reorder = value; }
143 [DefaultValue (true)]
144 public bool AllowMerge {
145 get { return this.allow_merge; }
146 set { this.allow_merge = false; }
149 public override AnchorStyles Anchor {
150 get { return base.Anchor; }
151 set { base.Anchor = value; }
155 [EditorBrowsable (EditorBrowsableState.Never)]
156 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
157 public override bool AutoScroll {
158 get { return base.AutoScroll; }
159 set { base.AutoScroll = value; }
163 [EditorBrowsable (EditorBrowsableState.Never)]
164 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
165 public new Size AutoScrollMargin {
166 get { return base.AutoScrollMargin; }
167 set { base.AutoScrollMargin = value; }
171 [EditorBrowsable (EditorBrowsableState.Never)]
172 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
173 public new Size AutoScrollMinSize {
174 get { return base.AutoScrollMinSize; }
175 set { base.AutoScrollMinSize = value; }
179 [EditorBrowsable (EditorBrowsableState.Never)]
180 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
181 public new Point AutoScrollPosition {
182 get { return base.AutoScrollPosition; }
183 set { base.AutoScrollPosition = value; }
186 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
188 [EditorBrowsable (EditorBrowsableState.Always)]
189 [DefaultValue (true)]
190 public override bool AutoSize {
191 get { return base.AutoSize; }
192 set { base.AutoSize = value; }
195 new public Color BackColor {
196 get { return this.back_color; }
197 set { this.back_color = value; }
200 public override BindingContext BindingContext {
201 get { return base.BindingContext; }
202 set { base.BindingContext = value; }
205 [DefaultValue (true)]
206 public bool CanOverflow {
207 get { return this.can_overflow; }
208 set { this.can_overflow = value; }
212 [DefaultValue (false)]
213 public new bool CausesValidation {
214 get { return base.CausesValidation; }
215 set { base.CausesValidation = value; }
218 [EditorBrowsable (EditorBrowsableState.Never)]
219 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
220 public new ControlCollection Controls {
221 get { return base.Controls; }
225 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
226 public override Cursor Cursor {
227 get { return base.Cursor; }
228 set { base.Cursor = value; }
232 public virtual ToolStripDropDownDirection DefaultDropDownDirection {
233 get { return this.default_drop_down_direction; }
235 if (!Enum.IsDefined (typeof (ToolStripDropDownDirection), value))
236 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripDropDownDirection", value));
238 this.default_drop_down_direction = value;
242 public override Rectangle DisplayRectangle {
244 if (this.orientation == Orientation.Horizontal)
245 if (this.grip_style == ToolStripGripStyle.Hidden || this.layout_style == ToolStripLayoutStyle.Flow || this.layout_style == ToolStripLayoutStyle.Table)
246 return new Rectangle (this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical);
248 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);
250 if (this.grip_style == ToolStripGripStyle.Hidden || this.layout_style == ToolStripLayoutStyle.Flow || this.layout_style == ToolStripLayoutStyle.Table)
251 return new Rectangle (this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical);
253 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);
257 [DefaultValue (DockStyle.Top)]
258 public override DockStyle Dock {
259 get { return base.Dock; }
261 if (base.Dock != value) {
266 case DockStyle.Bottom:
268 this.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
271 case DockStyle.Right:
272 this.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
279 public override Font Font {
280 get { return base.Font; }
282 if (base.Font != value) {
285 foreach (ToolStripItem tsi in this.Items)
286 tsi.OnOwnerFontChanged (EventArgs.Empty);
292 public new Color ForeColor {
293 get { return this.fore_color; }
295 if (this.fore_color != value) {
296 this.fore_color = value;
297 this.OnForeColorChanged (EventArgs.Empty);
303 public ToolStripGripDisplayStyle GripDisplayStyle {
304 get { return this.orientation == Orientation.Vertical ? ToolStripGripDisplayStyle.Horizontal : ToolStripGripDisplayStyle.Vertical; }
307 public Padding GripMargin {
308 get { return this.grip_margin; }
310 if (this.grip_margin != value) {
311 this.grip_margin = value;
312 this.PerformLayout ();
318 public Rectangle GripRectangle {
320 if (this.grip_style == ToolStripGripStyle.Hidden)
321 return Rectangle.Empty;
323 if (this.orientation == Orientation.Horizontal)
324 return new Rectangle (this.grip_margin.Left + this.Padding.Left, this.Padding.Top, 3, this.Height);
326 return new Rectangle (this.Padding.Left, this.grip_margin.Top + this.Padding.Top, this.Width, 3);
330 [DefaultValue (ToolStripGripStyle.Visible)]
331 public ToolStripGripStyle GripStyle {
332 get { return this.grip_style; }
334 if (this.grip_style != value) {
335 if (!Enum.IsDefined (typeof (ToolStripGripStyle), value))
336 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripGripStyle", value));
337 this.grip_style = value;
338 this.PerformLayout ();
344 [EditorBrowsable (EditorBrowsableState.Never)]
345 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
346 public new bool HasChildren {
347 get { return base.HasChildren; }
351 [EditorBrowsable (EditorBrowsableState.Never)]
352 public new HScrollProperties HorizontalScroll {
353 get { return base.HorizontalScroll; }
357 [DefaultValue (null)]
358 public ImageList ImageList {
359 get { return this.image_list; }
360 set { this.image_list = value; }
363 [DefaultValue ("{Width=16, Height=16}")]
364 public Size ImageScalingSize {
365 get { return this.image_scaling_size; }
366 set { this.image_scaling_size = value; }
369 [MonoTODO ("Always returns false, dragging not implemented yet.")]
371 [EditorBrowsable (EditorBrowsableState.Advanced)]
372 public bool IsCurrentlyDragging {
373 get { return false; }
377 public bool IsDropDown {
379 if (this is ToolStripDropDown)
386 [MergableProperty (false)]
387 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
388 public virtual ToolStripItemCollection Items {
389 get { return this.items; }
392 public override LayoutEngine LayoutEngine {
394 if (layout_engine == null)
395 this.layout_engine = new ToolStripSplitStackLayout ();
397 return this.layout_engine;
402 [DefaultValue (null)]
403 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
404 public LayoutSettings LayoutSettings {
405 get { return this.layout_settings; }
406 set { this.layout_settings = value; }
409 [AmbientValue (ToolStripLayoutStyle.StackWithOverflow)]
410 public ToolStripLayoutStyle LayoutStyle {
411 get { return layout_style; }
413 if (this.layout_style != value) {
414 if (!Enum.IsDefined (typeof (ToolStripLayoutStyle), value))
415 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripLayoutStyle", value));
417 this.layout_style = value;
419 if (this.layout_style == ToolStripLayoutStyle.Flow)
420 this.layout_engine = new FlowLayout ();
422 this.layout_engine = new ToolStripSplitStackLayout ();
424 if (this.layout_style == ToolStripLayoutStyle.StackWithOverflow) {
425 if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right)
426 this.layout_style = ToolStripLayoutStyle.VerticalStackWithOverflow;
428 this.layout_style = ToolStripLayoutStyle.HorizontalStackWithOverflow;
431 if (this.layout_style == ToolStripLayoutStyle.HorizontalStackWithOverflow)
432 this.orientation = Orientation.Horizontal;
433 else if (this.layout_style == ToolStripLayoutStyle.VerticalStackWithOverflow)
434 this.orientation = Orientation.Vertical;
436 this.layout_settings = this.CreateLayoutSettings (value);
438 this.PerformLayout ();
439 this.OnLayoutStyleChanged (EventArgs.Empty);
445 public Orientation Orientation {
446 get { return this.orientation; }
450 [EditorBrowsable (EditorBrowsableState.Advanced)]
451 public ToolStripOverflowButton OverflowButton {
452 get { return this.overflow_button; }
456 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
457 public ToolStripRenderer Renderer {
459 if (this.render_mode == ToolStripRenderMode.ManagerRenderMode)
460 return ToolStripManager.Renderer;
462 return this.renderer;
465 if (this.renderer != value) {
466 this.renderer = value;
467 this.render_mode = ToolStripRenderMode.Custom;
468 this.PerformLayout ();
469 this.OnRendererChanged (EventArgs.Empty);
474 public ToolStripRenderMode RenderMode {
475 get { return this.render_mode; }
477 if (!Enum.IsDefined (typeof (ToolStripRenderMode), value))
478 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripRenderMode", value));
480 if (value == ToolStripRenderMode.Custom && this.renderer == null)
481 throw new NotSupportedException ("Must set Renderer property before setting RenderMode to Custom");
482 else if (value == ToolStripRenderMode.Professional)
483 this.Renderer = new ToolStripProfessionalRenderer ();
484 else if (value == ToolStripRenderMode.System)
485 this.Renderer = new ToolStripSystemRenderer ();
487 this.render_mode = value;
491 [DefaultValue (true)]
492 public bool ShowItemToolTips {
493 get { return this.show_item_tool_tips; }
494 set { this.show_item_tool_tips = value; }
497 [DefaultValue (false)]
498 public bool Stretch {
499 get { return this.stretch; }
500 set { this.stretch = value; }
503 [DefaultValue (false)]
505 public new bool TabStop {
506 get { return base.TabStop; }
507 set { base.TabStop = value; }
510 [DefaultValue (ToolStripTextDirection.Horizontal)]
511 public virtual ToolStripTextDirection TextDirection {
512 get { return this.text_direction; }
514 if (!Enum.IsDefined (typeof (ToolStripTextDirection), value))
515 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripTextDirection", value));
517 if (this.text_direction != value) {
518 this.text_direction = value;
520 this.PerformLayout (this, "TextDirection");
528 [EditorBrowsable (EditorBrowsableState.Never)]
529 public new VScrollProperties VerticalScroll {
530 get { return base.VerticalScroll; }
534 #region Protected Properties
535 protected virtual DockStyle DefaultDock { get { return DockStyle.Top; } }
536 protected virtual Padding DefaultGripMargin { get { return new Padding (2); } }
537 protected override Padding DefaultMargin { get { return Padding.Empty; } }
538 protected override Padding DefaultPadding { get { return new Padding (0, 0, 1, 0); } }
539 protected virtual bool DefaultShowItemToolTips { get { return true; } }
540 protected override Size DefaultSize { get { return new Size (100, 25); } }
541 protected internal virtual ToolStripItemCollection DisplayedItems { get { return this.displayed_items; } }
542 protected internal virtual Size MaxItemSize {
543 get { return new Size (Width - (GripStyle == ToolStripGripStyle.Hidden ? 1 : 8), Height); }
547 #region Public Methods
548 [EditorBrowsable (EditorBrowsableState.Never)]
549 public new Control GetChildAtPoint (Point point)
551 return base.GetChildAtPoint (point);
554 [EditorBrowsable (EditorBrowsableState.Never)]
555 public new Control GetChildAtPoint (Point pt, GetChildAtPointSkip skipValue)
557 return base.GetChildAtPoint (pt, skipValue);
560 public ToolStripItem GetItemAt (Point point)
562 foreach (ToolStripItem tsi in this.displayed_items)
563 if (tsi.Visible && tsi.Bounds.Contains (point))
569 public ToolStripItem GetItemAt (int x, int y)
571 return GetItemAt (new Point (x, y));
574 public virtual ToolStripItem GetNextItem (ToolStripItem start, ArrowDirection direction)
576 if (!Enum.IsDefined (typeof (ArrowDirection), direction))
577 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ArrowDirection", direction));
579 ToolStripItem current_best = null;
580 int current_best_point;
583 case ArrowDirection.Right:
584 current_best_point = int.MaxValue;
587 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
588 if (loop_tsi.Left >= start.Right && loop_tsi.Left < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
589 current_best = loop_tsi;
590 current_best_point = loop_tsi.Left;
593 if (current_best == null)
594 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
595 if (loop_tsi.Left < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
596 current_best = loop_tsi;
597 current_best_point = loop_tsi.Left;
601 case ArrowDirection.Up:
602 current_best_point = int.MinValue;
605 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
606 if (loop_tsi.Bottom <= start.Top && loop_tsi.Top > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
607 current_best = loop_tsi;
608 current_best_point = loop_tsi.Top;
611 if (current_best == null)
612 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
613 if (loop_tsi.Top > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
614 current_best = loop_tsi;
615 current_best_point = loop_tsi.Top;
619 case ArrowDirection.Left:
620 current_best_point = int.MinValue;
623 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
624 if (loop_tsi.Right <= start.Left && loop_tsi.Left > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
625 current_best = loop_tsi;
626 current_best_point = loop_tsi.Left;
629 if (current_best == null)
630 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
631 if (loop_tsi.Left > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
632 current_best = loop_tsi;
633 current_best_point = loop_tsi.Left;
637 case ArrowDirection.Down:
638 current_best_point = int.MaxValue;
641 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
642 if (loop_tsi.Top >= start.Bottom && loop_tsi.Bottom < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
643 current_best = loop_tsi;
644 current_best_point = loop_tsi.Top;
647 if (current_best == null)
648 foreach (ToolStripItem loop_tsi in this.DisplayedItems)
649 if (loop_tsi.Top < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
650 current_best = loop_tsi;
651 current_best_point = loop_tsi.Top;
660 [EditorBrowsable (EditorBrowsableState.Never)]
661 public void ResetMinimumSize ()
663 this.MinimumSize = new Size (-1, -1);
666 [EditorBrowsable (EditorBrowsableState.Never)]
667 public new void SetAutoScrollMargin (int x, int y)
669 base.SetAutoScrollMargin (x, y);
672 public override string ToString ()
674 return String.Format ("{0}, Name: {1}, Items: {2}", base.ToString(), this.Name, this.items.Count.ToString ());
678 #region Protected Methods
679 protected override AccessibleObject CreateAccessibilityInstance ()
681 return new ToolStripAccessibleObject (this);
684 protected override ControlCollection CreateControlsInstance ()
686 return base.CreateControlsInstance ();
689 protected internal virtual ToolStripItem CreateDefaultItem (string text, Image image, EventHandler onClick)
692 return new ToolStripSeparator ();
694 if (this is ToolStripDropDown)
695 return new ToolStripMenuItem (text, image, onClick);
697 return new ToolStripButton (text, image, onClick);
700 protected virtual LayoutSettings CreateLayoutSettings (ToolStripLayoutStyle layoutStyle)
702 switch (layoutStyle) {
703 case ToolStripLayoutStyle.Flow:
704 return new FlowLayoutSettings ();
705 case ToolStripLayoutStyle.Table:
706 //return new TableLayoutSettings ();
707 case ToolStripLayoutStyle.StackWithOverflow:
708 case ToolStripLayoutStyle.HorizontalStackWithOverflow:
709 case ToolStripLayoutStyle.VerticalStackWithOverflow:
715 protected override void Dispose (bool disposing)
718 ToolStripManager.RemoveToolStrip (this);
719 base.Dispose (disposing);
723 [MonoTODO ("Not called")]
724 protected virtual void OnBeginDrag (EventArgs e)
726 EventHandler eh = (EventHandler)(Events[BeginDragEvent]);
731 protected override void OnDockChanged (EventArgs e)
733 base.OnDockChanged (e);
736 [MonoTODO ("Not called")]
737 protected virtual void OnEndDrag (EventArgs e)
739 EventHandler eh = (EventHandler)(Events[EndDragEvent]);
744 protected override bool IsInputChar (char charCode)
746 return base.IsInputChar (charCode);
749 protected override bool IsInputKey (Keys keyData)
751 return base.IsInputKey (keyData);
754 protected override void OnEnabledChanged (EventArgs e)
756 base.OnEnabledChanged (e);
758 foreach (ToolStripItem tsi in this.Items)
759 tsi.OnParentEnabledChanged (EventArgs.Empty);
762 protected override void OnFontChanged (EventArgs e)
764 base.OnFontChanged (e);
767 protected override void OnHandleCreated (EventArgs e)
769 base.OnHandleCreated (e);
772 protected override void OnHandleDestroyed (EventArgs e)
774 base.OnHandleDestroyed (e);
777 protected override void OnInvalidated (InvalidateEventArgs e)
779 base.OnInvalidated (e);
782 protected internal virtual void OnItemAdded (ToolStripItemEventArgs e)
784 if (e.Item.InternalVisible)
785 e.Item.Available = true;
787 e.Item.SetPlacement (ToolStripItemPlacement.Main);
791 this.PerformLayout ();
793 ToolStripItemEventHandler eh = (ToolStripItemEventHandler)(Events [ItemAddedEvent]);
798 protected virtual void OnItemClicked (ToolStripItemClickedEventArgs e)
800 if (this.KeyboardActive)
801 ToolStripManager.SetActiveToolStrip (null, false);
803 ToolStripItemClickedEventHandler eh = (ToolStripItemClickedEventHandler)(Events [ItemClickedEvent]);
808 protected internal virtual void OnItemRemoved (ToolStripItemEventArgs e)
810 ToolStripItemEventHandler eh = (ToolStripItemEventHandler)(Events [ItemRemovedEvent]);
815 protected override void OnLayout (LayoutEventArgs e)
820 this.SetDisplayedItems ();
821 this.OnLayoutCompleted (EventArgs.Empty);
825 protected virtual void OnLayoutCompleted (EventArgs e)
827 EventHandler eh = (EventHandler)(Events [LayoutCompletedEvent]);
832 protected virtual void OnLayoutStyleChanged (EventArgs e)
834 EventHandler eh = (EventHandler)(Events[LayoutStyleChangedEvent]);
839 protected override void OnLeave (EventArgs e)
844 protected override void OnLostFocus (EventArgs e)
846 base.OnLostFocus (e);
849 protected override void OnMouseCaptureChanged (EventArgs e)
851 base.OnMouseCaptureChanged (e);
854 protected override void OnMouseDown (MouseEventArgs mea)
856 if (mouse_currently_over != null)
858 ToolStripItem focused = GetCurrentlyFocusedItem ();
860 if (focused != null && focused != mouse_currently_over)
861 this.FocusInternal (true);
863 if (this is MenuStrip && !(mouse_currently_over as ToolStripMenuItem).HasDropDownItems) {
865 (this as MenuStrip).FireMenuActivate ();
870 mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseDown);
872 if (this is MenuStrip && !menu_selected) {
873 (this as MenuStrip).FireMenuActivate ();
874 menu_selected = true;
877 if (this is MenuStrip)
878 this.HideMenus (true, ToolStripDropDownCloseReason.AppClicked);
881 if (this is MenuStrip)
882 this.Capture = false;
884 base.OnMouseDown (mea);
887 protected override void OnMouseLeave (EventArgs e)
889 if (mouse_currently_over != null) {
890 MouseLeftItem (mouse_currently_over);
891 mouse_currently_over.FireEvent (e, ToolStripItemEventType.MouseLeave);
892 mouse_currently_over = null;
895 base.OnMouseLeave (e);
898 protected override void OnMouseMove (MouseEventArgs mea)
901 // Find the item we are now
902 if (this.overflow_button != null && this.overflow_button.Visible && this.overflow_button.Bounds.Contains (mea.Location))
903 tsi = this.overflow_button;
905 tsi = this.GetItemAt (mea.X, mea.Y);
908 // If we were already hovering on this item, just send a mouse move
909 if (tsi == mouse_currently_over)
910 tsi.FireEvent (mea, ToolStripItemEventType.MouseMove);
912 // If we were over a different item, fire a mouse leave on it
913 if (mouse_currently_over != null) {
915 mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseLeave);
918 // Set the new item we are currently over
919 mouse_currently_over = tsi;
921 // Fire mouse enter and mouse move
922 tsi.FireEvent (mea, ToolStripItemEventType.MouseEnter);
923 MouseEnteredItem (tsi);
924 tsi.FireEvent (mea, ToolStripItemEventType.MouseMove);
926 // If we're over something with a drop down, show it
927 if (menu_selected && mouse_currently_over.Enabled && mouse_currently_over is ToolStripDropDownItem && (mouse_currently_over as ToolStripDropDownItem).HasDropDownItems)
928 (mouse_currently_over as ToolStripDropDownItem).ShowDropDown ();
931 // We're not over anything now, just fire the mouse leave on what we used to be over
932 if (mouse_currently_over != null) {
934 mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseLeave);
935 mouse_currently_over = null;
939 base.OnMouseMove (mea);
942 protected override void OnMouseUp (MouseEventArgs mea)
944 // If we're currently over an item (set in MouseMove)
945 if (mouse_currently_over != null) {
946 // Fire our ItemClicked event
947 OnItemClicked (new ToolStripItemClickedEventArgs (mouse_currently_over));
949 // Fire the item's MouseUp event
950 mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseUp);
952 // The event handler may have blocked until the mouse moved off of the ToolStripItem
953 if (mouse_currently_over == null)
957 base.OnMouseUp (mea);
960 protected override void OnPaint (PaintEventArgs e)
965 this.OnPaintGrip (e);
967 // Make each item draw itself
968 foreach (ToolStripItem tsi in this.displayed_items) {
970 e.Graphics.TranslateTransform (tsi.Bounds.Left, tsi.Bounds.Top);
971 tsi.FireEvent (e, ToolStripItemEventType.Paint);
972 e.Graphics.ResetTransform ();
976 // Paint the Overflow button if it's visible
977 if (this.overflow_button != null && this.overflow_button.Visible) {
978 e.Graphics.TranslateTransform (this.overflow_button.Bounds.Left, this.overflow_button.Bounds.Top);
979 this.overflow_button.FireEvent (e, ToolStripItemEventType.Paint);
980 e.Graphics.ResetTransform ();
983 Rectangle affected_bounds = new Rectangle (Point.Empty, this.Size);
985 ToolStripRenderEventArgs pevent = new ToolStripRenderEventArgs (e.Graphics, this, affected_bounds, Color.Empty);
986 pevent.InternalConnectedArea = CalculateConnectedArea ();
988 this.Renderer.DrawToolStripBorder (pevent);
991 [EditorBrowsable (EditorBrowsableState.Advanced)]
992 protected override void OnPaintBackground (PaintEventArgs pevent)
994 base.OnPaintBackground (pevent);
996 Rectangle affected_bounds = new Rectangle (Point.Empty, this.Size);
997 ToolStripRenderEventArgs e = new ToolStripRenderEventArgs (pevent.Graphics, this, affected_bounds, SystemColors.Control);
999 this.Renderer.DrawToolStripBackground (e);
1002 protected internal virtual void OnPaintGrip (PaintEventArgs e)
1004 // Never draw a grip with these two layouts
1005 if (this.layout_style == ToolStripLayoutStyle.Flow || this.layout_style == ToolStripLayoutStyle.Table)
1008 PaintEventHandler eh = (PaintEventHandler)(Events [PaintGripEvent]);
1012 if (!(this is MenuStrip)) {
1013 if (this.orientation == Orientation.Horizontal)
1014 e.Graphics.TranslateTransform (2, 0);
1016 e.Graphics.TranslateTransform (0, 2);
1019 this.Renderer.DrawGrip (new ToolStripGripRenderEventArgs (e.Graphics, this, this.GripRectangle, this.GripDisplayStyle, this.grip_style));
1020 e.Graphics.ResetTransform ();
1023 protected virtual void OnRendererChanged (EventArgs e)
1025 EventHandler eh = (EventHandler)(Events [RendererChangedEvent]);
1030 [EditorBrowsable (EditorBrowsableState.Advanced)]
1031 protected override void OnRightToLeftChanged (EventArgs e)
1033 base.OnRightToLeftChanged (e);
1035 foreach (ToolStripItem tsi in this.Items)
1036 tsi.OnParentRightToLeftChanged (e);
1039 protected override void OnScroll (ScrollEventArgs se)
1044 protected override void OnTabStopChanged (EventArgs e)
1046 base.OnTabStopChanged (e);
1049 protected override void OnVisibleChanged (EventArgs e)
1051 base.OnVisibleChanged (e);
1054 protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
1056 return base.ProcessCmdKey (ref msg, keyData);
1059 protected override bool ProcessDialogKey (Keys keyData)
1061 if (!this.KeyboardActive)
1064 // Give each item a chance to handle the key
1065 foreach (ToolStripItem tsi in this.Items)
1066 if (tsi.ProcessDialogKey (keyData))
1069 // See if I want to handle it
1070 if (this.ProcessArrowKey (keyData))
1073 ToolStrip ts = null;
1077 this.Dismiss (ToolStripDropDownCloseReason.Keyboard);
1080 case Keys.Control | Keys.Tab:
1081 ts = ToolStripManager.GetNextToolStrip (this, true);
1084 foreach (ToolStripItem tsi in this.Items)
1085 tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
1087 ToolStripManager.SetActiveToolStrip (ts, true);
1088 ts.SelectNextToolStripItem (null, true);
1092 case Keys.Control | Keys.Shift | Keys.Tab:
1093 ts = ToolStripManager.GetNextToolStrip (this, false);
1096 foreach (ToolStripItem tsi in this.Items)
1097 tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
1099 ToolStripManager.SetActiveToolStrip (ts, true);
1100 ts.SelectNextToolStripItem (null, true);
1108 if (GetCurrentlySelectedItem () is ToolStripControlHost)
1113 return base.ProcessDialogKey (keyData);
1116 protected override bool ProcessMnemonic (char charCode)
1118 // If any item has an explicit mnemonic, it gets the message
1119 foreach (ToolStripItem tsi in this.Items)
1120 if (tsi.Enabled && tsi.Visible && !string.IsNullOrEmpty (tsi.Text) && Control.IsMnemonic (charCode, tsi.Text))
1121 return tsi.ProcessMnemonic (charCode);
1123 string code = Char.ToUpper (charCode).ToString ();
1125 // If any item's text starts with our letter, it gets the message
1126 if (this is MenuStrip)
1127 foreach (ToolStripItem tsi in this.Items)
1128 if (tsi.Enabled && tsi.Visible && !string.IsNullOrEmpty (tsi.Text) && tsi.Text.ToUpper ().StartsWith (code))
1129 return tsi.ProcessMnemonic (charCode);
1131 return base.ProcessMnemonic (charCode);
1135 [EditorBrowsable (EditorBrowsableState.Advanced)]
1136 protected virtual void RestoreFocus ()
1141 protected override void Select (bool directed, bool forward)
1143 base.Select (directed, forward);
1146 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
1148 base.SetBoundsCore (x, y, width, height, specified);
1151 protected virtual void SetDisplayedItems ()
1153 this.displayed_items.Clear ();
1155 foreach (ToolStripItem tsi in this.items)
1156 if (tsi.Placement == ToolStripItemPlacement.Main && tsi.Available) {
1157 this.displayed_items.AddNoOwnerOrLayout (tsi);
1160 else if (tsi.Placement == ToolStripItemPlacement.Overflow)
1161 tsi.Parent = this.OverflowButton.DropDown;
1163 if (this.OverflowButton != null)
1164 this.OverflowButton.DropDown.SetDisplayedItems ();
1167 protected internal void SetItemLocation (ToolStripItem item, Point location)
1170 throw new ArgumentNullException ("item");
1172 if (item.Owner != this)
1173 throw new NotSupportedException ("The item is not owned by this ToolStrip");
1175 item.SetBounds (new Rectangle (location, item.Size));
1178 protected internal static void SetItemParent (ToolStripItem item, ToolStrip parent)
1180 if (item.Owner != null) {
1181 item.Owner.Items.RemoveNoOwnerOrLayout (item);
1183 if (item.Owner is ToolStripOverflow)
1184 (item.Owner as ToolStripOverflow).ParentToolStrip.Items.RemoveNoOwnerOrLayout (item);
1187 parent.Items.AddNoOwnerOrLayout (item);
1188 item.Parent = parent;
1191 protected override void SetVisibleCore (bool value)
1193 base.SetVisibleCore (value);
1196 protected override void WndProc (ref Message m)
1198 base.WndProc (ref m);
1202 #region Public Events
1203 static object BeginDragEvent = new object ();
1204 static object EndDragEvent = new object ();
1205 static object ItemAddedEvent = new object ();
1206 static object ItemClickedEvent = new object ();
1207 static object ItemRemovedEvent = new object ();
1208 static object LayoutCompletedEvent = new object ();
1209 static object LayoutStyleChangedEvent = new object ();
1210 static object PaintGripEvent = new object ();
1211 static object RendererChangedEvent = new object ();
1214 [EditorBrowsable (EditorBrowsableState.Always)]
1215 public new event EventHandler AutoSizeChanged {
1216 add { base.AutoSizeChanged += value; }
1217 remove { base.AutoSizeChanged -= value; }
1221 public event EventHandler BeginDrag {
1222 add { Events.AddHandler (BeginDragEvent, value); }
1223 remove { Events.RemoveHandler (BeginDragEvent, value); }
1227 public new event EventHandler CausesValidationChanged {
1228 add { base.CausesValidationChanged += value; }
1229 remove { base.CausesValidationChanged -= value; }
1233 [EditorBrowsable (EditorBrowsableState.Never)]
1234 public new event ControlEventHandler ControlAdded {
1235 add { base.ControlAdded += value; }
1236 remove { base.ControlAdded -= value; }
1240 [EditorBrowsable (EditorBrowsableState.Never)]
1241 public new event ControlEventHandler ControlRemoved {
1242 add { base.ControlRemoved += value; }
1243 remove { base.ControlRemoved -= value; }
1247 public new event EventHandler CursorChanged {
1248 add { base.CursorChanged += value; }
1249 remove { base.CursorChanged -= value; }
1253 public event EventHandler EndDrag {
1254 add { Events.AddHandler (EndDragEvent, value); }
1255 remove { Events.RemoveHandler (EndDragEvent, value); }
1259 public new event EventHandler ForeColorChanged {
1260 add { base.ForeColorChanged += value; }
1261 remove { base.ForeColorChanged -= value; }
1264 public event ToolStripItemEventHandler ItemAdded {
1265 add { Events.AddHandler (ItemAddedEvent, value); }
1266 remove { Events.RemoveHandler (ItemAddedEvent, value); }
1269 public event ToolStripItemClickedEventHandler ItemClicked {
1270 add { Events.AddHandler (ItemClickedEvent, value); }
1271 remove { Events.RemoveHandler (ItemClickedEvent, value); }
1274 public event ToolStripItemEventHandler ItemRemoved {
1275 add { Events.AddHandler (ItemRemovedEvent, value); }
1276 remove { Events.RemoveHandler (ItemRemovedEvent, value); }
1279 public event EventHandler LayoutCompleted {
1280 add { Events.AddHandler (LayoutCompletedEvent, value); }
1281 remove { Events.RemoveHandler (LayoutCompletedEvent, value); }
1284 public event EventHandler LayoutStyleChanged {
1285 add { Events.AddHandler (LayoutStyleChangedEvent, value); }
1286 remove { Events.RemoveHandler (LayoutStyleChangedEvent, value); }
1289 public event PaintEventHandler PaintGrip {
1290 add { Events.AddHandler (PaintGripEvent, value); }
1291 remove { Events.RemoveHandler (PaintGripEvent, value); }
1294 public event EventHandler RendererChanged {
1295 add { Events.AddHandler (RendererChangedEvent, value); }
1296 remove { Events.RemoveHandler (RendererChangedEvent, value); }
1300 #region Internal Properties
1301 internal virtual bool KeyboardActive
1303 get { return this.keyboard_active; }
1305 if (this.keyboard_active != value) {
1306 this.keyboard_active = value;
1309 Application.KeyboardCapture = this;
1310 else if (Application.KeyboardCapture == this) {
1311 Application.KeyboardCapture = null;
1312 ToolStripManager.ActivatedByKeyboard = false;
1315 // Redraw for mnemonic underlines
1322 #region Private Methods
1323 internal virtual Rectangle CalculateConnectedArea ()
1325 return Rectangle.Empty;
1328 internal void ChangeSelection (ToolStripItem nextItem)
1330 if (Application.KeyboardCapture != this)
1331 ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard);
1333 foreach (ToolStripItem tsi in this.Items)
1334 if (tsi != nextItem)
1335 tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
1337 ToolStripItem current = GetCurrentlySelectedItem ();
1339 if (!(current is ToolStripControlHost))
1340 this.FocusInternal (true);
1342 if (nextItem is ToolStripControlHost)
1343 (nextItem as ToolStripControlHost).Focus ();
1347 if (nextItem.Parent is MenuStrip && (nextItem.Parent as MenuStrip).MenuDroppedDown)
1348 (nextItem as ToolStripMenuItem).HandleAutoExpansion ();
1351 internal virtual void Dismiss ()
1353 this.Dismiss (ToolStripDropDownCloseReason.AppClicked);
1356 internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
1358 // Release our stranglehold on the keyboard
1359 this.KeyboardActive = false;
1361 // Set our drop down flag to false;
1362 this.menu_selected = false;
1364 // Make sure all of our items are deselected and repainted
1365 foreach (ToolStripItem tsi in this.Items)
1366 tsi.Dismiss (reason);
1368 // We probably need to redraw for mnemonic underlines
1372 private void DoAutoSize ()
1374 if (this.AutoSize == true && this.Dock == DockStyle.None) {
1375 Size new_size = GetToolStripPreferredSize (Size.Empty);
1376 SetBounds (Left, Top, new_size.Width, new_size.Height, BoundsSpecified.None);
1379 if (this.AutoSize == true && this.Orientation == Orientation.Horizontal && (this.Dock == DockStyle.Top || this.Dock == DockStyle.Bottom))
1380 SetBounds (Left, Top, Width, GetToolStripPreferredSize (Size.Empty).Height, BoundsSpecified.None);
1383 internal ToolStripItem GetCurrentlySelectedItem ()
1385 foreach (ToolStripItem tsi in this.DisplayedItems)
1392 internal ToolStripItem GetCurrentlyFocusedItem ()
1394 foreach (ToolStripItem tsi in this.DisplayedItems)
1395 if ((tsi is ToolStripControlHost) && (tsi as ToolStripControlHost).Control.Focused)
1401 internal virtual Size GetToolStripPreferredSize (Size proposedSize)
1403 Size new_size = new Size (0, this.Height);
1405 if (this.orientation == Orientation.Vertical) {
1406 foreach (ToolStripItem tsi in this.items)
1407 if (tsi.GetPreferredSize (Size.Empty).Height + tsi.Margin.Top + tsi.Margin.Bottom > new_size.Height)
1408 new_size.Height = tsi.GetPreferredSize (Size.Empty).Height + tsi.Margin.Top + tsi.Margin.Bottom;
1410 new_size.Height += this.Padding.Top + this.Padding.Bottom;
1411 new_size.Width = this.Width;
1413 foreach (ToolStripItem tsi in this.items)
1414 if (tsi.Available) {
1415 Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);
1416 new_size.Width += tsi_preferred.Width + tsi.Margin.Left + tsi.Margin.Right;
1418 if (new_size.Height < (this.Padding.Vertical + tsi_preferred.Height))
1419 new_size.Height = (this.Padding.Vertical + tsi_preferred.Height);
1423 new_size.Width += (this.GripRectangle.Width + this.GripMargin.Horizontal + this.Padding.Horizontal + 4);
1427 internal virtual ToolStrip GetTopLevelToolStrip ()
1432 internal virtual void HandleItemClick (ToolStripItem dismissingItem)
1434 this.GetTopLevelToolStrip ().Dismiss (ToolStripDropDownCloseReason.ItemClicked);
1437 internal void HideMenus (bool release, ToolStripDropDownCloseReason reason)
1439 if (this is MenuStrip && release && menu_selected)
1440 (this as MenuStrip).FireMenuDeactivate ();
1443 menu_selected = false;
1445 NotifySelectedChanged (null);
1448 internal void NotifySelectedChanged (ToolStripItem tsi)
1450 foreach (ToolStripItem tsi2 in this.DisplayedItems)
1452 if (tsi2 is ToolStripDropDownItem)
1453 (tsi2 as ToolStripDropDownItem).HideDropDown (ToolStripDropDownCloseReason.Keyboard);
1455 if (this.OverflowButton != null) {
1456 ToolStripItemCollection tsic = this.OverflowButton.DropDown.DisplayedItems;
1458 foreach (ToolStripItem tsi2 in tsic)
1460 if (tsi2 is ToolStripDropDownItem)
1461 (tsi2 as ToolStripDropDownItem).HideDropDown (ToolStripDropDownCloseReason.Keyboard);
1463 this.OverflowButton.HideDropDown ();
1466 foreach (ToolStripItem tsi2 in this.Items)
1468 tsi2.Dismiss (ToolStripDropDownCloseReason.Keyboard);
1471 internal virtual bool OnMenuKey ()
1476 internal virtual bool ProcessArrowKey (Keys keyData)
1482 tsi = this.GetCurrentlySelectedItem ();
1484 if (tsi is ToolStripControlHost)
1487 tsi = this.SelectNextToolStripItem (tsi, true);
1489 if (tsi is ToolStripControlHost)
1490 (tsi as ToolStripControlHost).Focus ();
1494 tsi = this.GetCurrentlySelectedItem ();
1496 tsi = this.SelectNextToolStripItem (tsi, true);
1498 if (tsi is ToolStripControlHost)
1499 (tsi as ToolStripControlHost).Focus ();
1503 tsi = this.GetCurrentlySelectedItem ();
1505 if (tsi is ToolStripControlHost)
1508 tsi = this.SelectNextToolStripItem (tsi, false);
1510 if (tsi is ToolStripControlHost)
1511 (tsi as ToolStripControlHost).Focus ();
1514 case Keys.Shift | Keys.Tab:
1515 tsi = this.GetCurrentlySelectedItem ();
1517 tsi = this.SelectNextToolStripItem (tsi, false);
1519 if (tsi is ToolStripControlHost)
1520 (tsi as ToolStripControlHost).Focus ();
1528 internal virtual ToolStripItem SelectNextToolStripItem (ToolStripItem start, bool forward)
1530 ToolStripItem next_item = this.GetNextItem (start, forward ? ArrowDirection.Right : ArrowDirection.Left);
1532 this.ChangeSelection (next_item);
1534 if (next_item is ToolStripControlHost)
1535 (next_item as ToolStripControlHost).Focus ();
1540 #region Stuff for ToolTips
1541 private void MouseEnteredItem (ToolStripItem item)
1543 if (this.show_item_tool_tips) {
1544 tooltip_currently_showing = item;
1545 ToolTipTimer.Start ();
1549 private void MouseLeftItem (ToolStripItem item)
1551 ToolTipTimer.Stop ();
1552 ToolTipWindow.Hide (this);
1553 tooltip_currently_showing = null;
1556 private Timer ToolTipTimer {
1558 if (tooltip_timer == null) {
1559 tooltip_timer = new Timer ();
1560 tooltip_timer.Enabled = false;
1561 tooltip_timer.Interval = 500;
1562 tooltip_timer.Tick += new EventHandler (ToolTipTimer_Tick);
1565 return tooltip_timer;
1569 private ToolTip ToolTipWindow {
1571 if (tooltip_window == null)
1572 tooltip_window = new ToolTip ();
1574 return tooltip_window;
1578 private void ToolTipTimer_Tick (object o, EventArgs args)
1580 string tooltip = tooltip_currently_showing.GetToolTip ();
1582 if (!string.IsNullOrEmpty (tooltip))
1583 ToolTipWindow.Present (this, tooltip);
1585 tooltip_currently_showing.FireEvent (EventArgs.Empty, ToolStripItemEventType.MouseHover);
1587 ToolTipTimer.Stop ();
1591 #region Stuff for Merging
1592 internal ToolStrip CurrentlyMergedWith {
1593 get { return this.currently_merged_with; }
1594 set { this.currently_merged_with = value; }
1597 internal List<ToolStripItem> HiddenMergedItems {
1599 if (this.hidden_merged_items == null)
1600 this.hidden_merged_items = new List<ToolStripItem> ();
1602 return this.hidden_merged_items;
1606 internal bool IsCurrentlyMerged {
1607 get { return this.is_currently_merged; }
1609 this.is_currently_merged = value;
1611 if (!value && this is MenuStrip)
1612 foreach (ToolStripMenuItem tsmi in this.Items)
1613 tsmi.DropDown.IsCurrentlyMerged = value;
1617 internal void BeginMerge ()
1619 if (!IsCurrentlyMerged) {
1620 IsCurrentlyMerged = true;
1622 if (this.pre_merge_items == null) {
1623 this.pre_merge_items = new List<ToolStripItem> ();
1625 foreach (ToolStripItem tsi in this.Items)
1626 this.pre_merge_items.Add (tsi);
1631 internal void RevertMergeItem (ToolStripItem item)
1635 // Remove it from it's current Parent
1636 if (item.Parent != null && item.Parent != this) {
1637 if (item.Parent is ToolStripOverflow)
1638 (item.Parent as ToolStripOverflow).ParentToolStrip.Items.RemoveNoOwnerOrLayout (item);
1640 item.Parent.Items.RemoveNoOwnerOrLayout (item);
1642 item.Parent = item.Owner;
1645 // Find where the item was before the merge
1646 index = item.Owner.pre_merge_items.IndexOf (item);
1648 // Find the first pre-merge item that was after this item, that
1649 // is currently in the Items collection. Insert our item before
1651 for (int i = index; i < this.pre_merge_items.Count; i++) {
1652 if (this.Items.Contains (this.pre_merge_items[i])) {
1653 item.Owner.Items.InsertNoOwnerOrLayout (this.Items.IndexOf (this.pre_merge_items[i]), item);
1658 // There aren't any items that are supposed to be after this item,
1659 // so just append it to the end.
1660 item.Owner.Items.AddNoOwnerOrLayout (item);
1665 #region ToolStripAccessibleObject
1667 public class ToolStripAccessibleObject : ControlAccessibleObject
1669 #region Public Constructor
1670 public ToolStripAccessibleObject (ToolStrip owner) : base (owner)
1675 #region Public Properties
1676 public override AccessibleRole Role {
1677 get { return AccessibleRole.ToolBar; }
1681 #region Public Methods
1682 public override AccessibleObject GetChild (int index)
1684 return base.GetChild (index);
1687 public override int GetChildCount ()
1689 return (owner as ToolStrip).Items.Count;
1692 public override AccessibleObject HitTest (int x, int y)
1694 return base.HitTest (x, y);