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 = Color.Empty;
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.fore_color = Color.Empty;
124 this.image_align = ContentAlignment.MiddleCenter;
125 this.image_index = -1;
126 this.image_key = string.Empty;
127 this.image_scaling = ToolStripItemImageScaling.SizeToFit;
128 this.image_transparent_color = Color.Empty;
129 this.margin = this.DefaultMargin;
130 this.merge_action = MergeAction.Append;
131 this.merge_index = -1;
133 this.overflow = ToolStripItemOverflow.AsNeeded;
134 this.padding = this.DefaultPadding;
135 this.placement = ToolStripItemPlacement.None;
136 this.right_to_left = RightToLeft.Inherit;
137 this.bounds.Size = this.DefaultSize;
139 this.text_align = ContentAlignment.MiddleCenter;
140 this.text_direction = DefaultTextDirection;
141 this.text_image_relation = TextImageRelation.ImageBeforeText;
144 this.Click += onClick;
145 OnLayout (new LayoutEventArgs (null, string.Empty));
149 #region Public Properties
151 [EditorBrowsable (EditorBrowsableState.Advanced)]
152 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
153 public AccessibleObject AccessibilityObject {
155 if (this.accessibility_object == null)
156 this.accessibility_object = CreateAccessibilityInstance ();
158 return this.accessibility_object;
163 [EditorBrowsable (EditorBrowsableState.Advanced)]
164 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
165 public string AccessibleDefaultActionDescription {
167 if (this.accessibility_object == null)
170 return this.accessible_default_action_description;
172 set { this.accessible_default_action_description = value; }
176 [DefaultValue (null)]
177 public string AccessibleDescription {
179 if (this.accessibility_object == null)
182 return this.AccessibilityObject.Description;
184 set { this.AccessibilityObject.description = value; }
188 [DefaultValue (null)]
189 public string AccessibleName {
191 if (this.accessibility_object == null)
194 return this.AccessibilityObject.Name;
196 set { this.AccessibilityObject.Name = value; }
199 [DefaultValue (AccessibleRole.Default)]
200 public AccessibleRole AccessibleRole {
203 if (this.accessibility_object == null)
204 return AccessibleRole.Default;
206 return this.AccessibilityObject.Role;
208 set { this.AccessibilityObject.role = value; }
211 [DefaultValue (ToolStripItemAlignment.Left)]
212 public ToolStripItemAlignment Alignment {
213 get { return this.alignment; }
215 if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
216 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
218 if (this.alignment != value) {
219 this.alignment = value;
220 this.CalculateAutoSize ();
225 [MonoTODO ("Stub, does nothing")]
227 [DefaultValue (false)]
228 [EditorBrowsable (EditorBrowsableState.Advanced)]
229 public virtual bool AllowDrop {
230 get { return this.allow_drop; }
231 set { this.allow_drop = value; }
235 [DefaultValue (AnchorStyles.Top | AnchorStyles.Left)]
236 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
237 public AnchorStyles Anchor {
238 get { return this.anchor; }
239 set { this.anchor = value; }
243 [DefaultValue (true)]
244 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
245 [RefreshProperties (RefreshProperties.All)]
246 public bool AutoSize {
247 get { return this.auto_size; }
249 this.auto_size = value;
250 this.CalculateAutoSize ();
254 [DefaultValue (false)]
255 public bool AutoToolTip {
256 get { return this.auto_tool_tip; }
257 set { this.auto_tool_tip = value; }
261 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
262 public bool Available {
263 get { return this.available; }
265 if (this.available != value) {
269 if (this.parent != null)
270 parent.PerformLayout ();
272 OnAvailableChanged (EventArgs.Empty);
273 OnVisibleChanged (EventArgs.Empty);
278 public virtual Color BackColor {
280 if (back_color != Color.Empty)
284 return parent.BackColor;
286 return Control.DefaultBackColor;
289 if (this.back_color != value) {
291 OnBackColorChanged (EventArgs.Empty);
298 [DefaultValue (null)]
299 public virtual Image BackgroundImage {
300 get { return this.background_image; }
302 if (this.background_image != value) {
303 this.background_image = value;
310 [DefaultValue (ImageLayout.Tile)]
311 public virtual ImageLayout BackgroundImageLayout {
312 get { return this.background_image_layout; }
314 if (this.background_image_layout != value) {
315 this.background_image_layout = value;
322 public virtual Rectangle Bounds {
323 get { return this.bounds; }
327 public virtual bool CanSelect {
328 get { return this.can_select; }
332 public Rectangle ContentRectangle {
334 // ToolStripLabels don't have a border
335 if (this is ToolStripLabel || this is ToolStripStatusLabel)
336 return new Rectangle (0, 0, this.bounds.Width, this.bounds.Height);
338 if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
339 return new Rectangle (2, 2, this.bounds.Width - 13, this.bounds.Height - 4);
341 return new Rectangle (2, 2, this.bounds.Width - 4, this.bounds.Height - 4);
345 public virtual ToolStripItemDisplayStyle DisplayStyle {
346 get { return this.display_style; }
348 if (this.display_style != value) {
349 this.display_style = value;
350 this.CalculateAutoSize ();
351 OnDisplayStyleChanged (EventArgs.Empty);
357 public bool IsDisposed {
358 get { return this.is_disposed; }
362 [DefaultValue (DockStyle.None)]
363 public DockStyle Dock {
364 get { return this.dock; }
366 if (this.dock != value) {
367 if (!Enum.IsDefined (typeof (DockStyle), value))
368 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for DockStyle", value));
371 this.CalculateAutoSize ();
376 [DefaultValue (false)]
377 public bool DoubleClickEnabled {
378 get { return this.double_click_enabled; }
379 set { this.double_click_enabled = value; }
383 [DefaultValue (true)]
384 public virtual bool Enabled {
397 if (this.enabled != value) {
398 this.enabled = value;
399 OnEnabledChanged (EventArgs.Empty);
406 public virtual Font Font {
417 if (this.font != value) {
419 this.CalculateAutoSize ();
420 this.OnFontChanged (EventArgs.Empty);
426 public virtual Color ForeColor {
428 if (fore_color != Color.Empty)
432 return parent.ForeColor;
434 return Control.DefaultForeColor;
437 if (this.fore_color != value) {
438 this.fore_color = value;
439 this.OnForeColorChanged (EventArgs.Empty);
446 [EditorBrowsable (EditorBrowsableState.Always)]
447 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
449 get { return this.Size.Height; }
451 this.Size = new Size (this.Size.Width, value);
452 this.explicit_size.Height = value;
455 this.CalculateAutoSize ();
456 this.OnBoundsChanged ();
463 public virtual Image Image {
465 if (this.image != null)
468 if (this.image_index >= 0)
469 if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
470 return this.owner.ImageList.Images[this.image_index];
473 if (!string.IsNullOrEmpty (this.image_key))
474 if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
475 return this.owner.ImageList.Images[this.image_key];
480 if (this.image != value) {
484 this.image_index = -1;
485 this.image_key = string.Empty;
486 this.CalculateAutoSize ();
495 [DefaultValue (ContentAlignment.MiddleCenter)]
496 public ContentAlignment ImageAlign {
497 get { return this.image_align; }
499 if (!Enum.IsDefined (typeof (ContentAlignment), value))
500 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
502 if (image_align != value) {
503 this.image_align = value;
504 this.CalculateAutoSize ();
511 [RelatedImageList ("Owner.ImageList")]
512 [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
513 [RefreshProperties (RefreshProperties.Repaint)]
514 [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
515 public int ImageIndex {
516 get { return this.image_index; }
518 if (this.image_index != value) {
519 // Lamespec: MSDN says ArgumentException, tests say otherwise
521 throw new ArgumentOutOfRangeException ("ImageIndex cannot be less than -1");
523 this.image_index = value;
525 this.image_key = string.Empty;
526 this.CalculateAutoSize ();
534 [RelatedImageList ("Owner.ImageList")]
535 [TypeConverter (typeof (ImageKeyConverter))]
536 [RefreshProperties (RefreshProperties.Repaint)]
537 [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
538 public string ImageKey {
539 get { return this.image_key; }
541 if (this.image_key != value) {
543 this.image_index = -1;
544 this.image_key = value;
545 this.CalculateAutoSize ();
552 [DefaultValue (ToolStripItemImageScaling.SizeToFit)]
553 public ToolStripItemImageScaling ImageScaling {
554 get { return this.image_scaling; }
556 if (image_scaling != value) {
557 this.image_scaling = value;
558 this.CalculateAutoSize ();
564 public Color ImageTransparentColor {
565 get { return this.image_transparent_color; }
566 set { this.image_transparent_color = value; }
570 public bool IsOnDropDown {
572 if (this.parent != null && this.parent is ToolStripDropDown)
580 public bool IsOnOverflow {
581 get { return this.placement == ToolStripItemPlacement.Overflow; }
584 public Padding Margin {
585 get { return this.margin; }
588 this.CalculateAutoSize ();
592 [DefaultValue (MergeAction.Append)]
593 public MergeAction MergeAction {
594 get { return this.merge_action; }
596 if (!Enum.IsDefined (typeof (MergeAction), value))
597 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for MergeAction", value));
599 this.merge_action = value;
604 public int MergeIndex {
605 get { return this.merge_index; }
606 set { this.merge_index = value; }
609 [DefaultValue (null)]
612 get { return this.name; }
613 set { this.name = value; }
616 [DefaultValue (ToolStripItemOverflow.AsNeeded)]
617 public ToolStripItemOverflow Overflow {
618 get { return this.overflow; }
620 if (this.overflow != value) {
621 if (!Enum.IsDefined (typeof (ToolStripItemOverflow), value))
622 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemOverflow", value));
624 this.overflow = value;
627 owner.PerformLayout ();
633 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
634 public ToolStrip Owner {
635 get { return this.owner; }
637 if (this.owner != value) {
638 if (this.owner != null)
639 this.owner.Items.Remove (this);
642 value.Items.Add (this);
650 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
651 public ToolStripItem OwnerItem {
652 get { return this.owner_item; }
655 public virtual Padding Padding {
656 get { return this.padding; }
658 this.padding = value;
659 this.CalculateAutoSize ();
665 public ToolStripItemPlacement Placement {
666 get { return this.placement; }
670 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
671 public virtual bool Pressed { get { return this.is_pressed; } }
673 [MonoTODO ("RTL not implemented")]
675 public virtual RightToLeft RightToLeft {
676 get { return this.right_to_left; }
678 if (this.right_to_left != value) {
679 this.right_to_left = value;
680 this.OnRightToLeftChanged (EventArgs.Empty);
686 [DefaultValue (false)]
687 public bool RightToLeftAutoMirrorImage {
688 get { return this.right_to_left_auto_mirror_image; }
690 if (this.right_to_left_auto_mirror_image != value) {
691 this.right_to_left_auto_mirror_image = value;
698 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
699 public virtual bool Selected { get { return this.is_selected; } }
702 public virtual Size Size {
704 if (!this.AutoSize && this.explicit_size != Size.Empty)
705 return this.explicit_size;
707 return this.bounds.Size;
710 this.bounds.Size = value;
711 this.explicit_size = value;
714 this.CalculateAutoSize ();
715 this.OnBoundsChanged ();
720 [Localizable (false)]
722 [DefaultValue (null)]
723 [TypeConverter (typeof (StringConverter))]
725 get { return this.tag; }
726 set { this.tag = value; }
731 public virtual string Text
733 get { return this.text; }
735 if (this.text != value) {
738 this.CalculateAutoSize ();
740 this.OnTextChanged (EventArgs.Empty);
746 [DefaultValue (ContentAlignment.MiddleCenter)]
747 public virtual ContentAlignment TextAlign {
748 get { return this.text_align; }
750 if (!Enum.IsDefined (typeof (ContentAlignment), value))
751 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
753 if (this.text_align != value) {
754 this.text_align = value;
755 this.CalculateAutoSize ();
760 public virtual ToolStripTextDirection TextDirection {
762 if (this.text_direction == ToolStripTextDirection.Inherit) {
763 if (this.Parent != null)
764 return this.Parent.TextDirection;
766 return ToolStripTextDirection.Horizontal;
769 return this.text_direction;
772 if (!Enum.IsDefined (typeof (ToolStripTextDirection), value))
773 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripTextDirection", value));
775 if (this.text_direction != value) {
776 this.text_direction = value;
777 this.CalculateAutoSize ();
784 [DefaultValue (TextImageRelation.ImageBeforeText)]
785 public TextImageRelation TextImageRelation {
786 get { return this.text_image_relation; }
788 this.text_image_relation = value;
789 this.CalculateAutoSize ();
795 [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
796 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
797 public string ToolTipText {
798 get { return this.tool_tip_text; }
799 set { this.tool_tip_text = value; }
803 public bool Visible {
805 if (this.parent == null)
808 return this.visible && this.parent.Visible;
811 if (this.visible != value) {
812 this.available = value;
813 this.SetVisibleCore (value);
814 if (this.Owner != null)
815 this.Owner.PerformLayout ();
821 [EditorBrowsable (EditorBrowsableState.Always)]
822 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
824 get { return this.Size.Width; }
826 this.Size = new Size (value, this.Size.Height);
827 this.explicit_size.Width = value;
830 this.CalculateAutoSize ();
831 this.OnBoundsChanged ();
838 #region Protected Properties
839 protected virtual bool DefaultAutoToolTip { get { return false; } }
840 protected virtual ToolStripItemDisplayStyle DefaultDisplayStyle { get { return ToolStripItemDisplayStyle.ImageAndText; } }
841 protected internal virtual Padding DefaultMargin { get { return new Padding (0, 1, 0, 2); } }
842 protected virtual Padding DefaultPadding { get { return new Padding (); } }
843 protected virtual Size DefaultSize { get { return new Size (23, 23); } }
844 protected internal virtual bool DismissWhenClicked { get { return true; } }
846 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
847 protected internal ToolStrip Parent {
848 get { return this.parent; }
850 if (this.parent != value) {
851 ToolStrip old_parent = this.parent;
853 OnParentChanged(old_parent, this.parent);
857 protected internal virtual bool ShowKeyboardCues { get { return false; } }
860 #region Public Methods
861 [MonoTODO ("Stub, does nothing")]
862 [EditorBrowsable (EditorBrowsableState.Advanced)]
863 public DragDropEffects DoDragDrop (Object data, DragDropEffects allowedEffects)
865 return allowedEffects;
868 public ToolStrip GetCurrentParent ()
873 public virtual Size GetPreferredSize (Size constrainingSize)
875 return this.CalculatePreferredSize (constrainingSize);
878 public void Invalidate ()
881 parent.Invalidate (this.bounds);
884 public void Invalidate (Rectangle r)
887 parent.Invalidate (r);
890 public void PerformClick ()
892 this.OnClick (EventArgs.Empty);
895 [EditorBrowsable (EditorBrowsableState.Never)]
896 public virtual void ResetBackColor () { this.BackColor = Color.Empty; }
898 [EditorBrowsable (EditorBrowsableState.Never)]
899 public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
901 [EditorBrowsable (EditorBrowsableState.Never)]
902 public virtual void ResetFont () { this.font = null; }
904 [EditorBrowsable (EditorBrowsableState.Never)]
905 public virtual void ResetForeColor () { this.ForeColor = Color.Empty; }
907 [EditorBrowsable (EditorBrowsableState.Never)]
908 public virtual void ResetImage () { this.image = null; }
910 [EditorBrowsable (EditorBrowsableState.Never)]
911 public void ResetMargin () { this.margin = this.DefaultMargin; }
913 [EditorBrowsable (EditorBrowsableState.Never)]
914 public void ResetPadding () { this.padding = this.DefaultPadding; }
916 [EditorBrowsable (EditorBrowsableState.Never)]
917 public virtual void ResetRightToLeft () { this.right_to_left = RightToLeft.Inherit; }
919 [EditorBrowsable (EditorBrowsableState.Never)]
920 public virtual void ResetTextDirection () { this.TextDirection = this.DefaultTextDirection; }
922 public void Select ()
924 if (!this.is_selected && this.CanSelect) {
925 this.is_selected = true;
927 if (this.Parent != null) {
928 if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
929 (this as ToolStripControlHost).Focus ();
932 this.Parent.NotifySelectedChanged (this);
934 OnUIASelectionChanged ();
938 public override string ToString ()
944 #region Protected Methods
945 [EditorBrowsable (EditorBrowsableState.Advanced)]
946 protected virtual AccessibleObject CreateAccessibilityInstance ()
948 return new ToolStripItemAccessibleObject (this);
951 protected override void Dispose (bool disposing)
953 if (!is_disposed && disposing)
962 owner.Items.Remove (this);
964 base.Dispose (disposing);
967 protected internal virtual bool IsInputChar (char charCode)
972 protected internal virtual bool IsInputKey (Keys keyData)
977 protected virtual void OnAvailableChanged (EventArgs e)
979 EventHandler eh = (EventHandler)(Events [AvailableChangedEvent]);
984 [EditorBrowsable (EditorBrowsableState.Advanced)]
985 protected virtual void OnBackColorChanged (EventArgs e)
987 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
992 protected virtual void OnBoundsChanged ()
994 OnLayout (new LayoutEventArgs(null, string.Empty));
997 protected virtual void OnClick (EventArgs e)
999 EventHandler eh = (EventHandler)(Events [ClickEvent]);
1004 [EditorBrowsable (EditorBrowsableState.Advanced)]
1005 protected virtual void OnDisplayStyleChanged (EventArgs e)
1007 EventHandler eh = (EventHandler)(Events [DisplayStyleChangedEvent]);
1012 protected virtual void OnDoubleClick (EventArgs e)
1014 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
1019 [EditorBrowsable (EditorBrowsableState.Advanced)]
1020 protected virtual void OnDragDrop (DragEventArgs dragEvent)
1022 DragEventHandler eh = (DragEventHandler)(Events[DragDropEvent]);
1024 eh (this, dragEvent);
1027 [EditorBrowsable (EditorBrowsableState.Advanced)]
1028 protected virtual void OnDragEnter (DragEventArgs dragEvent)
1030 DragEventHandler eh = (DragEventHandler)(Events[DragEnterEvent]);
1032 eh (this, dragEvent);
1035 [EditorBrowsable (EditorBrowsableState.Advanced)]
1036 protected virtual void OnDragLeave (EventArgs e)
1038 EventHandler eh = (EventHandler)(Events[DragLeaveEvent]);
1043 [EditorBrowsable (EditorBrowsableState.Advanced)]
1044 protected virtual void OnDragOver (DragEventArgs dragEvent)
1046 DragEventHandler eh = (DragEventHandler)(Events[DragOverEvent]);
1048 eh (this, dragEvent);
1051 protected virtual void OnEnabledChanged (EventArgs e)
1053 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
1058 [EditorBrowsable (EditorBrowsableState.Advanced)]
1059 protected virtual void OnFontChanged (EventArgs e)
1063 [EditorBrowsable (EditorBrowsableState.Advanced)]
1064 protected virtual void OnForeColorChanged (EventArgs e)
1066 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
1071 [EditorBrowsable (EditorBrowsableState.Advanced)]
1072 protected virtual void OnGiveFeedback (GiveFeedbackEventArgs giveFeedbackEvent)
1074 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events[GiveFeedbackEvent]);
1076 eh (this, giveFeedbackEvent);
1079 protected virtual void OnLayout (LayoutEventArgs e)
1083 protected virtual void OnLocationChanged (EventArgs e)
1085 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
1090 protected virtual void OnMouseDown (MouseEventArgs e)
1093 this.is_pressed = true;
1096 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
1102 protected virtual void OnMouseEnter (EventArgs e)
1106 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
1111 protected virtual void OnMouseHover (EventArgs e)
1114 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
1120 protected virtual void OnMouseLeave (EventArgs e)
1122 if (this.CanSelect) {
1123 this.is_selected = false;
1124 this.is_pressed = false;
1126 OnUIASelectionChanged ();
1129 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
1134 protected virtual void OnMouseMove (MouseEventArgs mea)
1137 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
1143 protected virtual void OnMouseUp (MouseEventArgs e)
1146 this.is_pressed = false;
1149 if (this.IsOnDropDown)
1150 if (!(this is ToolStripDropDownItem) || !(this as ToolStripDropDownItem).HasDropDownItems || (this as ToolStripDropDownItem).DropDown.Visible == false) {
1151 if ((this.Parent as ToolStripDropDown).OwnerItem != null)
1152 ((this.Parent as ToolStripDropDown).OwnerItem as ToolStripDropDownItem).HideDropDown ();
1154 (this.Parent as ToolStripDropDown).Hide ();
1158 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
1164 protected virtual void OnOwnerChanged (EventArgs e)
1166 EventHandler eh = (EventHandler)(Events [OwnerChangedEvent]);
1171 [EditorBrowsable (EditorBrowsableState.Advanced)]
1172 protected internal virtual void OnOwnerFontChanged (EventArgs e)
1174 this.CalculateAutoSize ();
1175 OnFontChanged (EventArgs.Empty);
1178 void OnPaintInternal (PaintEventArgs e)
1180 // Have the background rendered independently from OnPaint
1181 if (this.parent != null)
1182 this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
1187 protected virtual void OnPaint (PaintEventArgs e)
1189 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
1194 // This is never called.
1195 [EditorBrowsable (EditorBrowsableState.Advanced)]
1196 protected virtual void OnParentBackColorChanged (EventArgs e)
1200 protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
1202 this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty : this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
1204 if (oldParent != null)
1205 oldParent.PerformLayout ();
1207 if (newParent != null)
1208 newParent.PerformLayout ();
1211 protected internal virtual void OnParentEnabledChanged (EventArgs e)
1213 this.OnEnabledChanged (e);
1216 // This is never called.
1217 [EditorBrowsable (EditorBrowsableState.Advanced)]
1218 protected virtual void OnParentForeColorChanged (EventArgs e)
1222 [EditorBrowsable (EditorBrowsableState.Advanced)]
1223 protected internal virtual void OnParentRightToLeftChanged (EventArgs e)
1225 this.OnRightToLeftChanged (e);
1228 [EditorBrowsable (EditorBrowsableState.Advanced)]
1229 protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs queryContinueDragEvent)
1231 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events[QueryContinueDragEvent]);
1233 eh (this, queryContinueDragEvent);
1236 protected virtual void OnRightToLeftChanged (EventArgs e)
1238 EventHandler eh = (EventHandler)(Events[RightToLeftChangedEvent]);
1243 [EditorBrowsable (EditorBrowsableState.Advanced)]
1244 protected virtual void OnTextChanged (EventArgs e)
1246 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
1251 protected virtual void OnVisibleChanged (EventArgs e)
1253 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
1258 protected internal virtual bool ProcessCmdKey (ref Message m, Keys keyData)
1263 protected internal virtual bool ProcessDialogKey (Keys keyData)
1265 if (this.Selected && keyData == Keys.Enter) {
1266 this.FireEvent (EventArgs.Empty, ToolStripItemEventType.Click);
1273 // ProcessMnemonic will only be called if we are supposed to handle
1274 // it. None of that fancy "thinking" needed!
1275 protected internal virtual bool ProcessMnemonic (char charCode)
1277 ToolStripManager.SetActiveToolStrip (this.Parent, true);
1278 this.PerformClick ();
1282 protected internal virtual void SetBounds (Rectangle bounds)
1284 if (this.bounds != bounds) {
1285 this.bounds = bounds;
1290 protected virtual void SetVisibleCore (bool visible)
1292 this.visible = visible;
1293 this.OnVisibleChanged (EventArgs.Empty);
1303 #region Public Events
1304 static object AvailableChangedEvent = new object ();
1305 static object BackColorChangedEvent = new object ();
1306 static object ClickEvent = new object ();
1307 static object DisplayStyleChangedEvent = new object ();
1308 static object DoubleClickEvent = new object ();
1309 static object DragDropEvent = new object ();
1310 static object DragEnterEvent = new object ();
1311 static object DragLeaveEvent = new object ();
1312 static object DragOverEvent = new object ();
1313 static object EnabledChangedEvent = new object ();
1314 static object ForeColorChangedEvent = new object ();
1315 static object GiveFeedbackEvent = new object ();
1316 static object LocationChangedEvent = new object ();
1317 static object MouseDownEvent = new object ();
1318 static object MouseEnterEvent = new object ();
1319 static object MouseHoverEvent = new object ();
1320 static object MouseLeaveEvent = new object ();
1321 static object MouseMoveEvent = new object ();
1322 static object MouseUpEvent = new object ();
1323 static object OwnerChangedEvent = new object ();
1324 static object PaintEvent = new object ();
1325 static object QueryAccessibilityHelpEvent = new object ();
1326 static object QueryContinueDragEvent = new object ();
1327 static object RightToLeftChangedEvent = new object ();
1328 static object TextChangedEvent = new object ();
1329 static object VisibleChangedEvent = new object ();
1332 public event EventHandler AvailableChanged {
1333 add { Events.AddHandler (AvailableChangedEvent, value); }
1334 remove {Events.RemoveHandler (AvailableChangedEvent, value); }
1337 public event EventHandler BackColorChanged {
1338 add { Events.AddHandler (BackColorChangedEvent, value); }
1339 remove {Events.RemoveHandler (BackColorChangedEvent, value); }
1342 public event EventHandler Click {
1343 add { Events.AddHandler (ClickEvent, value); }
1344 remove {Events.RemoveHandler (ClickEvent, value); }
1347 public event EventHandler DisplayStyleChanged {
1348 add { Events.AddHandler (DisplayStyleChangedEvent, value); }
1349 remove {Events.RemoveHandler (DisplayStyleChangedEvent, value); }
1352 public event EventHandler DoubleClick {
1353 add { Events.AddHandler (DoubleClickEvent, value); }
1354 remove {Events.RemoveHandler (DoubleClickEvent, value); }
1357 [MonoTODO ("Event never raised")]
1359 [EditorBrowsable (EditorBrowsableState.Advanced)]
1360 public event DragEventHandler DragDrop {
1361 add { Events.AddHandler (DragDropEvent, value); }
1362 remove { Events.RemoveHandler (DragDropEvent, value); }
1365 [MonoTODO ("Event never raised")]
1367 [EditorBrowsable (EditorBrowsableState.Advanced)]
1368 public event DragEventHandler DragEnter {
1369 add { Events.AddHandler (DragEnterEvent, value); }
1370 remove { Events.RemoveHandler (DragEnterEvent, value); }
1373 [MonoTODO ("Event never raised")]
1375 [EditorBrowsable (EditorBrowsableState.Advanced)]
1376 public event EventHandler DragLeave {
1377 add { Events.AddHandler (DragLeaveEvent, value); }
1378 remove { Events.RemoveHandler (DragLeaveEvent, value); }
1381 [MonoTODO ("Event never raised")]
1383 [EditorBrowsable (EditorBrowsableState.Advanced)]
1384 public event DragEventHandler DragOver {
1385 add { Events.AddHandler (DragOverEvent, value); }
1386 remove { Events.RemoveHandler (DragOverEvent, value); }
1389 public event EventHandler EnabledChanged {
1390 add { Events.AddHandler (EnabledChangedEvent, value); }
1391 remove {Events.RemoveHandler (EnabledChangedEvent, value); }
1394 public event EventHandler ForeColorChanged {
1395 add { Events.AddHandler (ForeColorChangedEvent, value); }
1396 remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
1399 [MonoTODO ("Event never raised")]
1401 [EditorBrowsable (EditorBrowsableState.Advanced)]
1402 public event GiveFeedbackEventHandler GiveFeedback {
1403 add { Events.AddHandler (GiveFeedbackEvent, value); }
1404 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
1407 public event EventHandler LocationChanged {
1408 add { Events.AddHandler (LocationChangedEvent, value); }
1409 remove {Events.RemoveHandler (LocationChangedEvent, value); }
1412 public event MouseEventHandler MouseDown {
1413 add { Events.AddHandler (MouseDownEvent, value); }
1414 remove {Events.RemoveHandler (MouseDownEvent, value); }
1417 public event EventHandler MouseEnter {
1418 add { Events.AddHandler (MouseEnterEvent, value); }
1419 remove {Events.RemoveHandler (MouseEnterEvent, value); }
1422 public event EventHandler MouseHover {
1423 add { Events.AddHandler (MouseHoverEvent, value); }
1424 remove {Events.RemoveHandler (MouseHoverEvent, value); }
1427 public event EventHandler MouseLeave {
1428 add { Events.AddHandler (MouseLeaveEvent, value); }
1429 remove {Events.RemoveHandler (MouseLeaveEvent, value); }
1432 public event MouseEventHandler MouseMove {
1433 add { Events.AddHandler (MouseMoveEvent, value); }
1434 remove {Events.RemoveHandler (MouseMoveEvent, value); }
1437 public event MouseEventHandler MouseUp {
1438 add { Events.AddHandler (MouseUpEvent, value); }
1439 remove {Events.RemoveHandler (MouseUpEvent, value); }
1442 public event EventHandler OwnerChanged {
1443 add { Events.AddHandler (OwnerChangedEvent, value); }
1444 remove {Events.RemoveHandler (OwnerChangedEvent, value); }
1447 public event PaintEventHandler Paint {
1448 add { Events.AddHandler (PaintEvent, value); }
1449 remove {Events.RemoveHandler (PaintEvent, value); }
1452 [MonoTODO ("Event never raised")]
1453 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
1454 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
1455 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
1458 [MonoTODO ("Event never raised")]
1460 [EditorBrowsable (EditorBrowsableState.Advanced)]
1461 public event QueryContinueDragEventHandler QueryContinueDrag {
1462 add { Events.AddHandler (QueryContinueDragEvent, value); }
1463 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
1466 public event EventHandler RightToLeftChanged {
1467 add { Events.AddHandler (RightToLeftChangedEvent, value); }
1468 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
1471 public event EventHandler TextChanged {
1472 add { Events.AddHandler (TextChangedEvent, value); }
1473 remove {Events.RemoveHandler (TextChangedEvent, value); }
1476 public event EventHandler VisibleChanged {
1477 add { Events.AddHandler (VisibleChangedEvent, value); }
1478 remove {Events.RemoveHandler (VisibleChangedEvent, value); }
1482 #region Internal Methods
1483 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, ContentAlignment align)
1488 if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft)
1490 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter)
1491 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
1492 else if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight)
1493 x = outer.Right - inner.Width;
1494 if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight)
1496 else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight)
1497 y = outer.Y + (outer.Height - inner.Height) / 2;
1498 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomRight || align == ContentAlignment.BottomLeft)
1499 y = outer.Bottom - inner.Height;
1501 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
1504 internal void CalculateAutoSize ()
1506 this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty: this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
1508 // If our text is rotated, flip the width and height
1509 ToolStripTextDirection direction = this.TextDirection;
1511 if (direction == ToolStripTextDirection.Vertical270 || direction == ToolStripTextDirection.Vertical90)
1512 this.text_size = new Size (this.text_size.Height, this.text_size.Width);
1514 if (!this.auto_size || this is ToolStripControlHost)
1516 //this.text_size.Width += 6;
1518 Size final_size = this.CalculatePreferredSize (Size.Empty);
1520 if (final_size != this.Size) {
1521 this.bounds.Width = final_size.Width;
1522 if (this.parent != null)
1523 this.parent.PerformLayout ();
1527 internal virtual Size CalculatePreferredSize (Size constrainingSize)
1529 if (!this.auto_size)
1530 return this.explicit_size;
1532 Size preferred_size = this.DefaultSize;
1534 switch (this.display_style) {
1535 case ToolStripItemDisplayStyle.Text:
1536 int width = text_size.Width + this.padding.Horizontal;
1537 int height = text_size.Height + this.padding.Vertical;
1538 preferred_size = new Size (width, height);
1540 case ToolStripItemDisplayStyle.Image:
1541 if (this.GetImageSize () == Size.Empty)
1542 preferred_size = this.DefaultSize;
1544 switch (this.image_scaling) {
1545 case ToolStripItemImageScaling.None:
1546 preferred_size = this.GetImageSize ();
1548 case ToolStripItemImageScaling.SizeToFit:
1549 if (this.parent == null)
1550 preferred_size = this.GetImageSize ();
1552 preferred_size = this.parent.ImageScalingSize;
1557 case ToolStripItemDisplayStyle.ImageAndText:
1558 int width2 = text_size.Width + this.padding.Horizontal;
1559 int height2 = text_size.Height + this.padding.Vertical;
1561 if (this.GetImageSize () != Size.Empty) {
1562 Size image_size = this.GetImageSize ();
1564 if (this.image_scaling == ToolStripItemImageScaling.SizeToFit && this.parent != null)
1565 image_size = this.parent.ImageScalingSize;
1567 switch (this.text_image_relation) {
1568 case TextImageRelation.Overlay:
1569 width2 = Math.Max (width2, image_size.Width);
1570 height2 = Math.Max (height2, image_size.Height);
1572 case TextImageRelation.ImageAboveText:
1573 case TextImageRelation.TextAboveImage:
1574 width2 = Math.Max (width2, image_size.Width);
1575 height2 += image_size.Height;
1577 case TextImageRelation.ImageBeforeText:
1578 case TextImageRelation.TextBeforeImage:
1579 height2 = Math.Max (height2, image_size.Height);
1580 width2 += image_size.Width;
1585 preferred_size = new Size (width2, height2);
1589 if (!(this is ToolStripLabel)) { // Everything but labels have a border
1590 preferred_size.Height += 4;
1591 preferred_size.Width += 4;
1594 return preferred_size;
1597 internal void CalculateTextAndImageRectangles (out Rectangle text_rect, out Rectangle image_rect)
1599 this.CalculateTextAndImageRectangles (this.ContentRectangle, out text_rect, out image_rect);
1602 internal void CalculateTextAndImageRectangles (Rectangle contentRectangle, out Rectangle text_rect, out Rectangle image_rect)
1604 text_rect = Rectangle.Empty;
1605 image_rect = Rectangle.Empty;
1607 switch (this.display_style) {
1608 case ToolStripItemDisplayStyle.None:
1610 case ToolStripItemDisplayStyle.Text:
1611 if (this.text != string.Empty)
1612 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1614 case ToolStripItemDisplayStyle.Image:
1615 if (this.Image != null && this.UseImageMargin)
1616 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1618 case ToolStripItemDisplayStyle.ImageAndText:
1619 if (this.text != string.Empty && (this.Image == null || !this.UseImageMargin))
1620 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1621 else if (this.text == string.Empty && (this.Image == null || !this.UseImageMargin))
1623 else if (this.text == string.Empty && this.Image != null)
1624 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1626 Rectangle text_area;
1627 Rectangle image_area;
1629 switch (this.text_image_relation) {
1630 case TextImageRelation.Overlay:
1631 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1632 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1634 case TextImageRelation.ImageAboveText:
1635 text_area = new Rectangle (contentRectangle.Left, contentRectangle.Bottom - (text_size.Height - 4), contentRectangle.Width, text_size.Height - 4);
1636 image_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, contentRectangle.Height - text_area.Height);
1638 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1639 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1641 case TextImageRelation.TextAboveImage:
1642 text_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, text_size.Height - 4);
1643 image_area = new Rectangle (contentRectangle.Left, text_area.Bottom, contentRectangle.Width, contentRectangle.Height - text_area.Height);
1645 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1646 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1648 case TextImageRelation.ImageBeforeText:
1649 LayoutTextBeforeOrAfterImage (contentRectangle, false, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1651 case TextImageRelation.TextBeforeImage:
1652 LayoutTextBeforeOrAfterImage (contentRectangle, true, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1660 private static Font DefaultFont { get { return new Font ("Tahoma", 8.25f); } }
1662 internal virtual ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Inherit; } }
1664 internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
1667 this.is_selected = false;
1669 OnUIASelectionChanged ();
1673 internal virtual ToolStrip GetTopLevelToolStrip ()
1675 if (this.Parent != null)
1676 return this.Parent.GetTopLevelToolStrip ();
1681 private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, ContentAlignment textAlign, ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
1683 int element_spacing = 0; // Spacing between the Text and the Image
1684 int total_width = textSize.Width + element_spacing + imageSize.Width;
1685 int excess_width = totalArea.Width - total_width;
1688 Rectangle final_text_rect;
1689 Rectangle final_image_rect;
1691 HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
1692 HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
1694 if (h_image == HorizontalAlignment.Left)
1696 else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
1697 offset = excess_width;
1698 else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
1699 offset += (int)(excess_width / 3);
1701 offset += (int)(2 * (excess_width / 3));
1704 final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
1705 final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
1707 final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
1708 final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
1711 textRect = final_text_rect;
1712 imageRect = final_image_rect;
1715 private HorizontalAlignment GetHorizontalAlignment (ContentAlignment align)
1718 case ContentAlignment.BottomLeft:
1719 case ContentAlignment.MiddleLeft:
1720 case ContentAlignment.TopLeft:
1721 return HorizontalAlignment.Left;
1722 case ContentAlignment.BottomCenter:
1723 case ContentAlignment.MiddleCenter:
1724 case ContentAlignment.TopCenter:
1725 return HorizontalAlignment.Center;
1726 case ContentAlignment.BottomRight:
1727 case ContentAlignment.MiddleRight:
1728 case ContentAlignment.TopRight:
1729 return HorizontalAlignment.Right;
1732 return HorizontalAlignment.Left;
1735 internal Size GetImageSize ()
1737 // Get the actual size of our internal image -or-
1738 // Get the ImageList.ImageSize if we are using ImageLists
1739 if (this.image_scaling == ToolStripItemImageScaling.None) {
1740 if (this.image != null)
1743 if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
1744 if (this.owner != null && this.owner.ImageList != null)
1745 return this.owner.ImageList.ImageSize;
1747 // If we have an image and a parent, return ImageScalingSize
1748 if (this.Parent == null)
1751 if (this.image != null)
1752 return this.Parent.ImageScalingSize;
1754 if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
1755 if (this.owner != null && this.owner.ImageList != null)
1756 return this.Parent.ImageScalingSize;
1762 internal string GetToolTip ()
1764 if (this.auto_tool_tip && string.IsNullOrEmpty (this.tool_tip_text))
1767 return this.tool_tip_text;
1770 internal void FireEvent (EventArgs e, ToolStripItemEventType met)
1772 // If we're disabled, don't fire any of these events, except Paint
1773 if (!this.Enabled && met != ToolStripItemEventType.Paint)
1777 case ToolStripItemEventType.MouseUp:
1778 this.HandleClick (((MouseEventArgs)e).Clicks, e);
1779 this.OnMouseUp ((MouseEventArgs)e);
1781 case ToolStripItemEventType.MouseDown:
1782 this.OnMouseDown ((MouseEventArgs)e);
1784 case ToolStripItemEventType.MouseEnter:
1785 this.OnMouseEnter (e);
1787 case ToolStripItemEventType.MouseHover:
1788 this.OnMouseHover (e);
1790 case ToolStripItemEventType.MouseLeave:
1791 this.OnMouseLeave (e);
1793 case ToolStripItemEventType.MouseMove:
1794 this.OnMouseMove ((MouseEventArgs)e);
1796 case ToolStripItemEventType.Paint:
1797 this.OnPaintInternal ((PaintEventArgs)e);
1799 case ToolStripItemEventType.Click:
1800 this.HandleClick (1, e);
1805 internal virtual void HandleClick (int mouse_clicks, EventArgs e)
1809 this.Parent.HandleItemClick (this);
1810 if (mouse_clicks == 2 && double_click_enabled)
1811 this.OnDoubleClick (e);
1816 internal virtual void SetPlacement (ToolStripItemPlacement placement)
1818 this.placement = placement;
1821 private void BeginAnimation ()
1823 if (image != null && ImageAnimator.CanAnimate (image)) {
1824 frame_handler = new EventHandler (OnAnimateImage);
1825 ImageAnimator.Animate (image, frame_handler);
1829 private void OnAnimateImage (object sender, EventArgs e)
1831 // This is called from a worker thread,BeginInvoke is used
1832 // so the control is updated from the correct thread
1834 // Check if we have a handle again, since it may have gotten
1835 // destroyed since the last time we checked.
1836 if (Parent == null || !Parent.IsHandleCreated)
1839 Parent.BeginInvoke (new EventHandler (UpdateAnimatedImage), new object[] { this, e });
1842 private void StopAnimation ()
1844 if (frame_handler == null)
1847 ImageAnimator.StopAnimate (image, frame_handler);
1848 frame_handler = null;
1851 private void UpdateAnimatedImage (object sender, EventArgs e)
1853 // Check if we have a handle again, since it may have gotten
1854 // destroyed since the last time we checked.
1855 if (Parent == null || !Parent.IsHandleCreated)
1858 ImageAnimator.UpdateFrames (image);
1862 internal bool ShowMargin {
1864 if (!this.IsOnDropDown)
1867 if (!(this.Owner is ToolStripDropDownMenu))
1870 ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
1872 return tsddm.ShowCheckMargin || tsddm.ShowImageMargin;
1876 internal bool UseImageMargin {
1878 if (!this.IsOnDropDown)
1881 if (!(this.Owner is ToolStripDropDownMenu))
1884 ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
1886 return tsddm.ShowImageMargin || tsddm.ShowCheckMargin;
1890 internal virtual bool InternalVisible {
1891 get { return this.visible; }
1892 set { this.visible = value; Invalidate (); }
1895 internal ToolStrip InternalOwner {
1897 if (this.owner != value) {
1899 if (this.owner != null)
1900 this.CalculateAutoSize ();
1901 OnOwnerChanged (EventArgs.Empty);
1906 internal Point Location {
1907 get { return this.bounds.Location; }
1909 if (this.bounds.Location != value) {
1910 this.bounds.Location = value;
1911 this.OnLocationChanged (EventArgs.Empty);
1917 get { return this.bounds.Y; }
1919 if (this.bounds.Y != value) {
1920 this.bounds.Y = value;
1921 this.OnLocationChanged (EventArgs.Empty);
1927 get { return this.bounds.X; }
1929 if (this.bounds.X != value) {
1930 this.bounds.X = value;
1931 this.OnLocationChanged (EventArgs.Empty);
1936 internal int Right { get { return this.bounds.Right; } }
1937 internal int Bottom { get { return this.bounds.Bottom; } }
1940 #region IDropTarget Members
1941 void IDropTarget.OnDragDrop (DragEventArgs dragEvent)
1943 OnDragDrop (dragEvent);
1946 void IDropTarget.OnDragEnter (DragEventArgs dragEvent)
1948 OnDragEnter (dragEvent);
1951 void IDropTarget.OnDragLeave (EventArgs e)
1956 void IDropTarget.OnDragOver (DragEventArgs dragEvent)
1958 OnDragOver (dragEvent);
1962 #region UIA Framework: Methods, Properties and Events
1964 static object UIASelectionChangedEvent = new object ();
1966 internal event EventHandler UIASelectionChanged {
1967 add { Events.AddHandler (UIASelectionChangedEvent, value); }
1968 remove { Events.RemoveHandler (UIASelectionChangedEvent, value); }
1971 internal void OnUIASelectionChanged ()
1973 EventHandler eh = (EventHandler)(Events [UIASelectionChangedEvent]);
1975 eh (this, EventArgs.Empty);
1981 public class ToolStripItemAccessibleObject : AccessibleObject
1983 internal ToolStripItem owner_item;
1985 public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
1987 if (ownerItem == null)
1988 throw new ArgumentNullException ("ownerItem");
1990 this.owner_item = ownerItem;
1991 base.default_action = string.Empty;
1992 base.keyboard_shortcut = string.Empty;
1993 base.name = string.Empty;
1994 base.value = string.Empty;
1997 #region Public Properties
1998 public override Rectangle Bounds {
2000 return owner_item.Visible ? owner_item.Bounds : Rectangle.Empty;
2004 public override string DefaultAction {
2005 get { return base.DefaultAction; }
2008 public override string Description {
2009 get { return base.Description; }
2012 public override string Help {
2013 get { return base.Help; }
2016 public override string KeyboardShortcut {
2017 get { return base.KeyboardShortcut; }
2020 public override string Name {
2022 if (base.name == string.Empty)
2023 return owner_item.Text;
2027 set { base.Name = value; }
2030 public override AccessibleObject Parent {
2031 get { return base.Parent; }
2034 public override AccessibleRole Role {
2035 get { return base.Role; }
2038 public override AccessibleStates State {
2039 get { return base.State; }
2043 #region Public Methods
2044 public void AddState (AccessibleStates state)
2049 public override void DoDefaultAction ()
2051 base.DoDefaultAction ();
2054 public override int GetHelpTopic (out string fileName)
2056 return base.GetHelpTopic (out fileName);
2059 public override AccessibleObject Navigate (AccessibleNavigation navigationDirection)
2061 return base.Navigate (navigationDirection);
2064 public override string ToString ()
2066 return string.Format ("ToolStripItemAccessibleObject: Owner = {0}", owner_item.ToString());
2072 internal class NoneExcludedImageIndexConverter : ImageIndexConverter