2007-05-03 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripItem.cs
blob85730000c392b502f70b64eb7758cc7ef46e43c0
1 //
2 // ToolStripItem.cs
3 //
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:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
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
25 // Authors:
26 // Jonathan Pobst (monkey@jpobst.com)
28 #if NET_2_0
30 using System;
31 using System.Drawing;
32 using System.ComponentModel;
34 namespace System.Windows.Forms
36 [DefaultEvent ("Click")]
37 [DefaultProperty ("Text")]
38 [DesignTimeVisible (false)]
39 [ToolboxItem (false)]
40 [Designer ("System.Windows.Forms.Design.ToolStripItemDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
41 public abstract class ToolStripItem : Component, IDropTarget, IComponent, IDisposable
43 #region Private Variables
44 private AccessibleObject accessibility_object;
45 private string accessible_default_action_description;
46 private bool allow_drop;
47 private ToolStripItemAlignment alignment;
48 private AnchorStyles anchor;
49 private bool available;
50 private bool auto_size;
51 private bool auto_tool_tip;
52 private Color back_color;
53 private Image background_image;
54 private ImageLayout background_image_layout;
55 private Rectangle bounds;
56 private bool can_select;
57 private ToolStripItemDisplayStyle display_style;
58 private DockStyle dock;
59 private bool double_click_enabled;
60 private bool enabled;
61 private Size explicit_size;
62 private Font font;
63 private Color fore_color;
64 private Image image;
65 private ContentAlignment image_align;
66 private int image_index;
67 private string image_key;
68 private ToolStripItemImageScaling image_scaling;
69 private Color image_transparent_color;
70 private bool is_disposed;
71 internal bool is_pressed;
72 private bool is_selected;
73 private Padding margin;
74 private MergeAction merge_action;
75 private int merge_index;
76 private string name;
77 private ToolStripItemOverflow overflow;
78 private ToolStrip owner;
79 internal ToolStripItem owner_item;
80 private Padding padding;
81 private ToolStripItemPlacement placement;
82 private RightToLeft right_to_left;
83 private bool right_to_left_auto_mirror_image;
84 private Object tag;
85 private string text;
86 private ContentAlignment text_align;
87 private TextImageRelation text_image_relation;
88 private string tool_tip_text;
89 private bool visible;
91 private ToolStrip parent;
92 private Size text_size;
93 #endregion
95 #region Public Constructors
96 protected ToolStripItem ()
97 : this (String.Empty, null, null, String.Empty)
101 protected ToolStripItem (string text, Image image, EventHandler onClick)
102 : this (text, image, onClick, String.Empty)
106 protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
108 this.alignment = ToolStripItemAlignment.Left;
109 this.anchor = AnchorStyles.Left | AnchorStyles.Top;
110 this.auto_size = true;
111 this.auto_tool_tip = this.DefaultAutoToolTip;
112 this.available = true;
113 this.back_color = Control.DefaultBackColor;
114 this.background_image_layout = ImageLayout.Tile;
115 this.can_select = true;
116 this.display_style = this.DefaultDisplayStyle;
117 this.dock = DockStyle.None;
118 this.enabled = true;
119 this.font = new Font ("Tahoma", 8.25f);
120 this.fore_color = Control.DefaultForeColor;
121 this.image = image;
122 this.image_align = ContentAlignment.MiddleCenter;
123 this.image_index = -1;
124 this.image_key = string.Empty;
125 this.image_scaling = ToolStripItemImageScaling.SizeToFit;
126 this.image_transparent_color = Color.Empty;
127 this.margin = this.DefaultMargin;
128 this.merge_action = MergeAction.Append;
129 this.merge_index = -1;
130 this.name = name;
131 this.overflow = ToolStripItemOverflow.AsNeeded;
132 this.padding = this.DefaultPadding;
133 this.placement = ToolStripItemPlacement.None;
134 this.right_to_left = RightToLeft.Inherit;
135 this.bounds.Size = this.DefaultSize;
136 this.text = text;
137 this.text_align = ContentAlignment.MiddleCenter;
138 this.text_image_relation = TextImageRelation.ImageBeforeText;
139 this.visible = true;
141 this.Click += onClick;
142 OnLayout (new LayoutEventArgs (null, string.Empty));
144 #endregion
146 #region Public Properties
147 [Browsable (false)]
148 [EditorBrowsable (EditorBrowsableState.Advanced)]
149 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
150 public AccessibleObject AccessibilityObject {
151 get {
152 if (this.accessibility_object == null)
153 this.accessibility_object = CreateAccessibilityInstance ();
155 return this.accessibility_object;
159 [Browsable (false)]
160 [EditorBrowsable (EditorBrowsableState.Advanced)]
161 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
162 public string AccessibleDefaultActionDescription {
163 get {
164 if (this.accessibility_object == null)
165 return null;
167 return this.accessible_default_action_description;
169 set { this.accessible_default_action_description = value; }
172 [Localizable (true)]
173 [DefaultValue (null)]
174 public string AccessibleDescription {
175 get {
176 if (this.accessibility_object == null)
177 return null;
179 return this.AccessibilityObject.Description;
181 set { this.AccessibilityObject.description = value; }
184 [Localizable (true)]
185 [DefaultValue (null)]
186 public string AccessibleName {
187 get {
188 if (this.accessibility_object == null)
189 return null;
191 return this.AccessibilityObject.Name;
193 set { this.AccessibilityObject.Name = value; }
196 [DefaultValue (AccessibleRole.Default)]
197 public AccessibleRole AccessibleRole {
200 if (this.accessibility_object == null)
201 return AccessibleRole.Default;
203 return this.AccessibilityObject.Role;
205 set { this.AccessibilityObject.role = value; }
208 [DefaultValue (ToolStripItemAlignment.Left)]
209 public ToolStripItemAlignment Alignment {
210 get { return this.alignment; }
211 set {
212 if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
213 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
215 this.alignment = value;
219 [MonoTODO]
220 [Browsable (false)]
221 [DefaultValue (false)]
222 [EditorBrowsable (EditorBrowsableState.Advanced)]
223 public virtual bool AllowDrop {
224 get { return this.allow_drop; }
225 set { this.allow_drop = value; }
228 [Browsable (false)]
229 [DefaultValue (AnchorStyles.Top | AnchorStyles.Left)]
230 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
231 public AnchorStyles Anchor {
232 get { return this.anchor; }
233 set { this.anchor = value; }
236 [Localizable (true)]
237 [DefaultValue (true)]
238 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
239 [RefreshProperties (RefreshProperties.All)]
240 public bool AutoSize {
241 get { return this.auto_size; }
242 set {
243 this.auto_size = value;
244 this.CalculateAutoSize ();
248 [DefaultValue (false)]
249 public bool AutoToolTip {
250 get { return this.auto_tool_tip; }
251 set { this.auto_tool_tip = value; }
254 [Browsable (false)]
255 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
256 public bool Available {
257 get { return this.available; }
258 set {
259 if (this.available != value) {
260 available = value;
261 visible = value;
263 if (this.parent != null)
264 parent.PerformLayout ();
266 OnAvailableChanged (EventArgs.Empty);
267 OnVisibleChanged (EventArgs.Empty);
272 public virtual Color BackColor {
273 get { return this.back_color; }
274 set {
275 if (this.back_color != value) {
276 back_color = value;
277 OnBackColorChanged (EventArgs.Empty);
278 this.Invalidate ();
283 [Localizable (true)]
284 [DefaultValue (null)]
285 public virtual Image BackgroundImage {
286 get { return this.background_image; }
287 set {
288 if (this.background_image != value) {
289 this.background_image = value;
290 this.Invalidate ();
295 [Localizable (true)]
296 [DefaultValue (ImageLayout.Tile)]
297 public virtual ImageLayout BackgroundImageLayout {
298 get { return this.background_image_layout; }
299 set {
300 if (this.background_image_layout != value) {
301 this.background_image_layout = value;
302 this.Invalidate ();
307 [Browsable (false)]
308 public virtual Rectangle Bounds {
309 get { return this.bounds; }
312 [Browsable (false)]
313 public virtual bool CanSelect {
314 get { return this.can_select; }
317 [Browsable (false)]
318 public Rectangle ContentRectangle {
319 get {
320 // ToolStripLabels don't have a border
321 if (this is ToolStripLabel || this is ToolStripStatusLabel)
322 return new Rectangle (0, 0, this.bounds.Width, this.bounds.Height);
324 if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
325 return new Rectangle (2, 2, this.bounds.Width - 13, this.bounds.Height - 4);
327 return new Rectangle (2, 2, this.bounds.Width - 4, this.bounds.Height - 4);
331 public virtual ToolStripItemDisplayStyle DisplayStyle {
332 get { return this.display_style; }
333 set {
334 if (this.display_style != value) {
335 this.display_style = value;
336 this.CalculateAutoSize ();
337 OnDisplayStyleChanged (EventArgs.Empty);
338 if (this.Parent != null)
339 this.Parent.PerformLayout ();
344 [Browsable (false)]
345 public bool IsDisposed {
346 get { return this.is_disposed; }
349 [Browsable (false)]
350 [DefaultValue (DockStyle.None)]
351 public DockStyle Dock {
352 get { return this.dock; }
353 set {
354 if (this.dock != value) {
355 if (!Enum.IsDefined (typeof (DockStyle), value))
356 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for DockStyle", value));
358 this.dock = value;
359 this.CalculateAutoSize ();
364 [DefaultValue (false)]
365 public bool DoubleClickEnabled {
366 get { return this.double_click_enabled; }
367 set { this.double_click_enabled = value; }
370 [Localizable (true)]
371 [DefaultValue (true)]
372 public virtual bool Enabled {
373 get { return enabled; }
374 set {
375 if (this.enabled != value) {
376 this.enabled = value;
377 OnEnabledChanged (EventArgs.Empty);
378 this.Invalidate ();
383 [Localizable (true)]
384 public virtual Font Font
386 get { return this.font; }
387 set {
388 if (this.font != value) {
389 this.font = value;
390 this.CalculateAutoSize ();
391 this.OnFontChanged (EventArgs.Empty);
392 this.Invalidate ();
397 public virtual Color ForeColor {
398 get { return this.fore_color; }
399 set {
400 if (this.fore_color != value) {
401 this.fore_color = value;
402 this.OnForeColorChanged (EventArgs.Empty);
403 this.Invalidate ();
408 [Browsable (false)]
409 [EditorBrowsable (EditorBrowsableState.Always)]
410 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
411 public int Height {
412 get { return this.Size.Height; }
413 set {
414 this.bounds.Height = value;
415 this.explicit_size.Height = value;
417 if (this.Visible) {
418 this.CalculateAutoSize ();
419 this.OnBoundsChanged ();
420 this.Invalidate ();
425 [Localizable (true)]
426 public virtual Image Image {
427 get {
428 if (this.image != null)
429 return this.image;
431 if (this.image_index >= 0)
432 if (this.owner != null && this.owner.ImageList != null)
433 return this.owner.ImageList.Images[this.image_index];
436 if (!string.IsNullOrEmpty (this.image_key))
437 if (this.owner != null && this.owner.ImageList != null)
438 return this.owner.ImageList.Images[this.image_key];
440 return null;
442 set {
443 if (this.image != value) {
444 this.image = value;
445 this.image_index = -1;
446 this.image_key = string.Empty;
447 this.CalculateAutoSize ();
448 this.Invalidate ();
453 [Localizable (true)]
454 [DefaultValue (ContentAlignment.MiddleCenter)]
455 public ContentAlignment ImageAlign {
456 get { return this.image_align; }
457 set {
458 if (!Enum.IsDefined (typeof (ContentAlignment), value))
459 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
461 this.image_align = value;
462 this.Invalidate ();
466 [Localizable (true)]
467 [Browsable (false)]
468 [RelatedImageList ("Owner.ImageList")]
469 //[TypeConverter (typeof (NoneExcludedImageIndexConverter))]
470 [RefreshProperties (RefreshProperties.Repaint)]
471 [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
472 public int ImageIndex {
473 get { return this.image_index; }
474 set {
475 if (this.image_index != value) {
476 // Lamespec: MSDN says ArgumentException, tests say otherwise
477 if (value < -1)
478 throw new ArgumentOutOfRangeException ("ImageIndex cannot be less than -1");
480 this.image_index = value;
481 this.image = null;
482 this.image_key = string.Empty;
483 this.CalculateAutoSize ();
484 this.Invalidate ();
489 [Localizable (true)]
490 [Browsable (false)]
491 [RelatedImageList ("Owner.ImageList")]
492 [RefreshProperties (RefreshProperties.Repaint)]
493 [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
494 public string ImageKey {
495 get { return this.image_key; }
496 set {
497 if (this.image_key != value) {
498 this.image = null;
499 this.image_index = -1;
500 this.image_key = value;
501 this.CalculateAutoSize ();
502 this.Invalidate ();
507 [Localizable (true)]
508 [DefaultValue (ToolStripItemImageScaling.SizeToFit)]
509 public ToolStripItemImageScaling ImageScaling {
510 get { return this.image_scaling; }
511 set {
512 this.image_scaling = value;
513 this.CalculateAutoSize ();
514 this.Invalidate ();
518 [Localizable (true)]
519 public Color ImageTransparentColor {
520 get { return this.image_transparent_color; }
521 set { this.image_transparent_color = value; }
524 [Browsable (false)]
525 public bool IsOnDropDown {
526 get {
527 if (this.parent != null && this.parent is ToolStripDropDown)
528 return true;
530 return false;
534 [Browsable (false)]
535 public bool IsOnOverflow {
536 get { return this.placement == ToolStripItemPlacement.Overflow; }
539 public Padding Margin {
540 get { return this.margin; }
541 set {
542 this.margin = value;
543 this.CalculateAutoSize ();
547 [DefaultValue (MergeAction.Append)]
548 public MergeAction MergeAction {
549 get { return this.merge_action; }
550 set {
551 if (!Enum.IsDefined (typeof (MergeAction), value))
552 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for MergeAction", value));
554 this.merge_action = value;
558 [DefaultValue (-1)]
559 public int MergeIndex {
560 get { return this.merge_index; }
561 set { this.merge_index = value; }
564 [DefaultValue (null)]
565 [Browsable (false)]
566 public string Name {
567 get { return this.name; }
568 set { this.name = value; }
571 [DefaultValue (ToolStripItemOverflow.AsNeeded)]
572 public ToolStripItemOverflow Overflow {
573 get { return this.overflow; }
574 set {
575 if (this.overflow != value) {
576 if (!Enum.IsDefined (typeof (ToolStripItemOverflow), value))
577 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemOverflow", value));
579 this.overflow = value;
581 if (owner != null)
582 owner.PerformLayout ();
587 [Browsable (false)]
588 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
589 public ToolStrip Owner {
590 get { return this.owner; }
591 set {
592 if (this.owner != value) {
593 this.owner = value;
594 this.CalculateAutoSize ();
595 OnOwnerChanged (EventArgs.Empty);
600 [Browsable (false)]
601 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
602 public ToolStripItem OwnerItem {
603 get { return this.owner_item; }
606 public virtual Padding Padding {
607 get { return this.padding; }
608 set {
609 this.padding = value;
610 this.CalculateAutoSize ();
611 this.Invalidate ();
615 [Browsable (false)]
616 public ToolStripItemPlacement Placement {
617 get { return this.placement; }
620 [Browsable (false)]
621 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
622 public virtual bool Pressed { get { return this.is_pressed; } }
624 [MonoTODO ("Stub, not implemented")]
625 [Localizable (true)]
626 public virtual RightToLeft RightToLeft {
627 get { return this.right_to_left; }
628 set {
629 if (this.right_to_left != value) {
630 this.right_to_left = value;
631 this.OnRightToLeftChanged (EventArgs.Empty);
636 [Localizable (true)]
637 [DefaultValue (false)]
638 public bool RightToLeftAutoMirrorImage {
639 get { return this.right_to_left_auto_mirror_image; }
640 set {
641 if (this.right_to_left_auto_mirror_image != value) {
642 this.right_to_left_auto_mirror_image = value;
643 this.Invalidate ();
648 [Browsable (false)]
649 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
650 public virtual bool Selected { get { return this.is_selected; } }
652 [Localizable (true)]
653 public virtual Size Size {
654 get {
655 if (!this.AutoSize && this.explicit_size != Size.Empty)
656 return this.explicit_size;
658 return this.bounds.Size;
660 set {
661 this.bounds.Size = value;
662 this.explicit_size = value;
664 if (this.Visible) {
665 this.CalculateAutoSize ();
666 this.OnBoundsChanged ();
671 [Localizable (false)]
672 [Bindable (true)]
673 [DefaultValue (null)]
674 [TypeConverter (typeof (StringConverter))]
675 public Object Tag {
676 get { return this.tag; }
677 set { this.tag = value; }
680 [Localizable (true)]
681 [DefaultValue ("")]
682 public virtual string Text
684 get { return this.text; }
685 set {
686 if (this.text != value) {
687 this.text = value;
688 this.CalculateAutoSize ();
689 this.OnTextChanged (EventArgs.Empty);
690 this.Invalidate ();
695 [Localizable (true)]
696 [DefaultValue (ContentAlignment.MiddleCenter)]
697 public virtual ContentAlignment TextAlign {
698 get { return this.text_align; }
699 set {
700 if (!Enum.IsDefined (typeof (ContentAlignment), value))
701 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
702 this.text_align = value;
703 this.Invalidate ();
707 [Localizable (true)]
708 [DefaultValue (TextImageRelation.ImageBeforeText)]
709 public TextImageRelation TextImageRelation {
710 get { return this.text_image_relation; }
711 set {
712 this.text_image_relation = value;
713 this.CalculateAutoSize ();
714 this.Invalidate ();
718 [Localizable (true)]
719 [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
720 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
721 public string ToolTipText {
722 get { return this.tool_tip_text; }
723 set { this.tool_tip_text = value; }
726 [Localizable (true)]
727 public bool Visible {
728 get {
729 if (this.parent == null)
730 return false;
732 return this.visible && this.parent.Visible;
734 set {
735 if (this.visible != value) {
736 this.available = value;
737 this.SetVisibleCore (value);
742 [Browsable (false)]
743 [EditorBrowsable (EditorBrowsableState.Always)]
744 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
745 public int Width {
746 get { return this.Size.Width; }
747 set {
748 this.bounds.Width = value;
749 this.explicit_size.Width = value;
751 if (this.Visible) {
752 this.CalculateAutoSize ();
753 this.OnBoundsChanged ();
754 this.Invalidate ();
758 #endregion
760 #region Protected Properties
761 protected virtual bool DefaultAutoToolTip { get { return false; } }
762 protected virtual ToolStripItemDisplayStyle DefaultDisplayStyle { get { return ToolStripItemDisplayStyle.ImageAndText; } }
763 protected internal virtual Padding DefaultMargin { get { return new Padding (0, 1, 0, 2); } }
764 protected virtual Padding DefaultPadding { get { return new Padding (); } }
765 protected virtual Size DefaultSize { get { return new Size (23, 23); } }
766 protected internal virtual bool DismissWhenClicked { get { return true; } }
767 [Browsable (false)]
768 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
769 protected internal ToolStrip Parent {
770 get { return this.parent; }
771 set {
772 if (this.parent != value) {
773 ToolStrip old_parent = this.parent;
774 this.parent = value;
775 OnParentChanged(old_parent, this.parent);
779 protected internal virtual bool ShowKeyboardCues { get { return false; } }
780 #endregion
782 #region Public Methods
783 public ToolStrip GetCurrentParent ()
785 return this.parent;
788 public virtual Size GetPreferredSize (Size constrainingSize)
790 return this.CalculatePreferredSize (constrainingSize);
793 public void Invalidate ()
795 if (parent != null)
796 parent.Invalidate (this.bounds);
799 public void Invalidate (Rectangle r)
801 if (parent != null)
802 parent.Invalidate (r);
805 public void PerformClick ()
807 this.OnClick (EventArgs.Empty);
810 [EditorBrowsable (EditorBrowsableState.Never)]
811 public virtual void ResetBackColor () { this.BackColor = Control.DefaultBackColor; }
813 [EditorBrowsable (EditorBrowsableState.Never)]
814 public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
816 [EditorBrowsable (EditorBrowsableState.Never)]
817 public virtual void ResetFont () { this.font = new Font ("Tahoma", 8.25f); }
819 [EditorBrowsable (EditorBrowsableState.Never)]
820 public virtual void ResetForeColor () { this.ForeColor = Control.DefaultForeColor; }
822 [EditorBrowsable (EditorBrowsableState.Never)]
823 public virtual void ResetImage () { this.image = null; }
825 [EditorBrowsable (EditorBrowsableState.Never)]
826 public void ResetMargin () { this.margin = this.DefaultMargin; }
828 [EditorBrowsable (EditorBrowsableState.Never)]
829 public void ResetPadding () { this.padding = this.DefaultPadding; }
831 public void Select ()
833 if (!this.is_selected && this.CanSelect) {
834 this.is_selected = true;
835 this.Invalidate ();
836 this.Parent.NotifySelectedChanged (this);
840 public override string ToString ()
842 return this.text;
844 #endregion
846 #region Protected Methods
847 [EditorBrowsable (EditorBrowsableState.Advanced)]
848 protected virtual AccessibleObject CreateAccessibilityInstance ()
850 return new ToolStripItemAccessibleObject (this);
853 protected override void Dispose (bool disposing)
855 if (!is_disposed && disposing)
856 is_disposed = true;
858 base.Dispose (disposing);
861 protected internal virtual bool IsInputChar (char charCode)
863 return false;
866 protected internal virtual bool IsInputKey (Keys keyData)
868 return false;
871 protected virtual void OnAvailableChanged (EventArgs e)
873 EventHandler eh = (EventHandler)(Events [AvailableChangedEvent]);
874 if (eh != null)
875 eh (this, e);
878 [EditorBrowsable (EditorBrowsableState.Advanced)]
879 protected virtual void OnBackColorChanged (EventArgs e)
881 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
882 if (eh != null)
883 eh (this, e);
886 protected virtual void OnBoundsChanged ()
888 OnLayout (new LayoutEventArgs(null, string.Empty));
891 protected virtual void OnClick (EventArgs e)
893 EventHandler eh = (EventHandler)(Events [ClickEvent]);
894 if (eh != null)
895 eh (this, e);
898 [EditorBrowsable (EditorBrowsableState.Advanced)]
899 protected virtual void OnDisplayStyleChanged (EventArgs e)
901 EventHandler eh = (EventHandler)(Events [DisplayStyleChangedEvent]);
902 if (eh != null)
903 eh (this, e);
906 protected virtual void OnDoubleClick (EventArgs e)
908 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
909 if (eh != null)
910 eh (this, e);
912 if (!double_click_enabled)
913 OnClick (e);
916 void IDropTarget.OnDragDrop (DragEventArgs e)
918 // XXX
921 void IDropTarget.OnDragEnter (DragEventArgs e)
923 // XXX
926 void IDropTarget.OnDragLeave (EventArgs e)
928 // XXX
931 void IDropTarget.OnDragOver (DragEventArgs e)
933 // XXX
936 protected virtual void OnEnabledChanged (EventArgs e)
938 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
939 if (eh != null)
940 eh (this, e);
943 [EditorBrowsable (EditorBrowsableState.Advanced)]
944 protected virtual void OnFontChanged (EventArgs e)
948 [EditorBrowsable (EditorBrowsableState.Advanced)]
949 protected virtual void OnForeColorChanged (EventArgs e)
951 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
952 if (eh != null)
953 eh (this, e);
956 protected virtual void OnLayout (LayoutEventArgs e)
960 protected virtual void OnLocationChanged (EventArgs e)
962 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
963 if (eh != null)
964 eh (this, e);
967 protected virtual void OnMouseDown (MouseEventArgs e)
969 if (this.Enabled) {
970 this.is_pressed = true;
971 this.Invalidate ();
973 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
974 if (eh != null)
975 eh (this, e);
979 protected virtual void OnMouseEnter (EventArgs e)
981 this.Select ();
983 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
984 if (eh != null)
985 eh (this, e);
988 protected virtual void OnMouseHover (EventArgs e)
990 if (this.Enabled) {
991 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
992 if (eh != null)
993 eh (this, e);
997 protected virtual void OnMouseLeave (EventArgs e)
999 if (this.CanSelect) {
1000 this.is_selected = false;
1001 this.is_pressed = false;
1002 this.Invalidate ();
1005 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
1006 if (eh != null)
1007 eh (this, e);
1010 protected virtual void OnMouseMove (MouseEventArgs e)
1012 if (this.Enabled) {
1013 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
1014 if (eh != null)
1015 eh (this, e);
1019 protected virtual void OnMouseUp (MouseEventArgs e)
1021 if (this.Enabled) {
1022 this.is_pressed = false;
1023 this.Invalidate ();
1025 if (this.IsOnDropDown)
1026 if (!(this is ToolStripDropDownItem) || !(this as ToolStripDropDownItem).HasDropDownItems || (this as ToolStripDropDownItem).DropDown.Visible == false) {
1027 if ((this.Parent as ToolStripDropDown).OwnerItem != null)
1028 ((this.Parent as ToolStripDropDown).OwnerItem as ToolStripDropDownItem).HideDropDown ();
1029 else
1030 (this.Parent as ToolStripDropDown).Hide ();
1034 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
1035 if (eh != null)
1036 eh (this, e);
1040 protected virtual void OnOwnerChanged (EventArgs e)
1042 EventHandler eh = (EventHandler)(Events [OwnerChangedEvent]);
1043 if (eh != null)
1044 eh (this, e);
1047 [EditorBrowsable (EditorBrowsableState.Advanced)]
1048 protected internal virtual void OnOwnerFontChanged (EventArgs e)
1052 protected virtual void OnPaint (PaintEventArgs e)
1054 if (this.parent != null)
1055 this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
1057 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
1058 if (eh != null)
1059 eh (this, e);
1062 // This is never called.
1063 [EditorBrowsable (EditorBrowsableState.Advanced)]
1064 protected virtual void OnParentBackColorChanged (EventArgs e)
1068 protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
1070 if (oldParent != null)
1071 oldParent.PerformLayout ();
1073 if (newParent != null)
1074 newParent.PerformLayout ();
1077 protected internal virtual void OnParentEnabledChanged (EventArgs e)
1079 this.OnEnabledChanged (e);
1082 // This is never called.
1083 [EditorBrowsable (EditorBrowsableState.Advanced)]
1084 protected virtual void OnParentForeColorChanged (EventArgs e)
1088 [EditorBrowsable (EditorBrowsableState.Advanced)]
1089 protected internal virtual void OnParentRightToLeftChanged (EventArgs e)
1091 this.OnRightToLeftChanged (e);
1094 protected virtual void OnRightToLeftChanged (EventArgs e)
1096 EventHandler eh = (EventHandler)(Events[RightToLeftChangedEvent]);
1097 if (eh != null)
1098 eh (this, e);
1101 [EditorBrowsable (EditorBrowsableState.Advanced)]
1102 protected virtual void OnTextChanged (EventArgs e)
1104 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
1105 if (eh != null)
1106 eh (this, e);
1109 protected virtual void OnVisibleChanged (EventArgs e)
1111 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
1112 if (eh != null)
1113 eh (this, e);
1116 protected internal virtual bool ProcessCmdKey (ref Message m, Keys keyData)
1118 return false;
1121 protected internal virtual bool ProcessDialogKey (Keys keyData)
1123 if (this.Selected && keyData == Keys.Enter) {
1124 this.FireEvent (EventArgs.Empty, ToolStripItemEventType.Click);
1125 return true;
1128 return false;
1131 // ProcessMnemonic will only be called if we are supposed to handle
1132 // it. None of that fancy "thinking" needed!
1133 protected internal virtual bool ProcessMnemonic (char charCode)
1135 this.PerformClick ();
1136 return true;
1139 protected internal virtual void SetBounds (Rectangle bounds)
1141 if (this.bounds != bounds) {
1142 this.bounds = bounds;
1143 OnBoundsChanged ();
1147 protected virtual void SetVisibleCore (bool visible)
1149 this.visible = visible;
1150 this.OnVisibleChanged (EventArgs.Empty);
1151 this.Invalidate ();
1153 #endregion
1155 #region Public Events
1156 static object AvailableChangedEvent = new object ();
1157 static object BackColorChangedEvent = new object ();
1158 static object ClickEvent = new object ();
1159 static object DisplayStyleChangedEvent = new object ();
1160 static object DoubleClickEvent = new object ();
1161 static object EnabledChangedEvent = new object ();
1162 static object ForeColorChangedEvent = new object ();
1163 static object LocationChangedEvent = new object ();
1164 static object MouseDownEvent = new object ();
1165 static object MouseEnterEvent = new object ();
1166 static object MouseHoverEvent = new object ();
1167 static object MouseLeaveEvent = new object ();
1168 static object MouseMoveEvent = new object ();
1169 static object MouseUpEvent = new object ();
1170 static object OwnerChangedEvent = new object ();
1171 static object PaintEvent = new object ();
1172 static object RightToLeftChangedEvent = new object ();
1173 static object TextChangedEvent = new object ();
1174 static object VisibleChangedEvent = new object ();
1176 [Browsable (false)]
1177 public event EventHandler AvailableChanged {
1178 add { Events.AddHandler (AvailableChangedEvent, value); }
1179 remove {Events.RemoveHandler (AvailableChangedEvent, value); }
1182 public event EventHandler BackColorChanged {
1183 add { Events.AddHandler (BackColorChangedEvent, value); }
1184 remove {Events.RemoveHandler (BackColorChangedEvent, value); }
1187 public event EventHandler Click {
1188 add { Events.AddHandler (ClickEvent, value); }
1189 remove {Events.RemoveHandler (ClickEvent, value); }
1192 public event EventHandler DisplayStyleChanged {
1193 add { Events.AddHandler (DisplayStyleChangedEvent, value); }
1194 remove {Events.RemoveHandler (DisplayStyleChangedEvent, value); }
1197 public event EventHandler DoubleClick {
1198 add { Events.AddHandler (DoubleClickEvent, value); }
1199 remove {Events.RemoveHandler (DoubleClickEvent, value); }
1202 public event EventHandler EnabledChanged {
1203 add { Events.AddHandler (EnabledChangedEvent, value); }
1204 remove {Events.RemoveHandler (EnabledChangedEvent, value); }
1207 public event EventHandler ForeColorChanged {
1208 add { Events.AddHandler (ForeColorChangedEvent, value); }
1209 remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
1212 public event EventHandler LocationChanged {
1213 add { Events.AddHandler (LocationChangedEvent, value); }
1214 remove {Events.RemoveHandler (LocationChangedEvent, value); }
1217 public event MouseEventHandler MouseDown {
1218 add { Events.AddHandler (MouseDownEvent, value); }
1219 remove {Events.RemoveHandler (MouseDownEvent, value); }
1222 public event EventHandler MouseEnter {
1223 add { Events.AddHandler (MouseEnterEvent, value); }
1224 remove {Events.RemoveHandler (MouseEnterEvent, value); }
1227 public event EventHandler MouseHover {
1228 add { Events.AddHandler (MouseHoverEvent, value); }
1229 remove {Events.RemoveHandler (MouseHoverEvent, value); }
1232 public event EventHandler MouseLeave {
1233 add { Events.AddHandler (MouseLeaveEvent, value); }
1234 remove {Events.RemoveHandler (MouseLeaveEvent, value); }
1237 public event MouseEventHandler MouseMove {
1238 add { Events.AddHandler (MouseMoveEvent, value); }
1239 remove {Events.RemoveHandler (MouseMoveEvent, value); }
1242 public event MouseEventHandler MouseUp {
1243 add { Events.AddHandler (MouseUpEvent, value); }
1244 remove {Events.RemoveHandler (MouseUpEvent, value); }
1247 public event EventHandler OwnerChanged {
1248 add { Events.AddHandler (OwnerChangedEvent, value); }
1249 remove {Events.RemoveHandler (OwnerChangedEvent, value); }
1252 public event PaintEventHandler Paint {
1253 add { Events.AddHandler (PaintEvent, value); }
1254 remove {Events.RemoveHandler (PaintEvent, value); }
1257 public event EventHandler RightToLeftChanged {
1258 add { Events.AddHandler (RightToLeftChangedEvent, value); }
1259 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
1262 public event EventHandler TextChanged {
1263 add { Events.AddHandler (TextChangedEvent, value); }
1264 remove {Events.RemoveHandler (TextChangedEvent, value); }
1267 public event EventHandler VisibleChanged {
1268 add { Events.AddHandler (VisibleChangedEvent, value); }
1269 remove {Events.RemoveHandler (VisibleChangedEvent, value); }
1271 #endregion
1273 #region Internal Methods
1274 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, ContentAlignment align)
1276 int x = 0;
1277 int y = 0;
1279 if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft)
1280 x = outer.X;
1281 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter)
1282 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
1283 else if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight)
1284 x = outer.Right - inner.Width;
1285 if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight)
1286 y = outer.Y;
1287 else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight)
1288 y = outer.Y + (outer.Height - inner.Height) / 2;
1289 else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomRight || align == ContentAlignment.BottomLeft)
1290 y = outer.Bottom - inner.Height;
1292 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
1295 internal void CalculateAutoSize ()
1297 this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty: this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
1299 if (!this.auto_size || this is ToolStripControlHost)
1300 return;
1301 //this.text_size.Width += 6;
1303 Size final_size = this.CalculatePreferredSize (Size.Empty);
1305 if (final_size != this.Size) {
1306 this.bounds.Width = final_size.Width;
1307 if (this.parent != null)
1308 this.parent.PerformLayout ();
1312 internal virtual Size CalculatePreferredSize (Size constrainingSize)
1314 if (!this.auto_size)
1315 return this.explicit_size;
1317 Size preferred_size = this.DefaultSize;
1319 switch (this.display_style) {
1320 case ToolStripItemDisplayStyle.Text:
1321 int width = text_size.Width + this.padding.Horizontal;
1322 int height = text_size.Height + this.padding.Vertical;
1323 preferred_size = new Size (width, height);
1324 break;
1325 case ToolStripItemDisplayStyle.Image:
1326 if (this.Image == null)
1327 preferred_size = this.DefaultSize;
1328 else {
1329 switch (this.image_scaling) {
1330 case ToolStripItemImageScaling.None:
1331 preferred_size = this.Image.Size;
1332 break;
1333 case ToolStripItemImageScaling.SizeToFit:
1334 if (this.parent == null)
1335 preferred_size = this.Image.Size;
1336 else
1337 preferred_size = this.parent.ImageScalingSize;
1338 break;
1341 break;
1342 case ToolStripItemDisplayStyle.ImageAndText:
1343 int width2 = text_size.Width + this.padding.Horizontal;
1344 int height2 = text_size.Height + this.padding.Vertical;
1346 if (this.Image != null) {
1347 switch (this.text_image_relation) {
1348 case TextImageRelation.Overlay:
1349 width2 = Math.Max (width2, this.Image.Width);
1350 height2 = Math.Max (height2, this.Image.Height);
1351 break;
1352 case TextImageRelation.ImageAboveText:
1353 case TextImageRelation.TextAboveImage:
1354 width2 = Math.Max (width2, this.Image.Width);
1355 height2 += this.Image.Height;
1356 break;
1357 case TextImageRelation.ImageBeforeText:
1358 case TextImageRelation.TextBeforeImage:
1359 height2 = Math.Max (height2, this.Image.Height);
1360 width2 += this.Image.Width;
1361 break;
1365 preferred_size = new Size (width2, height2);
1366 break;
1369 if (!(this is ToolStripLabel)) { // Everything but labels have a border
1370 preferred_size.Height += 4;
1371 preferred_size.Width += 4;
1374 // Account for ToolStripDropDownButton's drop down arrow
1375 if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
1376 preferred_size.Width += 9;
1378 return preferred_size;
1381 internal void CalculateTextAndImageRectangles (out Rectangle text_rect, out Rectangle image_rect)
1383 this.CalculateTextAndImageRectangles (this.ContentRectangle, out text_rect, out image_rect);
1386 internal void CalculateTextAndImageRectangles (Rectangle contentRectangle, out Rectangle text_rect, out Rectangle image_rect)
1388 text_rect = Rectangle.Empty;
1389 image_rect = Rectangle.Empty;
1391 switch (this.display_style) {
1392 case ToolStripItemDisplayStyle.None:
1393 break;
1394 case ToolStripItemDisplayStyle.Text:
1395 if (this.text != string.Empty)
1396 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1397 break;
1398 case ToolStripItemDisplayStyle.Image:
1399 if (this.Image != null)
1400 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1401 break;
1402 case ToolStripItemDisplayStyle.ImageAndText:
1403 if (this.text != string.Empty && this.Image == null)
1404 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1405 else if (this.text == string.Empty && this.Image != null)
1406 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1407 else if (this.text == string.Empty && this.Image == null)
1408 break;
1409 else {
1410 Rectangle text_area;
1411 Rectangle image_area;
1413 switch (this.text_image_relation) {
1414 case TextImageRelation.Overlay:
1415 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1416 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1417 break;
1418 case TextImageRelation.ImageAboveText:
1419 text_area = new Rectangle (contentRectangle.Left, contentRectangle.Bottom - (text_size.Height - 4), contentRectangle.Width, text_size.Height - 4);
1420 image_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, contentRectangle.Height - text_area.Height);
1422 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1423 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1424 break;
1425 case TextImageRelation.TextAboveImage:
1426 text_area = new Rectangle (contentRectangle.Left, contentRectangle.Top, contentRectangle.Width, text_size.Height - 4);
1427 image_area = new Rectangle (contentRectangle.Left, text_area.Bottom, contentRectangle.Width, contentRectangle.Height - text_area.Height);
1429 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1430 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1431 break;
1432 case TextImageRelation.ImageBeforeText:
1433 LayoutTextBeforeOrAfterImage (contentRectangle, false, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1434 break;
1435 case TextImageRelation.TextBeforeImage:
1436 LayoutTextBeforeOrAfterImage (contentRectangle, true, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1437 break;
1440 break;
1444 internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
1446 if (is_selected) {
1447 this.is_selected = false;
1448 this.Invalidate ();
1452 internal virtual ToolStrip GetTopLevelToolStrip ()
1454 if (this.Parent != null)
1455 return this.Parent.GetTopLevelToolStrip ();
1457 return null;
1460 private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, ContentAlignment textAlign, ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
1462 int element_spacing = 0; // Spacing between the Text and the Image
1463 int total_width = textSize.Width + element_spacing + imageSize.Width;
1464 int excess_width = totalArea.Width - total_width;
1465 int offset = 0;
1467 Rectangle final_text_rect;
1468 Rectangle final_image_rect;
1470 HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
1471 HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
1473 if (h_image == HorizontalAlignment.Left)
1474 offset = 0;
1475 else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
1476 offset = excess_width;
1477 else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
1478 offset += (int)(excess_width / 3);
1479 else
1480 offset += (int)(2 * (excess_width / 3));
1482 if (textFirst) {
1483 final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
1484 final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
1485 } else {
1486 final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
1487 final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
1490 textRect = final_text_rect;
1491 imageRect = final_image_rect;
1494 private HorizontalAlignment GetHorizontalAlignment (ContentAlignment align)
1496 switch (align) {
1497 case ContentAlignment.BottomLeft:
1498 case ContentAlignment.MiddleLeft:
1499 case ContentAlignment.TopLeft:
1500 return HorizontalAlignment.Left;
1501 case ContentAlignment.BottomCenter:
1502 case ContentAlignment.MiddleCenter:
1503 case ContentAlignment.TopCenter:
1504 return HorizontalAlignment.Center;
1505 case ContentAlignment.BottomRight:
1506 case ContentAlignment.MiddleRight:
1507 case ContentAlignment.TopRight:
1508 return HorizontalAlignment.Right;
1511 return HorizontalAlignment.Left;
1514 internal Size GetImageSize ()
1516 if (this.Image == null)
1517 return Size.Empty;
1519 if (this.image_scaling == ToolStripItemImageScaling.None)
1520 return this.Image.Size;
1522 if (this.Parent == null)
1523 return Size.Empty;
1525 return this.Parent.ImageScalingSize;
1528 internal string GetToolTip ()
1530 if (this.auto_tool_tip && string.IsNullOrEmpty (this.tool_tip_text))
1531 return this.text;
1533 return this.tool_tip_text;
1536 internal void FireEvent (EventArgs e, ToolStripItemEventType met)
1538 // If we're disabled, don't fire any of these events, except Paint
1539 if (!this.Enabled && met != ToolStripItemEventType.Paint)
1540 return;
1542 switch (met) {
1543 case ToolStripItemEventType.MouseUp:
1544 this.OnMouseUp ((MouseEventArgs)e);
1545 this.HandleClick (e);
1546 break;
1547 case ToolStripItemEventType.MouseDown:
1548 this.OnMouseDown ((MouseEventArgs)e);
1549 break;
1550 case ToolStripItemEventType.MouseEnter:
1551 this.OnMouseEnter (e);
1552 break;
1553 case ToolStripItemEventType.MouseHover:
1554 this.OnMouseHover (e);
1555 break;
1556 case ToolStripItemEventType.MouseLeave:
1557 this.OnMouseLeave (e);
1558 break;
1559 case ToolStripItemEventType.MouseMove:
1560 this.OnMouseMove ((MouseEventArgs)e);
1561 break;
1562 case ToolStripItemEventType.Paint:
1563 this.OnPaint ((PaintEventArgs)e);
1564 break;
1565 case ToolStripItemEventType.Click:
1566 this.HandleClick (e);
1567 break;
1571 internal virtual void HandleClick (EventArgs e)
1573 this.Parent.HandleItemClick (this);
1574 this.OnClick (e);
1577 internal virtual void SetPlacement (ToolStripItemPlacement placement)
1579 this.placement = placement;
1582 internal bool InternalVisible {
1583 get { return this.visible; }
1584 set { this.visible = value; }
1587 internal Point Location {
1588 get { return this.bounds.Location; }
1589 set {
1590 if (this.bounds.Location != value) {
1591 this.bounds.Location = value;
1592 this.OnLocationChanged (EventArgs.Empty);
1597 internal int Top {
1598 get { return this.bounds.Y; }
1599 set {
1600 if (this.bounds.Y != value) {
1601 this.bounds.Y = value;
1602 this.OnLocationChanged (EventArgs.Empty);
1607 internal int Left {
1608 get { return this.bounds.X; }
1609 set {
1610 if (this.bounds.X != value) {
1611 this.bounds.X = value;
1612 this.OnLocationChanged (EventArgs.Empty);
1617 internal int Right { get { return this.bounds.Right; } }
1618 internal int Bottom { get { return this.bounds.Bottom; } }
1619 #endregion
1621 public class ToolStripItemAccessibleObject : AccessibleObject
1623 private ToolStripItem owner_item;
1625 public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
1627 if (ownerItem == null)
1628 throw new ArgumentNullException ("ownerItem");
1630 this.owner_item = ownerItem;
1631 base.default_action = string.Empty;
1632 base.keyboard_shortcut = string.Empty;
1633 base.name = string.Empty;
1634 base.value = string.Empty;
1637 #region Public Properties
1638 public override Rectangle Bounds {
1639 get {
1640 return owner_item.Visible ? owner_item.Bounds : Rectangle.Empty;
1644 public override string DefaultAction {
1645 get { return base.DefaultAction; }
1648 public override string Description {
1649 get { return base.Description; }
1652 public override string Help {
1653 get { return base.Help; }
1656 public override string KeyboardShortcut {
1657 get { return base.KeyboardShortcut; }
1660 public override string Name {
1661 get {
1662 if (base.name == string.Empty)
1663 return owner_item.Text;
1665 return base.Name;
1667 set { base.Name = value; }
1670 public override AccessibleObject Parent {
1671 get { return base.Parent; }
1674 public override AccessibleRole Role {
1675 get { return base.Role; }
1678 public override AccessibleStates State {
1679 get { return base.State; }
1681 #endregion
1683 #region Public Methods
1684 public void AddState (AccessibleStates state)
1686 base.state = state;
1689 public override void DoDefaultAction ()
1691 base.DoDefaultAction ();
1694 public override int GetHelpTopic (out string FileName)
1696 return base.GetHelpTopic (out FileName);
1699 public override AccessibleObject Navigate (AccessibleNavigation navdir)
1701 return base.Navigate (navdir);
1704 public override string ToString ()
1706 return string.Format ("ToolStripItemAccessibleObject: Owner = {0}", owner_item.ToString());
1708 #endregion
1712 #endif