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;
34 namespace System.Windows.Forms
36 [DefaultEvent ("Click")]
37 [DefaultProperty ("Text")]
38 [DesignTimeVisible (false)]
40 public abstract class ToolStripItem : Component, IDropTarget, IComponent, IDisposable
42 #region Private Variables
43 private AccessibleObject accessibility_object;
44 private string accessible_default_action_description;
45 private ToolStripItemAlignment alignment;
46 private bool auto_size;
47 private bool auto_tool_tip;
48 private bool available;
49 private Color back_color;
50 private Rectangle bounds;
51 private bool can_select;
52 private ToolStripItemDisplayStyle display_style;
53 private DockStyle dock;
54 private bool double_click_enabled;
57 private Color fore_color;
59 private ContentAlignment image_align;
60 private int image_index;
61 private ToolStripItemImageScaling image_scaling;
62 protected bool is_pressed;
63 private bool is_selected;
64 private Padding margin;
66 private ToolStrip owner;
67 internal ToolStripItem owner_item;
68 private Padding padding;
71 private ContentAlignment text_align;
72 private TextImageRelation text_image_relation;
73 private string tool_tip_text;
76 private ToolStrip parent;
77 internal Size text_size;
80 #region Public Constructors
81 protected ToolStripItem ()
82 : this (String.Empty, null, null, String.Empty)
86 protected ToolStripItem (string text, Image image, EventHandler onClick)
87 : this (text, image, onClick, String.Empty)
91 protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
93 this.alignment = ToolStripItemAlignment.Left;
94 this.auto_size = true;
95 this.auto_tool_tip = this.DefaultAutoToolTip;
96 this.available = true;
97 this.back_color = Control.DefaultBackColor;
98 this.display_style = this.DefaultDisplayStyle;
99 this.dock = DockStyle.None;
101 this.font = new Font ("Tahoma", 8.25f);
102 this.fore_color = Control.DefaultForeColor;
104 this.image_align = ContentAlignment.MiddleCenter;
105 this.image_index = -1;
106 this.image_scaling = ToolStripItemImageScaling.SizeToFit;
107 this.margin = this.DefaultMargin;
109 this.padding = this.DefaultPadding;
110 this.bounds.Size = this.DefaultSize;
112 this.text_align = ContentAlignment.MiddleCenter;
113 this.text_image_relation = TextImageRelation.ImageBeforeText;
116 this.Click = onClick;
117 this.can_select = this is ToolStripMenuItem ? true : false;
118 OnLayout (new LayoutEventArgs (null, ""));
122 #region Public Properties
123 public AccessibleObject AccessibilityObject {
125 if (this.accessibility_object == null)
126 this.accessibility_object = CreateAccessibilityInstance ();
128 return this.accessibility_object;
132 public string AccessibleDefaultActionDescription {
134 if (this.accessibility_object == null)
137 return this.accessible_default_action_description;
139 set { this.accessible_default_action_description = value; }
143 public string AccessibleDescription {
145 if (this.accessibility_object == null)
148 return this.AccessibilityObject.Description;
150 set { this.AccessibilityObject.description = value; }
154 public string AccessibleName {
156 if (this.accessibility_object == null)
159 return this.AccessibilityObject.Name;
161 set { this.AccessibilityObject.Name = value; }
164 public AccessibleRole AccessibleRole {
167 if (this.accessibility_object == null)
168 return AccessibleRole.Default;
170 return this.AccessibilityObject.Role;
172 set { this.AccessibilityObject.role = value; }
176 [DefaultValue (ToolStripItemAlignment.Left)]
177 public ToolStripItemAlignment Alignment {
178 get { return this.alignment; }
180 if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
181 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
183 this.alignment = value;
188 [DefaultValue (true)]
189 public bool AutoSize {
190 get { return this.auto_size; }
192 this.auto_size = value;
193 this.CalculateAutoSize ();
197 [MonoTODO ("Need 2.0 ToolTip to implement tool tips.")]
198 [DefaultValue (false)]
199 public bool AutoToolTip {
200 get { return this.auto_tool_tip; }
201 set { this.auto_tool_tip = value; }
205 public bool Available {
206 get { return this.visible; }
208 if (this.visible != value) {
211 if (this.owner != null)
212 owner.PerformLayout ();
214 OnAvailableChanged (EventArgs.Empty);
219 public virtual Color BackColor {
220 get { return this.back_color; }
222 if (this.back_color != value) {
224 OnBackColorChanged (EventArgs.Empty);
231 public virtual Rectangle Bounds {
232 get { return this.bounds; }
236 public virtual bool CanSelect {
237 get { return this.can_select; }
241 public Rectangle ContentRectangle {
243 // ToolStripLabels don't have a border
244 if (this is ToolStripLabel)
245 return new Rectangle (0, 0, this.bounds.Width, this.bounds.Height);
247 return new Rectangle (2, 2, this.bounds.Width - 4, this.bounds.Height - 4);
251 public virtual ToolStripItemDisplayStyle DisplayStyle {
252 get { return this.display_style; }
254 if (this.display_style != value) {
255 this.display_style = value;
256 this.CalculateAutoSize ();
257 OnDisplayStyleChanged (EventArgs.Empty);
264 [DefaultValue (DockStyle.None)]
265 public DockStyle Dock {
266 get { return this.dock; }
268 if (this.dock != value) {
269 if (!Enum.IsDefined (typeof (DockStyle), value))
270 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for DockStyle", value));
273 this.CalculateAutoSize ();
278 [DefaultValue (false)]
279 public bool DoubleClickEnabled {
280 get { return this.double_click_enabled; }
281 set { this.double_click_enabled = value; }
285 [DefaultValue (true)]
286 public virtual bool Enabled {
287 get { return enabled; }
289 if (this.enabled != value) {
290 this.enabled = value;
291 OnEnabledChanged (EventArgs.Empty);
298 public virtual Font Font
300 get { return this.font; }
302 if (this.font != value) {
304 this.CalculateAutoSize ();
305 this.OnFontChanged (EventArgs.Empty);
311 public virtual Color ForeColor {
312 get { return this.fore_color; }
314 if (this.fore_color != value) {
315 this.fore_color = value;
316 this.OnForeColorChanged (EventArgs.Empty);
324 get { return this.bounds.Height; }
326 this.bounds.Height = value;
327 this.CalculateAutoSize ();
328 this.OnBoundsChanged ();
334 public virtual Image Image {
335 get { return this.image; }
338 this.CalculateAutoSize ();
344 [DefaultValue (ContentAlignment.MiddleCenter)]
345 public ContentAlignment ImageAlign {
346 get { return this.image_align; }
348 if (!Enum.IsDefined (typeof (ContentAlignment), value))
349 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
351 this.image_align = value;
357 public int ImageIndex {
358 get { return this.image_index; }
361 throw new ArgumentException ("ImageIndex cannot be less than -1");
363 this.image_index = value;
364 this.CalculateAutoSize ();
370 [DefaultValue (ToolStripItemImageScaling.SizeToFit)]
371 public ToolStripItemImageScaling ImageScaling {
372 get { return this.image_scaling; }
374 this.image_scaling = value;
375 this.CalculateAutoSize ();
381 public bool IsOnDropDown {
383 if (this.owner != null && this.owner is ToolStripDropDown)
390 public Padding Margin {
391 get { return this.margin; }
394 this.CalculateAutoSize ();
398 [DefaultValue (null)]
400 get { return this.name; }
401 set { this.name = value; }
405 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
406 public ToolStrip Owner {
407 get { return this.owner; }
409 if (this.owner != value) {
411 this.CalculateAutoSize ();
412 OnOwnerChanged (EventArgs.Empty);
418 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
419 public ToolStripItem OwnerItem {
420 get { return this.owner_item; }
423 public virtual Padding Padding {
424 get { return this.padding; }
426 this.padding = value;
427 this.CalculateAutoSize ();
433 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
434 public virtual bool Pressed { get { return this.is_pressed; } }
437 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
438 public virtual bool Selected { get { return this.is_selected; } }
441 public virtual Size Size {
442 get { return this.bounds.Size; }
444 this.bounds.Size = value;
445 this.CalculateAutoSize ();
450 [Localizable (false)]
452 [DefaultValue (null)]
454 get { return this.tag; }
455 set { this.tag = value; }
460 public virtual string Text
462 get { return this.text; }
464 if (this.text != value) {
466 this.CalculateAutoSize ();
467 this.OnTextChanged (EventArgs.Empty);
474 [DefaultValue (ContentAlignment.MiddleCenter)]
475 public virtual ContentAlignment TextAlign {
476 get { return this.text_align; }
478 if (!Enum.IsDefined (typeof (ContentAlignment), value))
479 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
480 this.text_align = value;
486 [DefaultValue (TextImageRelation.ImageBeforeText)]
487 public TextImageRelation TextImageRelation {
488 get { return this.text_image_relation; }
490 this.text_image_relation = value;
491 this.CalculateAutoSize ();
497 public string ToolTipText {
498 get { return this.tool_tip_text; }
499 set { this.tool_tip_text = value; }
503 public bool Visible {
505 if (this.parent == null)
508 return this.visible && this.parent.Visible;
511 if (this.visible != value) {
512 this.visible = value;
513 this.OnVisibleChanged (EventArgs.Empty);
521 get { return this.bounds.Width; }
523 this.bounds.Width = value;
524 this.CalculateAutoSize ();
525 this.OnBoundsChanged();
530 #region Protected Properties
531 protected virtual bool DefaultAutoToolTip { get { return false; } }
532 protected virtual ToolStripItemDisplayStyle DefaultDisplayStyle { get { return ToolStripItemDisplayStyle.ImageAndText; } }
533 protected internal virtual Padding DefaultMargin { get { return new Padding (0, 1, 0, 2); } }
534 protected virtual Padding DefaultPadding { get { return new Padding (); } }
535 protected virtual Size DefaultSize { get { return new Size (23, 23); } }
536 protected internal virtual bool DismissWhenClicked { get { return false; } }
538 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
539 protected internal ToolStrip Parent {
540 get { return this.parent; }
542 ToolStrip old_parent = this.parent;
544 OnParentChanged(old_parent, this.parent);
547 protected internal virtual bool ShowKeyboardCues { get { return true; } }
550 #region Public Methods
551 public ToolStrip GetCurrentParent ()
556 public virtual Size GetPreferredSize (Size constrainingSize)
558 return this.CalculatePreferredSize (constrainingSize);
561 public void Invalidate ()
564 owner.Invalidate (this.bounds);
567 public void Invalidate (Rectangle r)
570 owner.Invalidate (r);
573 public void PerformClick ()
575 this.OnClick (EventArgs.Empty);
578 [EditorBrowsable (EditorBrowsableState.Never)]
579 public virtual void ResetBackColor () { this.BackColor = Control.DefaultBackColor; }
581 [EditorBrowsable (EditorBrowsableState.Never)]
582 public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
584 [EditorBrowsable (EditorBrowsableState.Never)]
585 public virtual void ResetFont () { this.font = new Font ("Tahoma", 8.25f); }
587 [EditorBrowsable (EditorBrowsableState.Never)]
588 public virtual void ResetForeColor () { this.ForeColor = Control.DefaultForeColor; }
590 [EditorBrowsable (EditorBrowsableState.Never)]
591 public virtual void ResetImage () { this.image = null; }
593 [EditorBrowsable (EditorBrowsableState.Never)]
594 public void ResetMargin () { this.margin = this.DefaultMargin; }
596 [EditorBrowsable (EditorBrowsableState.Never)]
597 public void ResetPadding () { this.padding = this.DefaultPadding; }
599 public void Select ()
601 if (this.CanSelect) {
602 this.is_selected = true;
607 public override string ToString ()
613 #region Protected Methods
614 protected virtual AccessibleObject CreateAccessibilityInstance ()
616 return new ToolStripItemAccessibleObject (this);
619 protected virtual void OnAvailableChanged (EventArgs e)
621 if (AvailableChanged != null) AvailableChanged (this, e);
624 protected virtual void OnBackColorChanged (EventArgs e)
626 if (BackColorChanged != null) BackColorChanged (this, e);
629 protected virtual void OnBoundsChanged ()
631 OnLayout (new LayoutEventArgs(null, ""));
634 protected virtual void OnClick (EventArgs e)
636 if (Click != null) Click (this, e);
639 protected virtual void OnDisplayStyleChanged (EventArgs e)
641 if (DisplayStyleChanged != null) DisplayStyleChanged (this, e);
644 protected virtual void OnDoubleClick (EventArgs e)
646 if (DoubleClick != null) DoubleClick (this, e);
648 if (!double_click_enabled)
652 protected virtual void OnEnabledChanged (EventArgs e)
654 if (EnabledChanged != null) EnabledChanged (this, e);
657 protected virtual void OnFontChanged (EventArgs e)
661 protected virtual void OnForeColorChanged (EventArgs e)
663 if (ForeColorChanged != null) ForeColorChanged (this, e);
666 protected virtual void OnLayout (LayoutEventArgs e)
670 protected virtual void OnLocationChanged (EventArgs e)
672 if (LocationChanged != null) LocationChanged (this, e);
675 protected virtual void OnMouseDown (MouseEventArgs e)
678 if (MouseDown != null) MouseDown (this, e);
679 this.is_pressed = true;
684 protected virtual void OnMouseEnter (EventArgs e)
686 if (MouseEnter != null) MouseEnter (this, e);
688 if (this.CanSelect) {
689 this.is_selected = true;
694 protected virtual void OnMouseHover (EventArgs e)
697 if (MouseHover != null) MouseHover (this, e);
700 protected virtual void OnMouseLeave (EventArgs e)
702 if (MouseLeave != null) MouseLeave (this, e);
704 if (this.CanSelect) {
705 this.is_selected = false;
706 this.is_pressed = false;
711 protected virtual void OnMouseMove (MouseEventArgs e)
714 if (MouseMove != null) MouseMove (this, e);
717 protected virtual void OnMouseUp (MouseEventArgs e)
720 if (MouseUp != null) MouseUp (this, e);
721 this.is_pressed = false;
726 protected virtual void OnOwnerChanged (EventArgs e)
728 if (OwnerChanged != null) OwnerChanged (this, e);
731 protected virtual void OnPaint (PaintEventArgs e)
733 if (Paint != null) Paint (this, e);
736 protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
740 protected virtual void OnTextChanged (EventArgs e)
742 if (TextChanged != null) TextChanged (this, e);
745 protected virtual void OnVisibleChanged (EventArgs e)
747 if (VisibleChanged != null) VisibleChanged (this, e);
750 protected internal virtual void SetBounds (Rectangle bounds)
752 if (this.bounds != bounds) {
753 this.bounds = bounds;
759 #region Public Events
761 public event EventHandler AvailableChanged;
762 public event EventHandler BackColorChanged;
763 public event EventHandler Click;
764 public event EventHandler DisplayStyleChanged;
765 public event EventHandler DoubleClick;
766 public event EventHandler EnabledChanged;
767 public event EventHandler ForeColorChanged;
768 public event EventHandler LocationChanged;
769 public event MouseEventHandler MouseDown;
770 public event EventHandler MouseEnter;
771 public event EventHandler MouseHover;
772 public event EventHandler MouseLeave;
773 public event MouseEventHandler MouseMove;
774 public event MouseEventHandler MouseUp;
775 public event EventHandler OwnerChanged;
776 public event PaintEventHandler Paint;
777 public event EventHandler TextChanged;
778 public event EventHandler VisibleChanged;
781 #region Internal Methods
782 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, ContentAlignment align)
787 if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft)
789 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter)
790 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
791 else if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight)
792 x = outer.Right - inner.Width;
793 if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight)
795 else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight)
796 y = outer.Y + (outer.Height - inner.Height) / 2;
797 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomRight || align == ContentAlignment.BottomLeft)
798 y = outer.Bottom - inner.Height;
800 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
803 internal void CalculateAutoSize ()
805 if (!this.auto_size || this is ToolStripControlHost)
808 this.text_size = TextRenderer.MeasureText (this.Text, this.Font);
809 //this.text_size.Width += 6;
811 Size final_size = this.CalculatePreferredSize (Size.Empty);
813 if (final_size != this.Size) {
814 this.bounds.Size = final_size;
815 if (this.owner != null)
816 this.owner.PerformLayout ();
820 internal Size CalculatePreferredSize (Size constrainingSize)
822 Size preferred_size = this.DefaultSize;
824 switch (this.display_style) {
825 case ToolStripItemDisplayStyle.Text:
826 int width = text_size.Width + this.padding.Horizontal;
827 int height = text_size.Height + this.padding.Vertical;
828 preferred_size = new Size (width, height);
830 case ToolStripItemDisplayStyle.Image:
831 if (this.image == null)
832 preferred_size = this.DefaultSize;
834 switch (this.image_scaling) {
835 case ToolStripItemImageScaling.None:
836 preferred_size = this.image.Size;
838 case ToolStripItemImageScaling.SizeToFit:
839 if (this.owner == null)
840 preferred_size = this.image.Size;
842 preferred_size = this.owner.ImageScalingSize;
847 case ToolStripItemDisplayStyle.ImageAndText:
848 int width2 = text_size.Width + this.padding.Horizontal;
849 int height2 = text_size.Height + this.padding.Vertical;
851 if (this.image != null) {
852 switch (this.text_image_relation) {
853 case TextImageRelation.Overlay:
854 width2 = Math.Max (width2, this.image.Width);
855 height2 = Math.Max (height2, this.image.Height);
857 case TextImageRelation.ImageAboveText:
858 case TextImageRelation.TextAboveImage:
859 width2 = Math.Max (width2, this.image.Width);
860 height2 += this.image.Height;
862 case TextImageRelation.ImageBeforeText:
863 case TextImageRelation.TextBeforeImage:
864 height2 = Math.Max (height2, this.image.Height);
865 width2 += this.image.Width;
870 preferred_size = new Size (width2, height2);
874 if (!(this is ToolStripLabel)) { // Everything but labels have a border
875 preferred_size.Height += 4;
876 preferred_size.Width += 4;
879 if (preferred_size.Width < 23)
880 preferred_size.Width = 23; // There seems to be a minimum width of 23
881 return preferred_size;
884 internal void CalculateTextAndImageRectangles (out Rectangle text_rect, out Rectangle image_rect)
886 text_rect = Rectangle.Empty;
887 image_rect = Rectangle.Empty;
889 switch (this.display_style) {
890 case ToolStripItemDisplayStyle.None:
892 case ToolStripItemDisplayStyle.Text:
893 if (this.text != string.Empty)
894 text_rect = AlignInRectangle (this.ContentRectangle, this.text_size, this.text_align);
896 case ToolStripItemDisplayStyle.Image:
897 if (this.image != null)
898 image_rect = AlignInRectangle (this.ContentRectangle, this.image.Size, this.image_align);
900 case ToolStripItemDisplayStyle.ImageAndText:
901 if (this.text != string.Empty && this.image == null)
902 text_rect = AlignInRectangle (this.ContentRectangle, this.text_size, this.text_align);
903 else if (this.text == string.Empty && this.image != null)
904 image_rect = AlignInRectangle (this.ContentRectangle, this.image.Size, this.image_align);
905 else if (this.text == string.Empty && this.image == null)
909 Rectangle image_area;
911 switch (this.text_image_relation) {
912 case TextImageRelation.Overlay:
913 text_rect = AlignInRectangle (this.ContentRectangle, this.text_size, this.text_align);
914 image_rect = AlignInRectangle (this.ContentRectangle, this.image.Size, this.image_align);
916 case TextImageRelation.ImageAboveText:
917 text_area = new Rectangle (this.ContentRectangle.Left, this.ContentRectangle.Bottom - (text_size.Height - 4), this.ContentRectangle.Width, text_size.Height - 4);
918 image_area = new Rectangle (this.ContentRectangle.Left, this.ContentRectangle.Top, this.ContentRectangle.Width, this.ContentRectangle.Height - text_area.Height);
920 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
921 image_rect = AlignInRectangle (image_area, this.image.Size, this.image_align);
923 case TextImageRelation.TextAboveImage:
924 text_area = new Rectangle (this.ContentRectangle.Left, this.ContentRectangle.Top, this.ContentRectangle.Width, text_size.Height - 4);
925 image_area = new Rectangle (this.ContentRectangle.Left, text_area.Bottom, this.ContentRectangle.Width, this.ContentRectangle.Height - text_area.Height);
927 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
928 image_rect = AlignInRectangle (image_area, this.image.Size, this.image_align);
930 case TextImageRelation.ImageBeforeText:
931 text_area = new Rectangle (this.ContentRectangle.Right - this.text_size.Width, this.ContentRectangle.Top, this.text_size.Width, this.ContentRectangle.Height);
932 image_area = new Rectangle (this.ContentRectangle.Left, this.ContentRectangle.Top, text_area.Left - this.ContentRectangle.Left, this.ContentRectangle.Height);
934 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
935 image_rect = AlignInRectangle (image_area, this.image.Size, this.image_align);
937 case TextImageRelation.TextBeforeImage:
938 text_area = new Rectangle (this.ContentRectangle.Left, this.ContentRectangle.Top, this.text_size.Width, this.ContentRectangle.Height);
939 image_area = new Rectangle (text_area.Right, this.ContentRectangle.Top, this.ContentRectangle.Width - text_area.Width, this.ContentRectangle.Height);
941 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
942 image_rect = AlignInRectangle (image_area, this.image.Size, this.image_align);
950 internal void FireEvent (EventArgs e, ToolStripItemEventType met)
953 case ToolStripItemEventType.MouseUp:
954 this.OnMouseUp ((MouseEventArgs)e);
955 this.OnClick ((MouseEventArgs)e);
957 case ToolStripItemEventType.MouseDown:
958 this.OnMouseDown ((MouseEventArgs)e);
960 case ToolStripItemEventType.MouseEnter:
961 this.OnMouseEnter (e);
963 case ToolStripItemEventType.MouseHover:
964 this.OnMouseHover (e);
966 case ToolStripItemEventType.MouseLeave:
967 this.OnMouseLeave (e);
969 case ToolStripItemEventType.MouseMove:
970 this.OnMouseMove ((MouseEventArgs)e);
972 case ToolStripItemEventType.Paint:
973 this.OnPaint ((PaintEventArgs)e);
979 public class ToolStripItemAccessibleObject : AccessibleObject
981 private ToolStripItem owner;
983 public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
985 if (ownerItem == null)
986 throw new ArgumentNullException ("ownerItem");
988 this.owner = ownerItem;
989 base.default_action = string.Empty;
990 base.keyboard_shortcut = string.Empty;
991 base.name = string.Empty;
992 base.value = string.Empty;
995 #region Public Properties
996 public override Rectangle Bounds {
998 return owner.Visible ? owner.Bounds : Rectangle.Empty;
1002 public override string DefaultAction {
1003 get { return base.DefaultAction; }
1006 public override string Description {
1007 get { return base.Description; }
1010 public override string Help {
1011 get { return base.Help; }
1014 public override string KeyboardShortcut {
1015 get { return base.KeyboardShortcut; }
1018 public override string Name {
1020 if (base.name == string.Empty)
1025 set { base.Name = value; }
1028 public override AccessibleObject Parent {
1029 get { return base.Parent; }
1032 public override AccessibleRole Role {
1033 get { return base.Role; }
1036 public override AccessibleStates State {
1037 get { return base.State; }
1041 #region Public Methods
1042 public void AddState (AccessibleStates state)
1047 public override void DoDefaultAction ()
1049 base.DoDefaultAction ();
1052 public override int GetHelpTopic (out string FileName)
1054 return base.GetHelpTopic (out FileName);
1057 public override AccessibleObject Navigate (AccessibleNavigation navdir)
1059 return base.Navigate (navdir);
1062 public override string ToString ()
1064 return string.Format ("ToolStripItemAccessibleObject: Owner = {0}", owner.ToString());