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)
32 using System.ComponentModel;
33 using System.Runtime.InteropServices;
35 namespace System.Windows.Forms
37 [DefaultEvent ("Click")]
38 [DefaultProperty ("Text")]
39 [DesignTimeVisible (false)]
41 [Designer ("System.Windows.Forms.Design.ToolStripItemDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 public abstract class ToolStripItem : Component, IDropTarget, IComponent, IDisposable
44 #region Private Variables
45 private AccessibleObject accessibility_object;
46 private string accessible_default_action_description;
47 private bool allow_drop;
48 private ToolStripItemAlignment alignment;
49 private AnchorStyles anchor;
50 private bool available;
51 private bool auto_size;
52 private bool auto_tool_tip;
53 private Color back_color;
54 private Image background_image;
55 private ImageLayout background_image_layout;
56 private Rectangle bounds;
57 private bool can_select;
58 private ToolStripItemDisplayStyle display_style;
59 private DockStyle dock;
60 private bool double_click_enabled;
62 private Size explicit_size;
64 private Color fore_color;
66 private ContentAlignment image_align;
67 private int image_index;
68 private string image_key;
69 private ToolStripItemImageScaling image_scaling;
70 private Color image_transparent_color;
71 private bool is_disposed;
72 internal bool is_pressed;
73 private bool is_selected;
74 private Padding margin;
75 private MergeAction merge_action;
76 private int merge_index;
78 private ToolStripItemOverflow overflow;
79 private ToolStrip owner;
80 internal ToolStripItem owner_item;
81 private Padding padding;
82 private ToolStripItemPlacement placement;
83 private RightToLeft right_to_left;
84 private bool right_to_left_auto_mirror_image;
87 private ContentAlignment text_align;
88 private ToolStripTextDirection text_direction;
89 private TextImageRelation text_image_relation;
90 private string tool_tip_text;
93 private EventHandler frame_handler; // For animating images
94 private ToolStrip parent;
95 private Size text_size;
98 #region Public Constructors
99 protected ToolStripItem ()
100 : this (String.Empty, null, null, String.Empty)
104 protected ToolStripItem (string text, Image image, EventHandler onClick)
105 : this (text, image, onClick, String.Empty)
109 protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
111 this.alignment = ToolStripItemAlignment.Left;
112 this.anchor = AnchorStyles.Left | AnchorStyles.Top;
113 this.auto_size = true;
114 this.auto_tool_tip = this.DefaultAutoToolTip;
115 this.available = true;
116 this.back_color = Control.DefaultBackColor;
117 this.background_image_layout = ImageLayout.Tile;
118 this.can_select = true;
119 this.display_style = this.DefaultDisplayStyle;
120 this.dock = DockStyle.None;
122 this.font = new Font ("Tahoma", 8.25f);
123 this.fore_color = Control.DefaultForeColor;
125 this.image_align = ContentAlignment.MiddleCenter;
126 this.image_index = -1;
127 this.image_key = string.Empty;
128 this.image_scaling = ToolStripItemImageScaling.SizeToFit;
129 this.image_transparent_color = Color.Empty;
130 this.margin = this.DefaultMargin;
131 this.merge_action = MergeAction.Append;
132 this.merge_index = -1;
134 this.overflow = ToolStripItemOverflow.AsNeeded;
135 this.padding = this.DefaultPadding;
136 this.placement = ToolStripItemPlacement.None;
137 this.right_to_left = RightToLeft.Inherit;
138 this.bounds.Size = this.DefaultSize;
140 this.text_align = ContentAlignment.MiddleCenter;
141 this.text_direction = DefaultTextDirection;
142 this.text_image_relation = TextImageRelation.ImageBeforeText;
145 this.Click += onClick;
146 OnLayout (new LayoutEventArgs (null, string.Empty));
150 #region Public Properties
152 [EditorBrowsable (EditorBrowsableState.Advanced)]
153 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
154 public AccessibleObject AccessibilityObject {
156 if (this.accessibility_object == null)
157 this.accessibility_object = CreateAccessibilityInstance ();
159 return this.accessibility_object;
164 [EditorBrowsable (EditorBrowsableState.Advanced)]
165 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
166 public string AccessibleDefaultActionDescription {
168 if (this.accessibility_object == null)
171 return this.accessible_default_action_description;
173 set { this.accessible_default_action_description = value; }
177 [DefaultValue (null)]
178 public string AccessibleDescription {
180 if (this.accessibility_object == null)
183 return this.AccessibilityObject.Description;
185 set { this.AccessibilityObject.description = value; }
189 [DefaultValue (null)]
190 public string AccessibleName {
192 if (this.accessibility_object == null)
195 return this.AccessibilityObject.Name;
197 set { this.AccessibilityObject.Name = value; }
200 [DefaultValue (AccessibleRole.Default)]
201 public AccessibleRole AccessibleRole {
204 if (this.accessibility_object == null)
205 return AccessibleRole.Default;
207 return this.AccessibilityObject.Role;
209 set { this.AccessibilityObject.role = value; }
212 [DefaultValue (ToolStripItemAlignment.Left)]
213 public ToolStripItemAlignment Alignment {
214 get { return this.alignment; }
216 if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
217 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
219 this.alignment = value;
225 [DefaultValue (false)]
226 [EditorBrowsable (EditorBrowsableState.Advanced)]
227 public virtual bool AllowDrop {
228 get { return this.allow_drop; }
229 set { this.allow_drop = value; }
233 [DefaultValue (AnchorStyles.Top | AnchorStyles.Left)]
234 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
235 public AnchorStyles Anchor {
236 get { return this.anchor; }
237 set { this.anchor = value; }
241 [DefaultValue (true)]
242 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
243 [RefreshProperties (RefreshProperties.All)]
244 public bool AutoSize {
245 get { return this.auto_size; }
247 this.auto_size = value;
248 this.CalculateAutoSize ();
252 [DefaultValue (false)]
253 public bool AutoToolTip {
254 get { return this.auto_tool_tip; }
255 set { this.auto_tool_tip = value; }
259 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
260 public bool Available {
261 get { return this.available; }
263 if (this.available != value) {
267 if (this.parent != null)
268 parent.PerformLayout ();
270 OnAvailableChanged (EventArgs.Empty);
271 OnVisibleChanged (EventArgs.Empty);
276 public virtual Color BackColor {
277 get { return this.back_color; }
279 if (this.back_color != value) {
281 OnBackColorChanged (EventArgs.Empty);
288 [DefaultValue (null)]
289 public virtual Image BackgroundImage {
290 get { return this.background_image; }
292 if (this.background_image != value) {
293 this.background_image = value;
300 [DefaultValue (ImageLayout.Tile)]
301 public virtual ImageLayout BackgroundImageLayout {
302 get { return this.background_image_layout; }
304 if (this.background_image_layout != value) {
305 this.background_image_layout = value;
312 public virtual Rectangle Bounds {
313 get { return this.bounds; }
317 public virtual bool CanSelect {
318 get { return this.can_select; }
322 public Rectangle ContentRectangle {
324 // ToolStripLabels don't have a border
325 if (this is ToolStripLabel || this is ToolStripStatusLabel)
326 return new Rectangle (0, 0, this.bounds.Width, this.bounds.Height);
328 if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
329 return new Rectangle (2, 2, this.bounds.Width - 13, this.bounds.Height - 4);
331 return new Rectangle (2, 2, this.bounds.Width - 4, this.bounds.Height - 4);
335 public virtual ToolStripItemDisplayStyle DisplayStyle {
336 get { return this.display_style; }
338 if (this.display_style != value) {
339 this.display_style = value;
340 this.CalculateAutoSize ();
341 OnDisplayStyleChanged (EventArgs.Empty);
342 if (this.Parent != null)
343 this.Parent.PerformLayout ();
349 public bool IsDisposed {
350 get { return this.is_disposed; }
354 [DefaultValue (DockStyle.None)]
355 public DockStyle Dock {
356 get { return this.dock; }
358 if (this.dock != value) {
359 if (!Enum.IsDefined (typeof (DockStyle), value))
360 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for DockStyle", value));
363 this.CalculateAutoSize ();
368 [DefaultValue (false)]
369 public bool DoubleClickEnabled {
370 get { return this.double_click_enabled; }
371 set { this.double_click_enabled = value; }
375 [DefaultValue (true)]
376 public virtual bool Enabled {
389 if (this.enabled != value) {
390 this.enabled = value;
391 OnEnabledChanged (EventArgs.Empty);
398 public virtual Font Font
400 get { return this.font; }
402 if (this.font != value) {
404 this.CalculateAutoSize ();
405 this.OnFontChanged (EventArgs.Empty);
411 public virtual Color ForeColor {
412 get { return this.fore_color; }
414 if (this.fore_color != value) {
415 this.fore_color = value;
416 this.OnForeColorChanged (EventArgs.Empty);
423 [EditorBrowsable (EditorBrowsableState.Always)]
424 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
426 get { return this.Size.Height; }
428 this.Size = new Size (this.Size.Width, value);
429 this.explicit_size.Height = value;
432 this.CalculateAutoSize ();
433 this.OnBoundsChanged ();
440 public virtual Image Image {
442 if (this.image != null)
445 if (this.image_index >= 0)
446 if (this.owner != null && this.owner.ImageList != null)
447 return this.owner.ImageList.Images[this.image_index];
450 if (!string.IsNullOrEmpty (this.image_key))
451 if (this.owner != null && this.owner.ImageList != null)
452 return this.owner.ImageList.Images[this.image_key];
457 if (this.image != value) {
461 this.image_index = -1;
462 this.image_key = string.Empty;
463 this.CalculateAutoSize ();
472 [DefaultValue (ContentAlignment.MiddleCenter)]
473 public ContentAlignment ImageAlign {
474 get { return this.image_align; }
476 if (!Enum.IsDefined (typeof (ContentAlignment), value))
477 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
479 this.image_align = value;
486 [RelatedImageList ("Owner.ImageList")]
487 [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
488 [RefreshProperties (RefreshProperties.Repaint)]
489 [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
490 public int ImageIndex {
491 get { return this.image_index; }
493 if (this.image_index != value) {
494 // Lamespec: MSDN says ArgumentException, tests say otherwise
496 throw new ArgumentOutOfRangeException ("ImageIndex cannot be less than -1");
498 this.image_index = value;
500 this.image_key = string.Empty;
501 this.CalculateAutoSize ();
509 [RelatedImageList ("Owner.ImageList")]
510 [TypeConverter (typeof (ImageKeyConverter))]
511 [RefreshProperties (RefreshProperties.Repaint)]
512 [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
513 public string ImageKey {
514 get { return this.image_key; }
516 if (this.image_key != value) {
518 this.image_index = -1;
519 this.image_key = value;
520 this.CalculateAutoSize ();
527 [DefaultValue (ToolStripItemImageScaling.SizeToFit)]
528 public ToolStripItemImageScaling ImageScaling {
529 get { return this.image_scaling; }
531 this.image_scaling = value;
532 this.CalculateAutoSize ();
538 public Color ImageTransparentColor {
539 get { return this.image_transparent_color; }
540 set { this.image_transparent_color = value; }
544 public bool IsOnDropDown {
546 if (this.parent != null && this.parent is ToolStripDropDown)
554 public bool IsOnOverflow {
555 get { return this.placement == ToolStripItemPlacement.Overflow; }
558 public Padding Margin {
559 get { return this.margin; }
562 this.CalculateAutoSize ();
566 [DefaultValue (MergeAction.Append)]
567 public MergeAction MergeAction {
568 get { return this.merge_action; }
570 if (!Enum.IsDefined (typeof (MergeAction), value))
571 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for MergeAction", value));
573 this.merge_action = value;
578 public int MergeIndex {
579 get { return this.merge_index; }
580 set { this.merge_index = value; }
583 [DefaultValue (null)]
586 get { return this.name; }
587 set { this.name = value; }
590 [DefaultValue (ToolStripItemOverflow.AsNeeded)]
591 public ToolStripItemOverflow Overflow {
592 get { return this.overflow; }
594 if (this.overflow != value) {
595 if (!Enum.IsDefined (typeof (ToolStripItemOverflow), value))
596 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemOverflow", value));
598 this.overflow = value;
601 owner.PerformLayout ();
607 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
608 public ToolStrip Owner {
609 get { return this.owner; }
611 if (this.owner != value) {
613 this.CalculateAutoSize ();
614 OnOwnerChanged (EventArgs.Empty);
620 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
621 public ToolStripItem OwnerItem {
622 get { return this.owner_item; }
625 public virtual Padding Padding {
626 get { return this.padding; }
628 this.padding = value;
629 this.CalculateAutoSize ();
635 public ToolStripItemPlacement Placement {
636 get { return this.placement; }
640 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
641 public virtual bool Pressed { get { return this.is_pressed; } }
643 [MonoTODO ("Stub, not implemented")]
645 public virtual RightToLeft RightToLeft {
646 get { return this.right_to_left; }
648 if (this.right_to_left != value) {
649 this.right_to_left = value;
650 this.OnRightToLeftChanged (EventArgs.Empty);
656 [DefaultValue (false)]
657 public bool RightToLeftAutoMirrorImage {
658 get { return this.right_to_left_auto_mirror_image; }
660 if (this.right_to_left_auto_mirror_image != value) {
661 this.right_to_left_auto_mirror_image = value;
668 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
669 public virtual bool Selected { get { return this.is_selected; } }
672 public virtual Size Size {
674 if (!this.AutoSize && this.explicit_size != Size.Empty)
675 return this.explicit_size;
677 return this.bounds.Size;
680 this.bounds.Size = value;
681 this.explicit_size = value;
684 this.CalculateAutoSize ();
685 this.OnBoundsChanged ();
690 [Localizable (false)]
692 [DefaultValue (null)]
693 [TypeConverter (typeof (StringConverter))]
695 get { return this.tag; }
696 set { this.tag = value; }
701 public virtual string Text
703 get { return this.text; }
705 if (this.text != value) {
708 this.CalculateAutoSize ();
710 this.OnTextChanged (EventArgs.Empty);
716 [DefaultValue (ContentAlignment.MiddleCenter)]
717 public virtual ContentAlignment TextAlign {
718 get { return this.text_align; }
720 if (!Enum.IsDefined (typeof (ContentAlignment), value))
721 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
722 this.text_align = value;
727 public virtual ToolStripTextDirection TextDirection {
729 if (this.text_direction == ToolStripTextDirection.Inherit) {
730 if (this.Parent != null)
731 return this.Parent.TextDirection;
733 return ToolStripTextDirection.Horizontal;
736 return this.text_direction;
739 if (!Enum.IsDefined (typeof (ToolStripTextDirection), value))
740 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripTextDirection", value));
742 if (this.text_direction != value) {
743 this.text_direction = value;
744 this.CalculateAutoSize ();
751 [DefaultValue (TextImageRelation.ImageBeforeText)]
752 public TextImageRelation TextImageRelation {
753 get { return this.text_image_relation; }
755 this.text_image_relation = value;
756 this.CalculateAutoSize ();
762 [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
763 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
764 public string ToolTipText {
765 get { return this.tool_tip_text; }
766 set { this.tool_tip_text = value; }
770 public bool Visible {
772 if (this.parent == null)
775 return this.visible && this.parent.Visible;
778 if (this.visible != value) {
779 this.available = value;
780 this.SetVisibleCore (value);
781 if (this.Owner != null)
782 this.Owner.PerformLayout ();
788 [EditorBrowsable (EditorBrowsableState.Always)]
789 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
791 get { return this.Size.Width; }
793 this.Size = new Size (value, this.Size.Height);
794 this.explicit_size.Width = value;
797 this.CalculateAutoSize ();
798 this.OnBoundsChanged ();
805 #region Protected Properties
806 protected virtual bool DefaultAutoToolTip { get { return false; } }
807 protected virtual ToolStripItemDisplayStyle DefaultDisplayStyle { get { return ToolStripItemDisplayStyle.ImageAndText; } }
808 protected internal virtual Padding DefaultMargin { get { return new Padding (0, 1, 0, 2); } }
809 protected virtual Padding DefaultPadding { get { return new Padding (); } }
810 protected virtual Size DefaultSize { get { return new Size (23, 23); } }
811 protected internal virtual bool DismissWhenClicked { get { return true; } }
813 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
814 protected internal ToolStrip Parent {
815 get { return this.parent; }
817 if (this.parent != value) {
818 ToolStrip old_parent = this.parent;
820 OnParentChanged(old_parent, this.parent);
824 protected internal virtual bool ShowKeyboardCues { get { return false; } }
827 #region Public Methods
829 [EditorBrowsable (EditorBrowsableState.Advanced)]
830 public DragDropEffects DoDragDrop (Object data, DragDropEffects allowedEffects)
832 return allowedEffects;
835 public ToolStrip GetCurrentParent ()
840 public virtual Size GetPreferredSize (Size constrainingSize)
842 return this.CalculatePreferredSize (constrainingSize);
845 public void Invalidate ()
848 parent.Invalidate (this.bounds);
851 public void Invalidate (Rectangle r)
854 parent.Invalidate (r);
857 public void PerformClick ()
859 this.OnClick (EventArgs.Empty);
862 [EditorBrowsable (EditorBrowsableState.Never)]
863 public virtual void ResetBackColor () { this.BackColor = Control.DefaultBackColor; }
865 [EditorBrowsable (EditorBrowsableState.Never)]
866 public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
868 [EditorBrowsable (EditorBrowsableState.Never)]
869 public virtual void ResetFont () { this.font = new Font ("Tahoma", 8.25f); }
871 [EditorBrowsable (EditorBrowsableState.Never)]
872 public virtual void ResetForeColor () { this.ForeColor = Control.DefaultForeColor; }
874 [EditorBrowsable (EditorBrowsableState.Never)]
875 public virtual void ResetImage () { this.image = null; }
877 [EditorBrowsable (EditorBrowsableState.Never)]
878 public void ResetMargin () { this.margin = this.DefaultMargin; }
880 [EditorBrowsable (EditorBrowsableState.Never)]
881 public void ResetPadding () { this.padding = this.DefaultPadding; }
883 [EditorBrowsable (EditorBrowsableState.Never)]
884 public virtual void ResetRightToLeft () { this.right_to_left = RightToLeft.Inherit; }
886 [EditorBrowsable (EditorBrowsableState.Never)]
887 public virtual void ResetTextDirection () { this.TextDirection = this.DefaultTextDirection; }
889 public void Select ()
891 if (!this.is_selected && this.CanSelect) {
892 this.is_selected = true;
894 if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
895 (this as ToolStripControlHost).Focus ();
898 this.Parent.NotifySelectedChanged (this);
902 public override string ToString ()
908 #region Protected Methods
909 [EditorBrowsable (EditorBrowsableState.Advanced)]
910 protected virtual AccessibleObject CreateAccessibilityInstance ()
912 return new ToolStripItemAccessibleObject (this);
915 protected override void Dispose (bool disposing)
917 if (!is_disposed && disposing)
925 base.Dispose (disposing);
928 protected internal virtual bool IsInputChar (char charCode)
933 protected internal virtual bool IsInputKey (Keys keyData)
938 protected virtual void OnAvailableChanged (EventArgs e)
940 EventHandler eh = (EventHandler)(Events [AvailableChangedEvent]);
945 [EditorBrowsable (EditorBrowsableState.Advanced)]
946 protected virtual void OnBackColorChanged (EventArgs e)
948 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
953 protected virtual void OnBoundsChanged ()
955 OnLayout (new LayoutEventArgs(null, string.Empty));
958 protected virtual void OnClick (EventArgs e)
960 EventHandler eh = (EventHandler)(Events [ClickEvent]);
965 [EditorBrowsable (EditorBrowsableState.Advanced)]
966 protected virtual void OnDisplayStyleChanged (EventArgs e)
968 EventHandler eh = (EventHandler)(Events [DisplayStyleChangedEvent]);
973 protected virtual void OnDoubleClick (EventArgs e)
975 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
979 if (!double_click_enabled)
983 [EditorBrowsable (EditorBrowsableState.Advanced)]
984 protected virtual void OnDragDrop (DragEventArgs dragEvent)
986 DragEventHandler eh = (DragEventHandler)(Events[DragDropEvent]);
988 eh (this, dragEvent);
991 [EditorBrowsable (EditorBrowsableState.Advanced)]
992 protected virtual void OnDragEnter (DragEventArgs dragEvent)
994 DragEventHandler eh = (DragEventHandler)(Events[DragEnterEvent]);
996 eh (this, dragEvent);
999 [EditorBrowsable (EditorBrowsableState.Advanced)]
1000 protected virtual void OnDragLeave (EventArgs e)
1002 EventHandler eh = (EventHandler)(Events[DragLeaveEvent]);
1007 [EditorBrowsable (EditorBrowsableState.Advanced)]
1008 protected virtual void OnDragOver (DragEventArgs dragEvent)
1010 DragEventHandler eh = (DragEventHandler)(Events[DragOverEvent]);
1012 eh (this, dragEvent);
1015 protected virtual void OnEnabledChanged (EventArgs e)
1017 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
1022 [EditorBrowsable (EditorBrowsableState.Advanced)]
1023 protected virtual void OnFontChanged (EventArgs e)
1027 [EditorBrowsable (EditorBrowsableState.Advanced)]
1028 protected virtual void OnForeColorChanged (EventArgs e)
1030 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
1035 [EditorBrowsable (EditorBrowsableState.Advanced)]
1036 protected virtual void OnGiveFeedback (GiveFeedbackEventArgs giveFeedbackEvent)
1038 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events[GiveFeedbackEvent]);
1040 eh (this, giveFeedbackEvent);
1043 protected virtual void OnLayout (LayoutEventArgs e)
1047 protected virtual void OnLocationChanged (EventArgs e)
1049 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
1054 protected virtual void OnMouseDown (MouseEventArgs e)
1057 this.is_pressed = true;
1060 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
1066 protected virtual void OnMouseEnter (EventArgs e)
1070 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
1075 protected virtual void OnMouseHover (EventArgs e)
1078 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
1084 protected virtual void OnMouseLeave (EventArgs e)
1086 if (this.CanSelect) {
1087 this.is_selected = false;
1088 this.is_pressed = false;
1092 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
1097 protected virtual void OnMouseMove (MouseEventArgs mea)
1100 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
1106 protected virtual void OnMouseUp (MouseEventArgs e)
1109 this.is_pressed = false;
1112 if (this.IsOnDropDown)
1113 if (!(this is ToolStripDropDownItem) || !(this as ToolStripDropDownItem).HasDropDownItems || (this as ToolStripDropDownItem).DropDown.Visible == false) {
1114 if ((this.Parent as ToolStripDropDown).OwnerItem != null)
1115 ((this.Parent as ToolStripDropDown).OwnerItem as ToolStripDropDownItem).HideDropDown ();
1117 (this.Parent as ToolStripDropDown).Hide ();
1121 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
1127 protected virtual void OnOwnerChanged (EventArgs e)
1129 EventHandler eh = (EventHandler)(Events [OwnerChangedEvent]);
1134 [EditorBrowsable (EditorBrowsableState.Advanced)]
1135 protected internal virtual void OnOwnerFontChanged (EventArgs e)
1139 protected virtual void OnPaint (PaintEventArgs e)
1141 if (this.parent != null)
1142 this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
1144 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
1149 // This is never called.
1150 [EditorBrowsable (EditorBrowsableState.Advanced)]
1151 protected virtual void OnParentBackColorChanged (EventArgs e)
1155 protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
1157 if (oldParent != null)
1158 oldParent.PerformLayout ();
1160 if (newParent != null)
1161 newParent.PerformLayout ();
1164 protected internal virtual void OnParentEnabledChanged (EventArgs e)
1166 this.OnEnabledChanged (e);
1169 // This is never called.
1170 [EditorBrowsable (EditorBrowsableState.Advanced)]
1171 protected virtual void OnParentForeColorChanged (EventArgs e)
1175 [EditorBrowsable (EditorBrowsableState.Advanced)]
1176 protected internal virtual void OnParentRightToLeftChanged (EventArgs e)
1178 this.OnRightToLeftChanged (e);
1181 [EditorBrowsable (EditorBrowsableState.Advanced)]
1182 protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs queryContinueDragEvent)
1184 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events[QueryContinueDragEvent]);
1186 eh (this, queryContinueDragEvent);
1189 protected virtual void OnRightToLeftChanged (EventArgs e)
1191 EventHandler eh = (EventHandler)(Events[RightToLeftChangedEvent]);
1196 [EditorBrowsable (EditorBrowsableState.Advanced)]
1197 protected virtual void OnTextChanged (EventArgs e)
1199 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
1204 protected virtual void OnVisibleChanged (EventArgs e)
1206 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
1211 protected internal virtual bool ProcessCmdKey (ref Message m, Keys keyData)
1216 protected internal virtual bool ProcessDialogKey (Keys keyData)
1218 if (this.Selected && keyData == Keys.Enter) {
1219 this.FireEvent (EventArgs.Empty, ToolStripItemEventType.Click);
1226 // ProcessMnemonic will only be called if we are supposed to handle
1227 // it. None of that fancy "thinking" needed!
1228 protected internal virtual bool ProcessMnemonic (char charCode)
1230 ToolStripManager.SetActiveToolStrip (this.Parent, true);
1231 this.PerformClick ();
1235 protected internal virtual void SetBounds (Rectangle bounds)
1237 if (this.bounds != bounds) {
1238 this.bounds = bounds;
1243 protected virtual void SetVisibleCore (bool visible)
1245 this.visible = visible;
1246 this.OnVisibleChanged (EventArgs.Empty);
1256 #region Public Events
1257 static object AvailableChangedEvent = new object ();
1258 static object BackColorChangedEvent = new object ();
1259 static object ClickEvent = new object ();
1260 static object DisplayStyleChangedEvent = new object ();
1261 static object DoubleClickEvent = new object ();
1262 static object DragDropEvent = new object ();
1263 static object DragEnterEvent = new object ();
1264 static object DragLeaveEvent = new object ();
1265 static object DragOverEvent = new object ();
1266 static object EnabledChangedEvent = new object ();
1267 static object ForeColorChangedEvent = new object ();
1268 static object GiveFeedbackEvent = new object ();
1269 static object LocationChangedEvent = new object ();
1270 static object MouseDownEvent = new object ();
1271 static object MouseEnterEvent = new object ();
1272 static object MouseHoverEvent = new object ();
1273 static object MouseLeaveEvent = new object ();
1274 static object MouseMoveEvent = new object ();
1275 static object MouseUpEvent = new object ();
1276 static object OwnerChangedEvent = new object ();
1277 static object PaintEvent = new object ();
1278 static object QueryAccessibilityHelpEvent = new object ();
1279 static object QueryContinueDragEvent = new object ();
1280 static object RightToLeftChangedEvent = new object ();
1281 static object TextChangedEvent = new object ();
1282 static object VisibleChangedEvent = new object ();
1285 public event EventHandler AvailableChanged {
1286 add { Events.AddHandler (AvailableChangedEvent, value); }
1287 remove {Events.RemoveHandler (AvailableChangedEvent, value); }
1290 public event EventHandler BackColorChanged {
1291 add { Events.AddHandler (BackColorChangedEvent, value); }
1292 remove {Events.RemoveHandler (BackColorChangedEvent, value); }
1295 public event EventHandler Click {
1296 add { Events.AddHandler (ClickEvent, value); }
1297 remove {Events.RemoveHandler (ClickEvent, value); }
1300 public event EventHandler DisplayStyleChanged {
1301 add { Events.AddHandler (DisplayStyleChangedEvent, value); }
1302 remove {Events.RemoveHandler (DisplayStyleChangedEvent, value); }
1305 public event EventHandler DoubleClick {
1306 add { Events.AddHandler (DoubleClickEvent, value); }
1307 remove {Events.RemoveHandler (DoubleClickEvent, value); }
1310 [MonoTODO ("Not raised")]
1312 [EditorBrowsable (EditorBrowsableState.Advanced)]
1313 public event DragEventHandler DragDrop {
1314 add { Events.AddHandler (DragDropEvent, value); }
1315 remove { Events.RemoveHandler (DragDropEvent, value); }
1318 [MonoTODO ("Not raised")]
1320 [EditorBrowsable (EditorBrowsableState.Advanced)]
1321 public event DragEventHandler DragEnter {
1322 add { Events.AddHandler (DragEnterEvent, value); }
1323 remove { Events.RemoveHandler (DragEnterEvent, value); }
1326 [MonoTODO ("Not raised")]
1328 [EditorBrowsable (EditorBrowsableState.Advanced)]
1329 public event EventHandler DragLeave {
1330 add { Events.AddHandler (DragLeaveEvent, value); }
1331 remove { Events.RemoveHandler (DragLeaveEvent, value); }
1334 [MonoTODO ("Not raised")]
1336 [EditorBrowsable (EditorBrowsableState.Advanced)]
1337 public event DragEventHandler DragOver {
1338 add { Events.AddHandler (DragOverEvent, value); }
1339 remove { Events.RemoveHandler (DragOverEvent, value); }
1342 public event EventHandler EnabledChanged {
1343 add { Events.AddHandler (EnabledChangedEvent, value); }
1344 remove {Events.RemoveHandler (EnabledChangedEvent, value); }
1347 public event EventHandler ForeColorChanged {
1348 add { Events.AddHandler (ForeColorChangedEvent, value); }
1349 remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
1352 [MonoTODO ("Not raised")]
1354 [EditorBrowsable (EditorBrowsableState.Advanced)]
1355 public event GiveFeedbackEventHandler GiveFeedback {
1356 add { Events.AddHandler (GiveFeedbackEvent, value); }
1357 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
1360 public event EventHandler LocationChanged {
1361 add { Events.AddHandler (LocationChangedEvent, value); }
1362 remove {Events.RemoveHandler (LocationChangedEvent, value); }
1365 public event MouseEventHandler MouseDown {
1366 add { Events.AddHandler (MouseDownEvent, value); }
1367 remove {Events.RemoveHandler (MouseDownEvent, value); }
1370 public event EventHandler MouseEnter {
1371 add { Events.AddHandler (MouseEnterEvent, value); }
1372 remove {Events.RemoveHandler (MouseEnterEvent, value); }
1375 public event EventHandler MouseHover {
1376 add { Events.AddHandler (MouseHoverEvent, value); }
1377 remove {Events.RemoveHandler (MouseHoverEvent, value); }
1380 public event EventHandler MouseLeave {
1381 add { Events.AddHandler (MouseLeaveEvent, value); }
1382 remove {Events.RemoveHandler (MouseLeaveEvent, value); }
1385 public event MouseEventHandler MouseMove {
1386 add { Events.AddHandler (MouseMoveEvent, value); }
1387 remove {Events.RemoveHandler (MouseMoveEvent, value); }
1390 public event MouseEventHandler MouseUp {
1391 add { Events.AddHandler (MouseUpEvent, value); }
1392 remove {Events.RemoveHandler (MouseUpEvent, value); }
1395 public event EventHandler OwnerChanged {
1396 add { Events.AddHandler (OwnerChangedEvent, value); }
1397 remove {Events.RemoveHandler (OwnerChangedEvent, value); }
1400 public event PaintEventHandler Paint {
1401 add { Events.AddHandler (PaintEvent, value); }
1402 remove {Events.RemoveHandler (PaintEvent, value); }
1405 [MonoTODO ("Not raised")]
1406 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
1407 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
1408 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
1411 [MonoTODO ("Not raised")]
1413 [EditorBrowsable (EditorBrowsableState.Advanced)]
1414 public event QueryContinueDragEventHandler QueryContinueDrag {
1415 add { Events.AddHandler (QueryContinueDragEvent, value); }
1416 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
1419 public event EventHandler RightToLeftChanged {
1420 add { Events.AddHandler (RightToLeftChangedEvent, value); }
1421 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
1424 public event EventHandler TextChanged {
1425 add { Events.AddHandler (TextChangedEvent, value); }
1426 remove {Events.RemoveHandler (TextChangedEvent, value); }
1429 public event EventHandler VisibleChanged {
1430 add { Events.AddHandler (VisibleChangedEvent, value); }
1431 remove {Events.RemoveHandler (VisibleChangedEvent, value); }
1435 #region Internal Methods
1436 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, ContentAlignment align)
1441 if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft)
1443 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter)
1444 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
1445 else if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight)
1446 x = outer.Right - inner.Width;
1447 if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight)
1449 else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight)
1450 y = outer.Y + (outer.Height - inner.Height) / 2;
1451 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomRight || align == ContentAlignment.BottomLeft)
1452 y = outer.Bottom - inner.Height;
1454 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
1457 internal void CalculateAutoSize ()
1459 this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty: this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
1461 // If our text is rotated, flip the width and height
1462 ToolStripTextDirection direction = this.TextDirection;
1464 if (direction == ToolStripTextDirection.Vertical270 || direction == ToolStripTextDirection.Vertical90)
1465 this.text_size = new Size (this.text_size.Height, this.text_size.Width);
1467 if (!this.auto_size || this is ToolStripControlHost)
1469 //this.text_size.Width += 6;
1471 Size final_size = this.CalculatePreferredSize (Size.Empty);
1473 if (final_size != this.Size) {
1474 this.bounds.Width = final_size.Width;
1475 if (this.parent != null)
1476 this.parent.PerformLayout ();
1480 internal virtual Size CalculatePreferredSize (Size constrainingSize)
1482 if (!this.auto_size)
1483 return this.explicit_size;
1485 Size preferred_size = this.DefaultSize;
1487 switch (this.display_style) {
1488 case ToolStripItemDisplayStyle.Text:
1489 int width = text_size.Width + this.padding.Horizontal;
1490 int height = text_size.Height + this.padding.Vertical;
1491 preferred_size = new Size (width, height);
1493 case ToolStripItemDisplayStyle.Image:
1494 if (this.Image == null)
1495 preferred_size = this.DefaultSize;
1497 switch (this.image_scaling) {
1498 case ToolStripItemImageScaling.None:
1499 preferred_size = this.Image.Size;
1501 case ToolStripItemImageScaling.SizeToFit:
1502 if (this.parent == null)
1503 preferred_size = this.Image.Size;
1505 preferred_size = this.parent.ImageScalingSize;
1510 case ToolStripItemDisplayStyle.ImageAndText:
1511 int width2 = text_size.Width + this.padding.Horizontal;
1512 int height2 = text_size.Height + this.padding.Vertical;
1514 if (this.Image != null) {
1515 Size image_size = this.Image.Size;
1517 if (this.image_scaling == ToolStripItemImageScaling.SizeToFit && this.parent != null)
1518 image_size = this.parent.ImageScalingSize;
1520 switch (this.text_image_relation) {
1521 case TextImageRelation.Overlay:
1522 width2 = Math.Max (width2, image_size.Width);
1523 height2 = Math.Max (height2, image_size.Height);
1525 case TextImageRelation.ImageAboveText:
1526 case TextImageRelation.TextAboveImage:
1527 width2 = Math.Max (width2, image_size.Width);
1528 height2 += image_size.Height;
1530 case TextImageRelation.ImageBeforeText:
1531 case TextImageRelation.TextBeforeImage:
1532 height2 = Math.Max (height2, image_size.Height);
1533 width2 += image_size.Width;
1538 preferred_size = new Size (width2, height2);
1542 if (!(this is ToolStripLabel)) { // Everything but labels have a border
1543 preferred_size.Height += 4;
1544 preferred_size.Width += 4;
1547 // Account for ToolStripDropDownButton's drop down arrow
1548 if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
1549 preferred_size.Width += 9;
1551 return preferred_size;
1554 internal void CalculateTextAndImageRectangles (out Rectangle text_rect, out Rectangle image_rect)
1556 this.CalculateTextAndImageRectangles (this.ContentRectangle, out text_rect, out image_rect);
1559 internal void CalculateTextAndImageRectangles (Rectangle contentRectangle, out Rectangle text_rect, out Rectangle image_rect)
1561 text_rect = Rectangle.Empty;
1562 image_rect = Rectangle.Empty;
1564 switch (this.display_style) {
1565 case ToolStripItemDisplayStyle.None:
1567 case ToolStripItemDisplayStyle.Text:
1568 if (this.text != string.Empty)
1569 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1571 case ToolStripItemDisplayStyle.Image:
1572 if (this.Image != null && this.UseImageMargin)
1573 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1575 case ToolStripItemDisplayStyle.ImageAndText:
1576 if (this.text != string.Empty && (this.Image == null || !this.UseImageMargin))
1577 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1578 else if (this.text == string.Empty && (this.Image == null || !this.UseImageMargin))
1580 else if (this.text == string.Empty && this.Image != null)
1581 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1583 Rectangle text_area;
1584 Rectangle image_area;
1586 switch (this.text_image_relation) {
1587 case TextImageRelation.Overlay:
1588 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1589 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1591 case TextImageRelation.ImageAboveText:
1592 text_area = new Rectangle (contentRectangle.Left, contentRectangle.Bottom - (text_size.Height - 4), contentRectangle.Width, text_size.Height - 4);
1593 image_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, contentRectangle.Height - text_area.Height);
1595 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1596 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1598 case TextImageRelation.TextAboveImage:
1599 text_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, text_size.Height - 4);
1600 image_area = new Rectangle (contentRectangle.Left, text_area.Bottom, contentRectangle.Width, contentRectangle.Height - text_area.Height);
1602 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1603 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1605 case TextImageRelation.ImageBeforeText:
1606 LayoutTextBeforeOrAfterImage (contentRectangle, false, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1608 case TextImageRelation.TextBeforeImage:
1609 LayoutTextBeforeOrAfterImage (contentRectangle, true, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1617 internal virtual ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Inherit; } }
1619 internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
1622 this.is_selected = false;
1627 internal virtual ToolStrip GetTopLevelToolStrip ()
1629 if (this.Parent != null)
1630 return this.Parent.GetTopLevelToolStrip ();
1635 private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, ContentAlignment textAlign, ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
1637 int element_spacing = 0; // Spacing between the Text and the Image
1638 int total_width = textSize.Width + element_spacing + imageSize.Width;
1639 int excess_width = totalArea.Width - total_width;
1642 Rectangle final_text_rect;
1643 Rectangle final_image_rect;
1645 HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
1646 HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
1648 if (h_image == HorizontalAlignment.Left)
1650 else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
1651 offset = excess_width;
1652 else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
1653 offset += (int)(excess_width / 3);
1655 offset += (int)(2 * (excess_width / 3));
1658 final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
1659 final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
1661 final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
1662 final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
1665 textRect = final_text_rect;
1666 imageRect = final_image_rect;
1669 private HorizontalAlignment GetHorizontalAlignment (ContentAlignment align)
1672 case ContentAlignment.BottomLeft:
1673 case ContentAlignment.MiddleLeft:
1674 case ContentAlignment.TopLeft:
1675 return HorizontalAlignment.Left;
1676 case ContentAlignment.BottomCenter:
1677 case ContentAlignment.MiddleCenter:
1678 case ContentAlignment.TopCenter:
1679 return HorizontalAlignment.Center;
1680 case ContentAlignment.BottomRight:
1681 case ContentAlignment.MiddleRight:
1682 case ContentAlignment.TopRight:
1683 return HorizontalAlignment.Right;
1686 return HorizontalAlignment.Left;
1689 internal Size GetImageSize ()
1691 if (this.Image == null)
1694 if (this.image_scaling == ToolStripItemImageScaling.None)
1695 return this.Image.Size;
1697 if (this.Parent == null)
1700 return this.Parent.ImageScalingSize;
1703 internal string GetToolTip ()
1705 if (this.auto_tool_tip && string.IsNullOrEmpty (this.tool_tip_text))
1708 return this.tool_tip_text;
1711 internal void FireEvent (EventArgs e, ToolStripItemEventType met)
1713 // If we're disabled, don't fire any of these events, except Paint
1714 if (!this.Enabled && met != ToolStripItemEventType.Paint)
1718 case ToolStripItemEventType.MouseUp:
1719 this.OnMouseUp ((MouseEventArgs)e);
1720 this.HandleClick (e);
1722 case ToolStripItemEventType.MouseDown:
1723 this.OnMouseDown ((MouseEventArgs)e);
1725 case ToolStripItemEventType.MouseEnter:
1726 this.OnMouseEnter (e);
1728 case ToolStripItemEventType.MouseHover:
1729 this.OnMouseHover (e);
1731 case ToolStripItemEventType.MouseLeave:
1732 this.OnMouseLeave (e);
1734 case ToolStripItemEventType.MouseMove:
1735 this.OnMouseMove ((MouseEventArgs)e);
1737 case ToolStripItemEventType.Paint:
1738 this.OnPaint ((PaintEventArgs)e);
1740 case ToolStripItemEventType.Click:
1741 this.HandleClick (e);
1746 internal virtual void HandleClick (EventArgs e)
1748 this.Parent.HandleItemClick (this);
1752 internal virtual void SetPlacement (ToolStripItemPlacement placement)
1754 this.placement = placement;
1757 private void BeginAnimation ()
1759 if (image != null && ImageAnimator.CanAnimate (image)) {
1760 frame_handler = new EventHandler (OnAnimateImage);
1761 ImageAnimator.Animate (image, frame_handler);
1765 private void OnAnimateImage (object sender, EventArgs e)
1767 // This is called from a worker thread,BeginInvoke is used
1768 // so the control is updated from the correct thread
1770 // Check if we have a handle again, since it may have gotten
1771 // destroyed since the last time we checked.
1772 if (Parent == null || !Parent.IsHandleCreated)
1775 Parent.BeginInvoke (new EventHandler (UpdateAnimatedImage), new object[] { this, e });
1778 private void StopAnimation ()
1780 if (frame_handler == null)
1783 ImageAnimator.StopAnimate (image, frame_handler);
1784 frame_handler = null;
1787 private void UpdateAnimatedImage (object sender, EventArgs e)
1789 // Check if we have a handle again, since it may have gotten
1790 // destroyed since the last time we checked.
1791 if (Parent == null || !Parent.IsHandleCreated)
1794 ImageAnimator.UpdateFrames (image);
1798 internal bool ShowMargin {
1800 if (!this.IsOnDropDown)
1803 if (!(this.Owner is ToolStripDropDownMenu))
1806 ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
1808 return tsddm.ShowCheckMargin || tsddm.ShowImageMargin;
1812 internal bool UseImageMargin {
1814 if (!this.IsOnDropDown)
1817 if (!(this.Owner is ToolStripDropDownMenu))
1820 ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
1822 return tsddm.ShowImageMargin || tsddm.ShowCheckMargin;
1826 internal virtual bool InternalVisible {
1827 get { return this.visible; }
1828 set { this.visible = value; Invalidate (); }
1831 internal Point Location {
1832 get { return this.bounds.Location; }
1834 if (this.bounds.Location != value) {
1835 this.bounds.Location = value;
1836 this.OnLocationChanged (EventArgs.Empty);
1842 get { return this.bounds.Y; }
1844 if (this.bounds.Y != value) {
1845 this.bounds.Y = value;
1846 this.OnLocationChanged (EventArgs.Empty);
1852 get { return this.bounds.X; }
1854 if (this.bounds.X != value) {
1855 this.bounds.X = value;
1856 this.OnLocationChanged (EventArgs.Empty);
1861 internal int Right { get { return this.bounds.Right; } }
1862 internal int Bottom { get { return this.bounds.Bottom; } }
1865 #region IDropTarget Members
1866 void IDropTarget.OnDragDrop (DragEventArgs e)
1871 void IDropTarget.OnDragEnter (DragEventArgs e)
1876 void IDropTarget.OnDragLeave (EventArgs e)
1881 void IDropTarget.OnDragOver (DragEventArgs e)
1888 public class ToolStripItemAccessibleObject : AccessibleObject
1890 internal ToolStripItem owner_item;
1892 public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
1894 if (ownerItem == null)
1895 throw new ArgumentNullException ("ownerItem");
1897 this.owner_item = ownerItem;
1898 base.default_action = string.Empty;
1899 base.keyboard_shortcut = string.Empty;
1900 base.name = string.Empty;
1901 base.value = string.Empty;
1904 #region Public Properties
1905 public override Rectangle Bounds {
1907 return owner_item.Visible ? owner_item.Bounds : Rectangle.Empty;
1911 public override string DefaultAction {
1912 get { return base.DefaultAction; }
1915 public override string Description {
1916 get { return base.Description; }
1919 public override string Help {
1920 get { return base.Help; }
1923 public override string KeyboardShortcut {
1924 get { return base.KeyboardShortcut; }
1927 public override string Name {
1929 if (base.name == string.Empty)
1930 return owner_item.Text;
1934 set { base.Name = value; }
1937 public override AccessibleObject Parent {
1938 get { return base.Parent; }
1941 public override AccessibleRole Role {
1942 get { return base.Role; }
1945 public override AccessibleStates State {
1946 get { return base.State; }
1950 #region Public Methods
1951 public void AddState (AccessibleStates state)
1956 public override void DoDefaultAction ()
1958 base.DoDefaultAction ();
1961 public override int GetHelpTopic (out string fileName)
1963 return base.GetHelpTopic (out fileName);
1966 public override AccessibleObject Navigate (AccessibleNavigation navigationDirection)
1968 return base.Navigate (navigationDirection);
1971 public override string ToString ()
1973 return string.Format ("ToolStripItemAccessibleObject: Owner = {0}", owner_item.ToString());
1979 #region NoneExcludedImageIndexConverter Class
1980 internal class NoneExcludedImageIndexConverter : ImageIndexConverter