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