Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripItem.cs
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.
22 //
23 // Copyright (c) 2006 Jonathan Pobst
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28
29
30 using System;
31 using System.Drawing;
32 using System.ComponentModel;
33 using System.Runtime.InteropServices;
34
35 namespace System.Windows.Forms
36 {
37         [DefaultEvent ("Click")]
38         [DefaultProperty ("Text")]
39         [DesignTimeVisible (false)]
40         [ToolboxItem (false)]
41         [Designer ("System.Windows.Forms.Design.ToolStripItemDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42         public abstract class ToolStripItem : Component, IDropTarget, IComponent, IDisposable
43         {
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;
61                 private bool enabled;
62                 private Size explicit_size;
63                 private Font font;
64                 private Color fore_color;
65                 private Image image;
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;
77                 private string name;
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;
85                 private Object tag;
86                 private string text;
87                 private ContentAlignment text_align;
88                 private ToolStripTextDirection text_direction;
89                 private TextImageRelation text_image_relation;
90                 private string tool_tip_text;
91                 private bool visible;
92
93                 private EventHandler frame_handler;     // For animating images
94                 private ToolStrip parent;
95                 private Size text_size;
96                 #endregion
97
98                 #region Public Constructors
99                 protected ToolStripItem ()
100                         : this (String.Empty, null, null, String.Empty)
101                 {
102                 }
103
104                 protected ToolStripItem (string text, Image image, EventHandler onClick)
105                         : this (text, image, onClick, String.Empty)
106                 {
107                 }
108
109                 protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
110                 {
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;
121                         this.enabled = true;
122                         this.fore_color = Color.Empty;
123                         this.image = image;
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;
132                         this.name = name;
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;
138                         this.text = text;
139                         this.text_align = ContentAlignment.MiddleCenter;
140                         this.text_direction = DefaultTextDirection;
141                         this.text_image_relation = TextImageRelation.ImageBeforeText;
142                         this.visible = true;
143
144                         this.Click += onClick;
145                         OnLayout (new LayoutEventArgs (null, string.Empty));
146                 }
147                 #endregion
148
149                 #region Public Properties
150                 [Browsable (false)]
151                 [EditorBrowsable (EditorBrowsableState.Advanced)]
152                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
153                 public AccessibleObject AccessibilityObject {
154                         get { 
155                                 if (this.accessibility_object == null)
156                                         this.accessibility_object = CreateAccessibilityInstance ();
157                                         
158                                 return this.accessibility_object;
159                         }
160                 }
161
162                 [Browsable (false)]
163                 [EditorBrowsable (EditorBrowsableState.Advanced)]
164                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
165                 public string AccessibleDefaultActionDescription {
166                         get {
167                                 if (this.accessibility_object == null)
168                                         return null;
169                                 
170                                 return this.accessible_default_action_description;
171                         }
172                         set { this.accessible_default_action_description = value; }
173                 }
174
175                 [Localizable (true)]
176                 [DefaultValue (null)]
177                 public string AccessibleDescription {
178                         get {
179                                 if (this.accessibility_object == null)
180                                         return null;
181                                 
182                                 return this.AccessibilityObject.Description;
183                         }
184                         set { this.AccessibilityObject.description = value; }
185                 }
186
187                 [Localizable (true)]
188                 [DefaultValue (null)]
189                 public string AccessibleName {
190                         get { 
191                                 if (this.accessibility_object == null)
192                                         return null;
193                                         
194                                 return this.AccessibilityObject.Name; 
195                         }
196                         set { this.AccessibilityObject.Name = value; }
197                 }
198                 
199                 [DefaultValue (AccessibleRole.Default)]
200                 public AccessibleRole AccessibleRole {
201                         get
202                         {
203                                 if (this.accessibility_object == null)
204                                         return AccessibleRole.Default;
205                                 
206                                 return this.AccessibilityObject.Role;
207                         }
208                         set { this.AccessibilityObject.role = value; }
209                 }
210                 
211                 [DefaultValue (ToolStripItemAlignment.Left)]
212                 public ToolStripItemAlignment Alignment {
213                         get { return this.alignment; }
214                         set {
215                                 if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
216                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
217
218                                 if (this.alignment != value) {
219                                         this.alignment = value;
220                                         this.CalculateAutoSize (); 
221                                 }
222                         }
223                 }
224
225                 [MonoTODO ("Stub, does nothing")]
226                 [Browsable (false)]
227                 [DefaultValue (false)]
228                 [EditorBrowsable (EditorBrowsableState.Advanced)]
229                 public virtual bool AllowDrop {
230                         get { return this.allow_drop; }
231                         set { this.allow_drop = value; }
232                 }
233                 
234                 [Browsable (false)]
235                 [DefaultValue (AnchorStyles.Top | AnchorStyles.Left)]
236                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
237                 public AnchorStyles Anchor {
238                         get { return this.anchor; }
239                         set { this.anchor = value; }
240                 }
241                         
242                 [Localizable (true)]
243                 [DefaultValue (true)]
244                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
245                 [RefreshProperties (RefreshProperties.All)]
246                 public bool AutoSize {
247                         get { return this.auto_size; }
248                         set { 
249                                 this.auto_size = value; 
250                                 this.CalculateAutoSize (); 
251                         }
252                 }
253
254                 [DefaultValue (false)]
255                 public bool AutoToolTip {
256                         get { return this.auto_tool_tip; }
257                         set { this.auto_tool_tip = value; }
258                 }
259
260                 [Browsable (false)]
261                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
262                 public bool Available {
263                         get { return this.available; }
264                         set {
265                                 if (this.available != value) {
266                                         available = value;
267                                         visible = value;
268
269                                         if (this.parent != null)
270                                                 parent.PerformLayout (); 
271                                                 
272                                         OnAvailableChanged (EventArgs.Empty); 
273                                         OnVisibleChanged (EventArgs.Empty);
274                                 }
275                         }
276                 }
277
278                 public virtual Color BackColor {
279                         get {
280                                 if (back_color != Color.Empty)
281                                         return back_color;
282
283                                 if (Parent != null)
284                                         return parent.BackColor;
285
286                                 return Control.DefaultBackColor;
287                         }
288                         set {
289                                 if (this.back_color != value) {
290                                         back_color = value;
291                                         OnBackColorChanged (EventArgs.Empty);
292                                         this.Invalidate ();
293                                 }
294                         }
295                 }
296
297                 [Localizable (true)]
298                 [DefaultValue (null)]
299                 public virtual Image BackgroundImage {
300                         get { return this.background_image; }
301                         set { 
302                                 if (this.background_image != value) {
303                                         this.background_image = value;
304                                         this.Invalidate ();
305                                 }
306                         }
307                 }
308
309                 [Localizable (true)]
310                 [DefaultValue (ImageLayout.Tile)]
311                 public virtual ImageLayout BackgroundImageLayout {
312                         get { return this.background_image_layout; }
313                         set { 
314                                 if (this.background_image_layout != value) {
315                                         this.background_image_layout = value;
316                                         this.Invalidate (); 
317                                 }
318                         }
319                 }
320
321                 [Browsable (false)]
322                 public virtual Rectangle Bounds {
323                         get { return this.bounds; }
324                 }
325
326                 [Browsable (false)]
327                 public virtual bool CanSelect {
328                         get { return this.can_select; }
329                 }
330
331                 [Browsable (false)]
332                 public Rectangle ContentRectangle {
333                         get {
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);
337
338                                 if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
339                                         return new Rectangle (2, 2, this.bounds.Width - 13, this.bounds.Height - 4);
340
341                                 return new Rectangle (2, 2, this.bounds.Width - 4, this.bounds.Height - 4);
342                         }
343                 }
344
345                 public virtual ToolStripItemDisplayStyle DisplayStyle {
346                         get { return this.display_style; }
347                         set {
348                                 if (this.display_style != value) {
349                                         this.display_style = value; 
350                                         this.CalculateAutoSize (); 
351                                         OnDisplayStyleChanged (EventArgs.Empty);
352                                 }
353                         }
354                 }
355
356                 [Browsable (false)]
357                 public bool IsDisposed {
358                         get { return this.is_disposed; }
359                 }
360                 
361                 [Browsable (false)]
362                 [DefaultValue (DockStyle.None)]
363                 public DockStyle Dock {
364                         get { return this.dock; }
365                         set {
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));
369
370                                         this.dock = value;
371                                         this.CalculateAutoSize ();
372                                 }
373                         }
374                 }
375
376                 [DefaultValue (false)]
377                 public bool DoubleClickEnabled {
378                         get { return this.double_click_enabled; }
379                         set { this.double_click_enabled = value; }
380                 }
381
382                 [Localizable (true)]
383                 [DefaultValue (true)]
384                 public virtual bool Enabled {
385                         get { 
386                                 if (Parent != null)
387                                         if (!Parent.Enabled)
388                                                 return false;
389
390                                 if (Owner != null)
391                                         if (!Owner.Enabled)
392                                                 return false;
393                                                 
394                                 return enabled;
395                         }
396                         set { 
397                                 if (this.enabled != value) {
398                                         this.enabled = value; 
399                                         OnEnabledChanged (EventArgs.Empty); 
400                                         this.Invalidate ();
401                                 }
402                         }
403                 }
404
405                 [Localizable (true)]
406                 public virtual Font Font {
407                         get { 
408                                 if (font != null)
409                                         return font;
410                                         
411                                 if (Parent != null)
412                                         return Parent.Font;
413                                         
414                                 return DefaultFont;
415                         }
416                         set { 
417                                 if (this.font != value) {
418                                         this.font = value; 
419                                         this.CalculateAutoSize (); 
420                                         this.OnFontChanged (EventArgs.Empty); 
421                                         this.Invalidate ();
422                                 }
423                         }
424                 }
425
426                 public virtual Color ForeColor {
427                         get { 
428                                 if (fore_color != Color.Empty)
429                                         return fore_color;
430                                         
431                                 if (Parent != null)
432                                         return parent.ForeColor;
433                                         
434                                 return Control.DefaultForeColor;
435                         }
436                         set { 
437                                 if (this.fore_color != value) {
438                                         this.fore_color = value; 
439                                         this.OnForeColorChanged (EventArgs.Empty); 
440                                         this.Invalidate ();
441                                 }
442                         }
443                 }
444
445                 [Browsable (false)]
446                 [EditorBrowsable (EditorBrowsableState.Always)]
447                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
448                 public int Height {
449                         get { return this.Size.Height; }
450                         set { 
451                                 this.Size = new Size (this.Size.Width, value); 
452                                 this.explicit_size.Height = value;
453                                 
454                                 if (this.Visible) {
455                                         this.CalculateAutoSize ();
456                                         this.OnBoundsChanged ();
457                                         this.Invalidate (); 
458                                 } 
459                         }
460                 }
461
462                 [Localizable (true)]
463                 public virtual Image Image {
464                         get { 
465                                 if (this.image != null)
466                                         return this.image;
467                                         
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];
471
472
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];
476                                                 
477                                 return null;
478                         }
479                         set {
480                                 if (this.image != value) {
481                                         StopAnimation ();
482                                         
483                                         this.image = value; 
484                                         this.image_index = -1;
485                                         this.image_key = string.Empty;
486                                         this.CalculateAutoSize (); 
487                                         this.Invalidate ();
488                                         
489                                         BeginAnimation ();
490                                 }
491                         }
492                 }
493
494                 [Localizable (true)]
495                 [DefaultValue (ContentAlignment.MiddleCenter)]
496                 public ContentAlignment ImageAlign {
497                         get { return this.image_align; }
498                         set {
499                                 if (!Enum.IsDefined (typeof (ContentAlignment), value))
500                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
501
502                                 if (image_align != value) {
503                                         this.image_align = value;
504                                         this.CalculateAutoSize (); 
505                                 }
506                         }
507                 }
508
509                 [Localizable (true)]
510                 [Browsable (false)]
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; }
517                         set {
518                                 if (this.image_index != value) {
519                                         // Lamespec: MSDN says ArgumentException, tests say otherwise
520                                         if (value < -1)
521                                                 throw new ArgumentOutOfRangeException ("ImageIndex cannot be less than -1");
522
523                                         this.image_index = value;
524                                         this.image = null;
525                                         this.image_key = string.Empty;
526                                         this.CalculateAutoSize ();
527                                         this.Invalidate ();
528                                 }
529                         }
530                 }
531
532                 [Localizable (true)]
533                 [Browsable (false)]
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; }
540                         set { 
541                                 if (this.image_key != value) {
542                                         this.image = null;
543                                         this.image_index = -1;
544                                         this.image_key = value;
545                                         this.CalculateAutoSize ();
546                                         this.Invalidate ();
547                                 }
548                         }
549                 }
550                 
551                 [Localizable (true)]
552                 [DefaultValue (ToolStripItemImageScaling.SizeToFit)]
553                 public ToolStripItemImageScaling ImageScaling {
554                         get { return this.image_scaling; }
555                         set { 
556                                 if (image_scaling != value) {
557                                         this.image_scaling = value; 
558                                         this.CalculateAutoSize (); 
559                                 }
560                         }
561                 }
562
563                 [Localizable (true)]
564                 public Color ImageTransparentColor {
565                         get { return this.image_transparent_color; }
566                         set { this.image_transparent_color = value; }
567                 }
568                 
569                 [Browsable (false)]
570                 public bool IsOnDropDown {
571                         get {
572                                 if (this.parent != null && this.parent is ToolStripDropDown)
573                                         return true;
574
575                                 return false;
576                         }
577                 }
578
579                 [Browsable (false)]
580                 public bool IsOnOverflow {
581                         get { return this.placement == ToolStripItemPlacement.Overflow; }
582                 }
583                 
584                 public Padding Margin {
585                         get { return this.margin; }
586                         set {
587                                 this.margin = value; 
588                                 this.CalculateAutoSize ();
589                         }
590                 }
591
592                 [DefaultValue (MergeAction.Append)]
593                 public MergeAction MergeAction {
594                         get { return this.merge_action; }
595                         set {
596                                 if (!Enum.IsDefined (typeof (MergeAction), value))
597                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for MergeAction", value));
598                                         
599                                 this.merge_action = value;
600                         }
601                 }
602
603                 [DefaultValue (-1)]
604                 public int MergeIndex {
605                         get { return this.merge_index; }
606                         set { this.merge_index = value; }
607                 }
608
609                 [DefaultValue (null)]
610                 [Browsable (false)]
611                 public string Name {
612                         get { return this.name; }
613                         set { this.name = value; }
614                 }
615
616                 [DefaultValue (ToolStripItemOverflow.AsNeeded)]
617                 public ToolStripItemOverflow Overflow {
618                         get { return this.overflow; }
619                         set { 
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));
623                                 
624                                         this.overflow = value;
625                                         
626                                         if (owner != null)
627                                                 owner.PerformLayout ();
628                                 }
629                         }
630                 }
631                         
632                 [Browsable (false)]
633                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
634                 public ToolStrip Owner {
635                         get { return this.owner; }
636                         set { 
637                                 if (this.owner != value) {
638                                         if (this.owner != null)
639                                                 this.owner.Items.Remove (this);
640                                         
641                                         if (value != null)      
642                                                 value.Items.Add (this);
643                                         else
644                                                 this.owner = null;
645                                 }
646                         }
647                 }
648
649                 [Browsable (false)]
650                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
651                 public ToolStripItem OwnerItem {
652                         get { return this.owner_item; }
653                 }
654
655                 public virtual Padding Padding {
656                         get { return this.padding; }
657                         set { 
658                                 this.padding = value; 
659                                 this.CalculateAutoSize (); 
660                                 this.Invalidate (); 
661                         }
662                 }
663
664                 [Browsable (false)]
665                 public ToolStripItemPlacement Placement {
666                         get { return this.placement; }
667                 }
668                 
669                 [Browsable (false)]
670                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
671                 public virtual bool Pressed { get { return this.is_pressed; } }
672
673                 [MonoTODO ("RTL not implemented")]
674                 [Localizable (true)]
675                 public virtual RightToLeft RightToLeft {
676                         get { return this.right_to_left; }
677                         set { 
678                                 if (this.right_to_left != value) {
679                                         this.right_to_left = value;
680                                         this.OnRightToLeftChanged (EventArgs.Empty);
681                                 }
682                         }
683                 }
684                 
685                 [Localizable (true)]
686                 [DefaultValue (false)]
687                 public bool RightToLeftAutoMirrorImage {
688                         get { return this.right_to_left_auto_mirror_image; }
689                         set { 
690                                 if (this.right_to_left_auto_mirror_image != value) {
691                                         this.right_to_left_auto_mirror_image = value;
692                                         this.Invalidate ();
693                                 }
694                         }
695                 }
696                 
697                 [Browsable (false)]
698                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
699                 public virtual bool Selected { get { return this.is_selected; } }
700
701                 [Localizable (true)]
702                 public virtual Size Size {
703                         get { 
704                                 if (!this.AutoSize && this.explicit_size != Size.Empty) 
705                                         return this.explicit_size; 
706                                         
707                                 return this.bounds.Size; 
708                         }
709                         set { 
710                                 this.bounds.Size = value; 
711                                 this.explicit_size = value;
712                                 
713                                 if (this.Visible) {
714                                         this.CalculateAutoSize ();
715                                         this.OnBoundsChanged (); 
716                                 }
717                         }
718                 }
719
720                 [Localizable (false)]
721                 [Bindable (true)]
722                 [DefaultValue (null)]
723                 [TypeConverter (typeof (StringConverter))]
724                 public Object Tag {
725                         get { return this.tag; }
726                         set { this.tag = value; }
727                 }
728
729                 [Localizable (true)]
730                 [DefaultValue ("")]
731                 public virtual string Text
732                 {
733                         get { return this.text; }
734                         set { 
735                                 if (this.text != value) { 
736                                         this.text = value; 
737                                         this.Invalidate (); 
738                                         this.CalculateAutoSize (); 
739                                         this.Invalidate ();
740                                         this.OnTextChanged (EventArgs.Empty); 
741                                 } 
742                         }
743                 }
744
745                 [Localizable (true)]
746                 [DefaultValue (ContentAlignment.MiddleCenter)]
747                 public virtual ContentAlignment TextAlign {
748                         get { return this.text_align; }
749                         set {
750                                 if (!Enum.IsDefined (typeof (ContentAlignment), value))
751                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
752
753                                 if (this.text_align != value) {
754                                         this.text_align = value;
755                                         this.CalculateAutoSize (); 
756                                 }
757                         }
758                 }
759
760                 public virtual ToolStripTextDirection TextDirection {
761                         get {
762                                 if (this.text_direction == ToolStripTextDirection.Inherit) {
763                                         if (this.Parent != null)
764                                                 return this.Parent.TextDirection;
765                                         else
766                                                 return ToolStripTextDirection.Horizontal;
767                                 }
768
769                                 return this.text_direction;
770                         }
771                         set {
772                                 if (!Enum.IsDefined (typeof (ToolStripTextDirection), value))
773                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripTextDirection", value));
774                                 
775                                 if (this.text_direction != value) {
776                                         this.text_direction = value;
777                                         this.CalculateAutoSize ();
778                                         this.Invalidate ();
779                                 }
780                         }       
781                 }
782
783                 [Localizable (true)]
784                 [DefaultValue (TextImageRelation.ImageBeforeText)]
785                 public TextImageRelation TextImageRelation {
786                         get { return this.text_image_relation; }
787                         set { 
788                                 this.text_image_relation = value; 
789                                 this.CalculateAutoSize (); 
790                                 this.Invalidate (); 
791                         }
792                 }
793
794                 [Localizable (true)]
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; }
800                 }
801
802                 [Localizable (true)]
803                 public bool Visible {
804                         get { 
805                                 if (this.parent == null)
806                                         return false;
807                         
808                                 return this.visible && this.parent.Visible; 
809                         }
810                         set { 
811                                 if (this.visible != value) {
812                                         this.available = value;
813                                         this.SetVisibleCore (value);
814                                         if (this.Owner != null)
815                                                 this.Owner.PerformLayout ();
816                                 }
817                         }
818                 }
819
820                 [Browsable (false)]
821                 [EditorBrowsable (EditorBrowsableState.Always)]
822                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
823                 public int Width {
824                         get { return this.Size.Width; }
825                         set { 
826                                 this.Size = new Size (value, this.Size.Height); 
827                                 this.explicit_size.Width = value;
828                                 
829                                 if (this.Visible) {
830                                         this.CalculateAutoSize ();
831                                         this.OnBoundsChanged ();
832                                         this.Invalidate ();
833                                 }
834                         }
835                 }
836                 #endregion
837
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; } }
845                 [Browsable (false)]
846                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
847                 protected internal ToolStrip Parent {
848                         get { return this.parent; }
849                         set { 
850                                 if (this.parent != value) {
851                                         ToolStrip old_parent = this.parent;
852                                         this.parent = value; 
853                                         OnParentChanged(old_parent, this.parent);
854                                 }
855                         }
856                 }
857                 protected internal virtual bool ShowKeyboardCues { get { return false; } }
858                 #endregion
859
860                 #region Public Methods
861                 [MonoTODO ("Stub, does nothing")]
862                 [EditorBrowsable (EditorBrowsableState.Advanced)]
863                 public DragDropEffects DoDragDrop (Object data, DragDropEffects allowedEffects)
864                 {
865                         return allowedEffects;
866                 }
867                 
868                 public ToolStrip GetCurrentParent ()
869                 { 
870                         return this.parent; 
871                 }
872
873                 public virtual Size GetPreferredSize (Size constrainingSize)
874                 {
875                         return this.CalculatePreferredSize (constrainingSize);
876                 }
877
878                 public void Invalidate ()
879                 {
880                         if (parent != null)
881                                 parent.Invalidate (this.bounds);
882                 }
883
884                 public void Invalidate (Rectangle r)
885                 {
886                         if (parent != null)
887                                 parent.Invalidate (r);
888                 }
889
890                 public void PerformClick ()
891                 { 
892                         this.OnClick (EventArgs.Empty); 
893                 }
894
895                 [EditorBrowsable (EditorBrowsableState.Never)]
896                 public virtual void ResetBackColor () { this.BackColor = Color.Empty; }
897
898                 [EditorBrowsable (EditorBrowsableState.Never)]
899                 public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
900
901                 [EditorBrowsable (EditorBrowsableState.Never)]
902                 public virtual void ResetFont () { this.font = null; }
903
904                 [EditorBrowsable (EditorBrowsableState.Never)]
905                 public virtual void ResetForeColor () { this.ForeColor = Color.Empty; }
906
907                 [EditorBrowsable (EditorBrowsableState.Never)]
908                 public virtual void ResetImage () { this.image = null; }
909
910                 [EditorBrowsable (EditorBrowsableState.Never)]
911                 public void ResetMargin () { this.margin = this.DefaultMargin; }
912
913                 [EditorBrowsable (EditorBrowsableState.Never)]
914                 public void ResetPadding () { this.padding = this.DefaultPadding; }
915
916                 [EditorBrowsable (EditorBrowsableState.Never)]
917                 public virtual void ResetRightToLeft () { this.right_to_left = RightToLeft.Inherit; }
918                 
919                 [EditorBrowsable (EditorBrowsableState.Never)]
920                 public virtual void ResetTextDirection () { this.TextDirection = this.DefaultTextDirection; }
921
922                 public void Select ()
923                 {
924                         if (!this.is_selected && this.CanSelect) {
925                                 this.is_selected = true;
926                                 
927                                 if (this.Parent != null) {
928                                         if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
929                                                 (this as ToolStripControlHost).Focus ();
930                                                 
931                                         this.Invalidate ();
932                                         this.Parent.NotifySelectedChanged (this);
933                                 }
934                                 OnUIASelectionChanged ();
935                         }
936                 }
937
938                 public override string ToString ()
939                 {
940                         return this.text;
941                 }
942                 #endregion
943
944                 #region Protected Methods
945                 [EditorBrowsable (EditorBrowsableState.Advanced)]
946                 protected virtual AccessibleObject CreateAccessibilityInstance ()
947                 {
948                         return new ToolStripItemAccessibleObject (this);
949                 }
950
951                 protected override void Dispose (bool disposing)
952                 {
953                         if (!is_disposed && disposing)
954                                 is_disposed = true;
955
956                         if (image != null) {
957                                 StopAnimation ();
958                                 image = null;
959                         }
960
961                         if (owner != null)
962                                 owner.Items.Remove (this);
963                         
964                         base.Dispose (disposing);
965                 }
966                 
967                 protected internal virtual bool IsInputChar (char charCode)
968                 {
969                         return false;
970                 }
971                 
972                 protected internal virtual bool IsInputKey (Keys keyData)
973                 {
974                         return false;
975                 }
976                 
977                 protected virtual void OnAvailableChanged (EventArgs e)
978                 {
979                         EventHandler eh = (EventHandler)(Events [AvailableChangedEvent]);
980                         if (eh != null)
981                                 eh (this, e);
982                 }
983
984                 [EditorBrowsable (EditorBrowsableState.Advanced)]
985                 protected virtual void OnBackColorChanged (EventArgs e)
986                 {
987                         EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
988                         if (eh != null)
989                                 eh (this, e);
990                 }
991
992                 protected virtual void OnBoundsChanged ()
993                 {
994                         OnLayout (new LayoutEventArgs(null, string.Empty));
995                 }
996
997                 protected virtual void OnClick (EventArgs e)
998                 {
999                         EventHandler eh = (EventHandler)(Events [ClickEvent]);
1000                         if (eh != null)
1001                                 eh (this, e);
1002                 }
1003
1004                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1005                 protected virtual void OnDisplayStyleChanged (EventArgs e)
1006                 {
1007                         EventHandler eh = (EventHandler)(Events [DisplayStyleChangedEvent]);
1008                         if (eh != null)
1009                                 eh (this, e);
1010                 }
1011
1012                 protected virtual void OnDoubleClick (EventArgs e)
1013                 {
1014                         EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
1015                         if (eh != null)
1016                                 eh (this, e);
1017                 }
1018
1019                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1020                 protected virtual void OnDragDrop (DragEventArgs dragEvent)
1021                 {
1022                         DragEventHandler eh = (DragEventHandler)(Events[DragDropEvent]);
1023                         if (eh != null)
1024                                 eh (this, dragEvent);
1025                 }
1026
1027                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1028                 protected virtual void OnDragEnter (DragEventArgs dragEvent)
1029                 {
1030                         DragEventHandler eh = (DragEventHandler)(Events[DragEnterEvent]);
1031                         if (eh != null)
1032                                 eh (this, dragEvent);
1033                 }
1034
1035                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1036                 protected virtual void OnDragLeave (EventArgs e)
1037                 {
1038                         EventHandler eh = (EventHandler)(Events[DragLeaveEvent]);
1039                         if (eh != null)
1040                                 eh (this, e);
1041                 }
1042
1043                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1044                 protected virtual void OnDragOver (DragEventArgs dragEvent)
1045                 {
1046                         DragEventHandler eh = (DragEventHandler)(Events[DragOverEvent]);
1047                         if (eh != null)
1048                                 eh (this, dragEvent);
1049                 }
1050
1051                 protected virtual void OnEnabledChanged (EventArgs e)
1052                 {
1053                         EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
1054                         if (eh != null)
1055                                 eh (this, e);
1056                 }
1057
1058                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1059                 protected virtual void OnFontChanged (EventArgs e)
1060                 {
1061                 }
1062
1063                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1064                 protected virtual void OnForeColorChanged (EventArgs e)
1065                 {
1066                         EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
1067                         if (eh != null)
1068                                 eh (this, e);
1069                 }
1070
1071                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1072                 protected virtual void OnGiveFeedback (GiveFeedbackEventArgs giveFeedbackEvent)
1073                 {
1074                         GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events[GiveFeedbackEvent]);
1075                         if (eh != null)
1076                                 eh (this, giveFeedbackEvent);
1077                 }
1078
1079                 protected virtual void OnLayout (LayoutEventArgs e)
1080                 {
1081                 }
1082
1083                 protected virtual void OnLocationChanged (EventArgs e)
1084                 {
1085                         EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
1086                         if (eh != null)
1087                                 eh (this, e);
1088                 }
1089
1090                 protected virtual void OnMouseDown (MouseEventArgs e)
1091                 {
1092                         if (this.Enabled) {
1093                                 this.is_pressed = true;
1094                                 this.Invalidate ();
1095
1096                                 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
1097                                 if (eh != null)
1098                                         eh (this, e);
1099                         }
1100                 }
1101
1102                 protected virtual void OnMouseEnter (EventArgs e)
1103                 {
1104                         this.Select ();
1105
1106                         EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
1107                         if (eh != null)
1108                                 eh (this, e);
1109                 }
1110
1111                 protected virtual void OnMouseHover (EventArgs e)
1112                 {
1113                         if (this.Enabled) {
1114                                 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
1115                                 if (eh != null)
1116                                         eh (this, e);
1117                         }
1118                 }
1119
1120                 protected virtual void OnMouseLeave (EventArgs e)
1121                 {
1122                         if (this.CanSelect) {
1123                                 this.is_selected = false;
1124                                 this.is_pressed = false;
1125                                 this.Invalidate ();
1126                                 OnUIASelectionChanged ();
1127                         }
1128
1129                         EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
1130                         if (eh != null)
1131                                 eh (this, e);
1132                 }
1133
1134                 protected virtual void OnMouseMove (MouseEventArgs mea)
1135                 {
1136                         if (this.Enabled) {
1137                                 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
1138                                 if (eh != null)
1139                                         eh (this, mea);
1140                         }
1141                 }
1142
1143                 protected virtual void OnMouseUp (MouseEventArgs e)
1144                 {
1145                         if (this.Enabled) {
1146                                 this.is_pressed = false;
1147                                 this.Invalidate ();
1148
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 ();
1153                                                 else
1154                                                         (this.Parent as ToolStripDropDown).Hide ();
1155                                         }
1156                                                 
1157                                 
1158                                 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
1159                                 if (eh != null)
1160                                         eh (this, e);
1161                         }
1162                 }
1163
1164                 protected virtual void OnOwnerChanged (EventArgs e)
1165                 {
1166                         EventHandler eh = (EventHandler)(Events [OwnerChangedEvent]);
1167                         if (eh != null)
1168                                 eh (this, e);
1169                 }
1170
1171                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1172                 protected internal virtual void OnOwnerFontChanged (EventArgs e)
1173                 {
1174                         this.CalculateAutoSize ();
1175                         OnFontChanged (EventArgs.Empty);
1176                 }
1177
1178                 void OnPaintInternal (PaintEventArgs e)
1179                 {
1180                         // Have the background rendered independently from OnPaint
1181                         if (this.parent != null)
1182                                 this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
1183
1184                         OnPaint (e);
1185                 }
1186
1187                 protected virtual void OnPaint (PaintEventArgs e)
1188                 {
1189                         PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
1190                         if (eh != null)
1191                                 eh (this, e);
1192                 }
1193
1194                 // This is never called.
1195                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1196                 protected virtual void OnParentBackColorChanged (EventArgs e)
1197                 {
1198                 }
1199                 
1200                 protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
1201                 {
1202                         this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty : this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
1203                         
1204                         if (oldParent != null)
1205                                 oldParent.PerformLayout ();
1206                                 
1207                         if (newParent != null)
1208                                 newParent.PerformLayout ();
1209                 }
1210
1211                 protected internal virtual void OnParentEnabledChanged (EventArgs e)
1212                 {
1213                         this.OnEnabledChanged (e);
1214                 }
1215
1216                 // This is never called.
1217                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1218                 protected virtual void OnParentForeColorChanged (EventArgs e)
1219                 {
1220                 }
1221
1222                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1223                 protected internal virtual void OnParentRightToLeftChanged (EventArgs e)
1224                 {
1225                         this.OnRightToLeftChanged (e);
1226                 }
1227
1228                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1229                 protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs queryContinueDragEvent)
1230                 {
1231                         QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events[QueryContinueDragEvent]);
1232                         if (eh != null)
1233                                 eh (this, queryContinueDragEvent);
1234                 }
1235                 
1236                 protected virtual void OnRightToLeftChanged (EventArgs e)
1237                 {
1238                         EventHandler eh = (EventHandler)(Events[RightToLeftChangedEvent]);
1239                         if (eh != null)
1240                                 eh (this, e);
1241                 }
1242                 
1243                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1244                 protected virtual void OnTextChanged (EventArgs e)
1245                 {
1246                         EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
1247                         if (eh != null)
1248                                 eh (this, e);
1249                 }
1250
1251                 protected virtual void OnVisibleChanged (EventArgs e)
1252                 {
1253                         EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
1254                         if (eh != null)
1255                                 eh (this, e);
1256                 }
1257
1258                 protected internal virtual bool ProcessCmdKey (ref Message m, Keys keyData)
1259                 {
1260                         return false;
1261                 }
1262                 
1263                 protected internal virtual bool ProcessDialogKey (Keys keyData)
1264                 {
1265                         if (this.Selected && keyData == Keys.Enter) {
1266                                 this.FireEvent (EventArgs.Empty, ToolStripItemEventType.Click);
1267                                 return true;
1268                         }
1269                                 
1270                         return false;
1271                 }
1272                 
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)
1276                 {
1277                         ToolStripManager.SetActiveToolStrip (this.Parent, true);
1278                         this.PerformClick ();
1279                         return true;
1280                 }
1281                 
1282                 protected internal virtual void SetBounds (Rectangle bounds)
1283                 {
1284                         if (this.bounds != bounds) {
1285                                 this.bounds = bounds;
1286                                 OnBoundsChanged ();
1287                         }
1288                 }
1289                 
1290                 protected virtual void SetVisibleCore (bool visible)
1291                 {
1292                         this.visible = visible;
1293                         this.OnVisibleChanged (EventArgs.Empty);
1294                         
1295                         if (this.visible)
1296                                 BeginAnimation ();
1297                         else
1298                                 StopAnimation ();
1299                         this.Invalidate ();
1300                 }
1301                 #endregion
1302
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 ();
1330
1331                 [Browsable (false)]
1332                 public event EventHandler AvailableChanged {
1333                         add { Events.AddHandler (AvailableChangedEvent, value); }
1334                         remove {Events.RemoveHandler (AvailableChangedEvent, value); }
1335                 }
1336
1337                 public event EventHandler BackColorChanged {
1338                         add { Events.AddHandler (BackColorChangedEvent, value); }
1339                         remove {Events.RemoveHandler (BackColorChangedEvent, value); }
1340                 }
1341
1342                 public event EventHandler Click {
1343                         add { Events.AddHandler (ClickEvent, value); }
1344                         remove {Events.RemoveHandler (ClickEvent, value); }
1345                 }
1346
1347                 public event EventHandler DisplayStyleChanged {
1348                         add { Events.AddHandler (DisplayStyleChangedEvent, value); }
1349                         remove {Events.RemoveHandler (DisplayStyleChangedEvent, value); }
1350                 }
1351
1352                 public event EventHandler DoubleClick {
1353                         add { Events.AddHandler (DoubleClickEvent, value); }
1354                         remove {Events.RemoveHandler (DoubleClickEvent, value); }
1355                 }
1356
1357                 [MonoTODO ("Event never raised")]
1358                 [Browsable (false)]
1359                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1360                 public event DragEventHandler DragDrop {
1361                         add { Events.AddHandler (DragDropEvent, value); }
1362                         remove { Events.RemoveHandler (DragDropEvent, value); }
1363                 }
1364
1365                 [MonoTODO ("Event never raised")]
1366                 [Browsable (false)]
1367                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1368                 public event DragEventHandler DragEnter {
1369                         add { Events.AddHandler (DragEnterEvent, value); }
1370                         remove { Events.RemoveHandler (DragEnterEvent, value); }
1371                 }
1372
1373                 [MonoTODO ("Event never raised")]
1374                 [Browsable (false)]
1375                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1376                 public event EventHandler DragLeave {
1377                         add { Events.AddHandler (DragLeaveEvent, value); }
1378                         remove { Events.RemoveHandler (DragLeaveEvent, value); }
1379                 }
1380
1381                 [MonoTODO ("Event never raised")]
1382                 [Browsable (false)]
1383                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1384                 public event DragEventHandler DragOver {
1385                         add { Events.AddHandler (DragOverEvent, value); }
1386                         remove { Events.RemoveHandler (DragOverEvent, value); }
1387                 }
1388
1389                 public event EventHandler EnabledChanged {
1390                         add { Events.AddHandler (EnabledChangedEvent, value); }
1391                         remove {Events.RemoveHandler (EnabledChangedEvent, value); }
1392                 }
1393
1394                 public event EventHandler ForeColorChanged {
1395                         add { Events.AddHandler (ForeColorChangedEvent, value); }
1396                         remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
1397                 }
1398
1399                 [MonoTODO ("Event never raised")]
1400                 [Browsable (false)]
1401                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1402                 public event GiveFeedbackEventHandler GiveFeedback {
1403                         add { Events.AddHandler (GiveFeedbackEvent, value); }
1404                         remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
1405                 }
1406
1407                 public event EventHandler LocationChanged {
1408                         add { Events.AddHandler (LocationChangedEvent, value); }
1409                         remove {Events.RemoveHandler (LocationChangedEvent, value); }
1410                 }
1411
1412                 public event MouseEventHandler MouseDown {
1413                         add { Events.AddHandler (MouseDownEvent, value); }
1414                         remove {Events.RemoveHandler (MouseDownEvent, value); }
1415                 }
1416
1417                 public event EventHandler MouseEnter {
1418                         add { Events.AddHandler (MouseEnterEvent, value); }
1419                         remove {Events.RemoveHandler (MouseEnterEvent, value); }
1420                 }
1421
1422                 public event EventHandler MouseHover {
1423                         add { Events.AddHandler (MouseHoverEvent, value); }
1424                         remove {Events.RemoveHandler (MouseHoverEvent, value); }
1425                 }
1426
1427                 public event EventHandler MouseLeave {
1428                         add { Events.AddHandler (MouseLeaveEvent, value); }
1429                         remove {Events.RemoveHandler (MouseLeaveEvent, value); }
1430                 }
1431
1432                 public event MouseEventHandler MouseMove {
1433                         add { Events.AddHandler (MouseMoveEvent, value); }
1434                         remove {Events.RemoveHandler (MouseMoveEvent, value); }
1435                 }
1436
1437                 public event MouseEventHandler MouseUp {
1438                         add { Events.AddHandler (MouseUpEvent, value); }
1439                         remove {Events.RemoveHandler (MouseUpEvent, value); }
1440                 }
1441
1442                 public event EventHandler OwnerChanged {
1443                         add { Events.AddHandler (OwnerChangedEvent, value); }
1444                         remove {Events.RemoveHandler (OwnerChangedEvent, value); }
1445                 }
1446
1447                 public event PaintEventHandler Paint {
1448                         add { Events.AddHandler (PaintEvent, value); }
1449                         remove {Events.RemoveHandler (PaintEvent, value); }
1450                 }
1451
1452                 [MonoTODO ("Event never raised")]
1453                 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
1454                         add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
1455                         remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
1456                 }
1457
1458                 [MonoTODO ("Event never raised")]
1459                 [Browsable (false)]
1460                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1461                 public event QueryContinueDragEventHandler QueryContinueDrag {
1462                         add { Events.AddHandler (QueryContinueDragEvent, value); }
1463                         remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
1464                 }
1465
1466                 public event EventHandler RightToLeftChanged {
1467                         add { Events.AddHandler (RightToLeftChangedEvent, value); }
1468                         remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
1469                 }
1470                 
1471                 public event EventHandler TextChanged {
1472                         add { Events.AddHandler (TextChangedEvent, value); }
1473                         remove {Events.RemoveHandler (TextChangedEvent, value); }
1474                 }
1475
1476                 public event EventHandler VisibleChanged {
1477                         add { Events.AddHandler (VisibleChangedEvent, value); }
1478                         remove {Events.RemoveHandler (VisibleChangedEvent, value); }
1479                 }
1480                 #endregion
1481
1482                 #region Internal Methods
1483                 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, ContentAlignment align)
1484                 {
1485                         int x = 0;
1486                         int y = 0;
1487
1488                         if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft)
1489                                 x = outer.X;
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)
1495                                 y = outer.Y;
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;
1500
1501                         return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
1502                 }
1503
1504                 internal void CalculateAutoSize ()
1505                 {
1506                         this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty: this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
1507
1508                         // If our text is rotated, flip the width and height
1509                         ToolStripTextDirection direction = this.TextDirection;
1510                         
1511                         if (direction == ToolStripTextDirection.Vertical270 || direction == ToolStripTextDirection.Vertical90)
1512                                 this.text_size = new Size (this.text_size.Height, this.text_size.Width);
1513                         
1514                         if (!this.auto_size || this is ToolStripControlHost)
1515                                 return;
1516                         //this.text_size.Width += 6;
1517
1518                         Size final_size = this.CalculatePreferredSize (Size.Empty);
1519
1520                         if (final_size != this.Size) {
1521                                 this.bounds.Width = final_size.Width;
1522                                 if (this.parent != null)
1523                                         this.parent.PerformLayout ();
1524                         }
1525                 }
1526
1527                 internal virtual Size CalculatePreferredSize (Size constrainingSize)
1528                 {
1529                         if (!this.auto_size)
1530                                 return this.explicit_size;
1531                                 
1532                         Size preferred_size = this.DefaultSize;
1533
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);
1539                                         break;
1540                                 case ToolStripItemDisplayStyle.Image:
1541                                         if (this.GetImageSize () == Size.Empty)
1542                                                 preferred_size = this.DefaultSize;
1543                                         else {
1544                                                 switch (this.image_scaling) {
1545                                                         case ToolStripItemImageScaling.None:
1546                                                                 preferred_size = this.GetImageSize ();
1547                                                                 break;
1548                                                         case ToolStripItemImageScaling.SizeToFit:
1549                                                                 if (this.parent == null)
1550                                                                         preferred_size = this.GetImageSize ();
1551                                                                 else
1552                                                                         preferred_size = this.parent.ImageScalingSize;
1553                                                                 break;
1554                                                 }
1555                                         }
1556                                         break;
1557                                 case ToolStripItemDisplayStyle.ImageAndText:
1558                                         int width2 = text_size.Width + this.padding.Horizontal;
1559                                         int height2 = text_size.Height + this.padding.Vertical;
1560
1561                                         if (this.GetImageSize () != Size.Empty) {
1562                                                 Size image_size = this.GetImageSize ();
1563                                                 
1564                                                 if (this.image_scaling == ToolStripItemImageScaling.SizeToFit && this.parent != null)
1565                                                         image_size = this.parent.ImageScalingSize;
1566                                                 
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);
1571                                                                 break;
1572                                                         case TextImageRelation.ImageAboveText:
1573                                                         case TextImageRelation.TextAboveImage:
1574                                                                 width2 = Math.Max (width2, image_size.Width);
1575                                                                 height2 += image_size.Height;
1576                                                                 break;
1577                                                         case TextImageRelation.ImageBeforeText:
1578                                                         case TextImageRelation.TextBeforeImage:
1579                                                                 height2 = Math.Max (height2, image_size.Height);
1580                                                                 width2 += image_size.Width;
1581                                                                 break;
1582                                                 }
1583                                         }
1584
1585                                         preferred_size = new Size (width2, height2);
1586                                         break;
1587                         }
1588
1589                         if (!(this is ToolStripLabel)) {                // Everything but labels have a border
1590                                 preferred_size.Height += 4;
1591                                 preferred_size.Width += 4;
1592                         }
1593
1594                         return preferred_size;
1595                 }
1596
1597                 internal void CalculateTextAndImageRectangles (out Rectangle text_rect, out Rectangle image_rect)
1598                 {
1599                         this.CalculateTextAndImageRectangles (this.ContentRectangle, out text_rect, out image_rect);
1600                 }
1601                 
1602                 internal void CalculateTextAndImageRectangles (Rectangle contentRectangle, out Rectangle text_rect, out Rectangle image_rect)
1603                 {
1604                         text_rect = Rectangle.Empty;
1605                         image_rect = Rectangle.Empty;
1606                                 
1607                         switch (this.display_style) {
1608                                 case ToolStripItemDisplayStyle.None:
1609                                         break;
1610                                 case ToolStripItemDisplayStyle.Text:
1611                                         if (this.text != string.Empty)
1612                                                 text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
1613                                         break;
1614                                 case ToolStripItemDisplayStyle.Image:
1615                                         if (this.Image != null && this.UseImageMargin)
1616                                                 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1617                                         break;
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))
1622                                                 break;
1623                                         else if (this.text == string.Empty && this.Image != null)
1624                                                 image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
1625                                         else {
1626                                                 Rectangle text_area;
1627                                                 Rectangle image_area;
1628
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);
1633                                                                 break;
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);
1637
1638                                                                 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1639                                                                 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1640                                                                 break;
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);
1644
1645                                                                 text_rect = AlignInRectangle (text_area, this.text_size, this.text_align);
1646                                                                 image_rect = AlignInRectangle (image_area, GetImageSize (), this.image_align);
1647                                                                 break;
1648                                                         case TextImageRelation.ImageBeforeText:
1649                                                                 LayoutTextBeforeOrAfterImage (contentRectangle, false, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1650                                                                 break;
1651                                                         case TextImageRelation.TextBeforeImage:
1652                                                                 LayoutTextBeforeOrAfterImage (contentRectangle, true, text_size, GetImageSize (), text_align, image_align, out text_rect, out image_rect);
1653                                                                 break;
1654                                                 }
1655                                         }
1656                                         break;
1657                         }
1658                 }
1659
1660                 private static Font DefaultFont { get { return new Font ("Tahoma", 8.25f); } }
1661                 
1662                 internal virtual ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Inherit; } }
1663
1664                 internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
1665                 {
1666                         if (is_selected) {
1667                                 this.is_selected = false;
1668                                 this.Invalidate ();
1669                                 OnUIASelectionChanged ();
1670                         }
1671                 }
1672                 
1673                 internal virtual ToolStrip GetTopLevelToolStrip ()
1674                 {
1675                         if (this.Parent != null)
1676                                 return this.Parent.GetTopLevelToolStrip ();
1677                                 
1678                         return null;
1679                 }
1680
1681                 private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, ContentAlignment textAlign, ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
1682                 {
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;
1686                         int offset = 0;
1687                         
1688                         Rectangle final_text_rect;
1689                         Rectangle final_image_rect;
1690
1691                         HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
1692                         HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
1693                         
1694                         if (h_image == HorizontalAlignment.Left)
1695                                 offset = 0;
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);
1700                         else
1701                                 offset += (int)(2 * (excess_width / 3));
1702                                 
1703                         if (textFirst) {
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);
1706                         } else {
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);
1709                         }
1710                         
1711                         textRect = final_text_rect;
1712                         imageRect = final_image_rect;
1713                 }
1714                 
1715                 private HorizontalAlignment GetHorizontalAlignment (ContentAlignment align)
1716                 {
1717                         switch (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;
1730                         }
1731                         
1732                         return HorizontalAlignment.Left;
1733                 }
1734                 
1735                 internal Size GetImageSize ()
1736                 {
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)
1741                                         return image.Size;
1742                                         
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;
1746                         } else {
1747                                 // If we have an image and a parent, return ImageScalingSize
1748                                 if (this.Parent == null)
1749                                         return Size.Empty;
1750                                         
1751                                 if (this.image != null)
1752                                         return this.Parent.ImageScalingSize;
1753
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;
1757                         }
1758                         
1759                         return Size.Empty;
1760                 }
1761                 
1762                 internal string GetToolTip ()
1763                 {
1764                         if (this.auto_tool_tip && string.IsNullOrEmpty (this.tool_tip_text))
1765                                 return this.Text;
1766                                 
1767                         return this.tool_tip_text;
1768                 }
1769                 
1770                 internal void FireEvent (EventArgs e, ToolStripItemEventType met)
1771                 {
1772                         // If we're disabled, don't fire any of these events, except Paint
1773                         if (!this.Enabled && met != ToolStripItemEventType.Paint)
1774                                 return;
1775                                 
1776                         switch (met) {
1777                                 case ToolStripItemEventType.MouseUp:
1778                                         this.HandleClick (((MouseEventArgs)e).Clicks, e);
1779                                         this.OnMouseUp ((MouseEventArgs)e);
1780                                         break;
1781                                 case ToolStripItemEventType.MouseDown:
1782                                         this.OnMouseDown ((MouseEventArgs)e);
1783                                         break;
1784                                 case ToolStripItemEventType.MouseEnter:
1785                                         this.OnMouseEnter (e);
1786                                         break;
1787                                 case ToolStripItemEventType.MouseHover:
1788                                         this.OnMouseHover (e);
1789                                         break;
1790                                 case ToolStripItemEventType.MouseLeave:
1791                                         this.OnMouseLeave (e);
1792                                         break;
1793                                 case ToolStripItemEventType.MouseMove:
1794                                         this.OnMouseMove ((MouseEventArgs)e);
1795                                         break;
1796                                 case ToolStripItemEventType.Paint:
1797                                         this.OnPaintInternal ((PaintEventArgs)e);
1798                                         break;
1799                                 case ToolStripItemEventType.Click:
1800                                         this.HandleClick (1, e);
1801                                         break;
1802                         }
1803                 }
1804                 
1805                 internal virtual void HandleClick (int mouse_clicks, EventArgs e)
1806                 {
1807                         if (Parent == null)
1808                                 return;
1809                         this.Parent.HandleItemClick (this);
1810                         if (mouse_clicks == 2 && double_click_enabled)
1811                                 this.OnDoubleClick (e);
1812                         else
1813                                 this.OnClick (e);
1814                 }
1815                 
1816                 internal virtual void SetPlacement (ToolStripItemPlacement placement)
1817                 {
1818                         this.placement = placement;
1819                 }
1820
1821                 private void BeginAnimation ()
1822                 {
1823                         if (image != null && ImageAnimator.CanAnimate (image)) {
1824                                 frame_handler = new EventHandler (OnAnimateImage);
1825                                 ImageAnimator.Animate (image, frame_handler);
1826                         }
1827                 }
1828
1829                 private void OnAnimateImage (object sender, EventArgs e)
1830                 {
1831                         // This is called from a worker thread,BeginInvoke is used
1832                         // so the control is updated from the correct thread
1833
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)
1837                                 return;
1838
1839                         Parent.BeginInvoke (new EventHandler (UpdateAnimatedImage), new object[] { this, e });
1840                 }
1841
1842                 private void StopAnimation ()
1843                 {
1844                         if (frame_handler == null)
1845                                 return;
1846                                 
1847                         ImageAnimator.StopAnimate (image, frame_handler);
1848                         frame_handler = null;
1849                 }
1850
1851                 private void UpdateAnimatedImage (object sender, EventArgs e)
1852                 {
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)
1856                                 return;
1857
1858                         ImageAnimator.UpdateFrames (image);
1859                         Invalidate ();
1860                 }
1861
1862                 internal bool ShowMargin {
1863                         get {
1864                                 if (!this.IsOnDropDown)
1865                                         return true;
1866
1867                                 if (!(this.Owner is ToolStripDropDownMenu))
1868                                         return false;
1869
1870                                 ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
1871
1872                                 return tsddm.ShowCheckMargin || tsddm.ShowImageMargin;
1873                         }
1874                 }
1875
1876                 internal bool UseImageMargin {
1877                         get {
1878                                 if (!this.IsOnDropDown)
1879                                         return true;
1880
1881                                 if (!(this.Owner is ToolStripDropDownMenu))
1882                                         return false;
1883
1884                                 ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
1885
1886                                 return tsddm.ShowImageMargin || tsddm.ShowCheckMargin;
1887                         }
1888                 }
1889
1890                 internal virtual bool InternalVisible {
1891                         get { return this.visible; }
1892                         set { this.visible = value; Invalidate (); }
1893                 }
1894
1895                 internal ToolStrip InternalOwner {
1896                         set {
1897                                 if (this.owner != value) {
1898                                         this.owner = value;
1899                                         if (this.owner != null)
1900                                                 this.CalculateAutoSize ();
1901                                         OnOwnerChanged (EventArgs.Empty);
1902                                 }
1903                         }
1904                 }
1905
1906                 internal Point Location {
1907                         get { return this.bounds.Location; }
1908                         set {
1909                                 if (this.bounds.Location != value) {
1910                                         this.bounds.Location = value;
1911                                         this.OnLocationChanged (EventArgs.Empty);
1912                                 }
1913                         }
1914                 }
1915
1916                 internal int Top {
1917                         get { return this.bounds.Y; }
1918                         set {
1919                                 if (this.bounds.Y != value) {
1920                                         this.bounds.Y = value;
1921                                         this.OnLocationChanged (EventArgs.Empty);
1922                                 }
1923                         }
1924                 }
1925
1926                 internal int Left {
1927                         get { return this.bounds.X; }
1928                         set {
1929                                 if (this.bounds.X != value) {
1930                                         this.bounds.X = value;
1931                                         this.OnLocationChanged (EventArgs.Empty);
1932                                 }
1933                         }
1934                 }
1935                 
1936                 internal int Right { get { return this.bounds.Right; } }
1937                 internal int Bottom { get { return this.bounds.Bottom; } }
1938                 #endregion
1939
1940                 #region IDropTarget Members
1941                 void IDropTarget.OnDragDrop (DragEventArgs dragEvent)
1942                 {
1943                         OnDragDrop (dragEvent);
1944                 }
1945
1946                 void IDropTarget.OnDragEnter (DragEventArgs dragEvent)
1947                 {
1948                         OnDragEnter (dragEvent);
1949                 }
1950
1951                 void IDropTarget.OnDragLeave (EventArgs e)
1952                 {
1953                         OnDragLeave (e);
1954                 }
1955
1956                 void IDropTarget.OnDragOver (DragEventArgs dragEvent)
1957                 {
1958                         OnDragOver (dragEvent);
1959                 }
1960                 #endregion
1961
1962                 #region UIA Framework: Methods, Properties and Events
1963
1964                 static object UIASelectionChangedEvent = new object ();
1965
1966                 internal event EventHandler UIASelectionChanged {
1967                         add { Events.AddHandler (UIASelectionChangedEvent, value); }
1968                         remove { Events.RemoveHandler (UIASelectionChangedEvent, value); }
1969                 }
1970
1971                 internal void OnUIASelectionChanged ()
1972                 {
1973                         EventHandler eh = (EventHandler)(Events [UIASelectionChangedEvent]);
1974                         if (eh != null)
1975                                 eh (this, EventArgs.Empty);
1976                 }
1977                 
1978                 #endregion
1979
1980                 [ComVisible (true)]
1981                 public class ToolStripItemAccessibleObject : AccessibleObject
1982                 {
1983                         internal ToolStripItem owner_item;
1984                         
1985                         public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
1986                         {
1987                                 if (ownerItem == null)
1988                                         throw new ArgumentNullException ("ownerItem");
1989                                         
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;
1995                         }
1996
1997                         #region Public Properties
1998                         public override Rectangle Bounds {
1999                                 get {
2000                                         return owner_item.Visible ? owner_item.Bounds : Rectangle.Empty;
2001                                 }
2002                         }
2003
2004                         public override string DefaultAction {
2005                                 get { return base.DefaultAction; }
2006                         }
2007
2008                         public override string Description {
2009                                 get { return base.Description; }
2010                         }
2011
2012                         public override string Help {
2013                                 get { return base.Help; }
2014                         }
2015
2016                         public override string KeyboardShortcut {
2017                                 get { return base.KeyboardShortcut; }
2018                         }
2019
2020                         public override string Name {
2021                                 get {
2022                                         if (base.name == string.Empty)
2023                                                 return owner_item.Text;
2024                                                 
2025                                         return base.Name;
2026                                 }
2027                                 set { base.Name = value; }
2028                         }
2029
2030                         public override AccessibleObject Parent {
2031                                 get { return base.Parent; }
2032                         }
2033
2034                         public override AccessibleRole Role {
2035                                 get { return base.Role; }
2036                         }
2037
2038                         public override AccessibleStates State {
2039                                 get { return base.State; }
2040                         }
2041                         #endregion
2042
2043                         #region Public Methods
2044                         public void AddState (AccessibleStates state)
2045                         {
2046                                 base.state = state;
2047                         }
2048
2049                         public override void DoDefaultAction ()
2050                         {
2051                                 base.DoDefaultAction ();
2052                         }
2053
2054                         public override int GetHelpTopic (out string fileName)
2055                         {
2056                                 return base.GetHelpTopic (out fileName);
2057                         }
2058
2059                         public override AccessibleObject Navigate (AccessibleNavigation navigationDirection)
2060                         {
2061                                 return base.Navigate (navigationDirection);
2062                         }
2063
2064                         public override string ToString ()
2065                         {
2066                                 return string.Format ("ToolStripItemAccessibleObject: Owner = {0}", owner_item.ToString());
2067                         }
2068                         #endregion
2069                 }
2070         }
2071
2072         internal class NoneExcludedImageIndexConverter : ImageIndexConverter
2073         {
2074         }
2075 }