2007-07-18 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripDropDown.cs
1 //
2 // ToolStripDropDown.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 using System.Drawing;
31 using System.Runtime.InteropServices;
32 using System.ComponentModel;
33
34 namespace System.Windows.Forms
35 {
36         [ClassInterface (ClassInterfaceType.AutoDispatch)]
37         [ComVisible (true)]
38         [Designer ("System.Windows.Forms.Design.ToolStripDropDownDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
39         public class ToolStripDropDown : ToolStrip
40         {
41                 private bool allow_transparency;
42                 private bool auto_close;
43                 private bool can_overflow;
44                 private bool drop_shadow_enabled = true;
45                 private double opacity = 1D;
46                 private ToolStripItem owner_item;
47
48                 #region Public Constructor
49                 public ToolStripDropDown () : base ()
50                 {
51                         SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
52                         SetStyle (ControlStyles.ResizeRedraw, true);
53
54                         this.auto_close = true;
55                         is_visible = false;
56                         this.DefaultDropDownDirection = ToolStripDropDownDirection.Right;
57                         this.GripStyle = ToolStripGripStyle.Hidden;
58                         this.is_toplevel = true;
59                 }
60                 #endregion
61
62                 #region Public Properties
63                 [Browsable (false)]
64                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
65                 public bool AllowTransparency {
66                         get { return allow_transparency; }
67                         set {
68                                 if (value == allow_transparency)
69                                         return;
70
71                                 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0) {
72                                         allow_transparency = value;
73
74                                         if (this.IsHandleCreated) {
75                                                 if (value) 
76                                                         XplatUI.SetWindowTransparency (Handle, Opacity, Color.Empty);
77                                                 else
78                                                         UpdateStyles (); // Remove the WS_EX_LAYERED style
79                                         }
80                                 }
81                         }
82                 }
83
84                 [Browsable (false)]
85                 [EditorBrowsable (EditorBrowsableState.Never)]
86                 public override AnchorStyles Anchor {
87                         get { return base.Anchor; }
88                         set { base.Anchor = value; }
89                 }
90
91                 [DefaultValue (true)]
92                 public bool AutoClose
93                 {
94                         get { return this.auto_close; }
95                         set { this.auto_close = value; }
96                 }
97
98                 [DefaultValue (true)]
99                 public override bool AutoSize {
100                         get { return base.AutoSize; }
101                         set { base.AutoSize = value; }
102                 }
103
104                 [Browsable (false)]
105                 [DefaultValue (false)]
106                 [EditorBrowsable (EditorBrowsableState.Never)]
107                 public new bool CanOverflow {
108                         get { return this.can_overflow; }
109                         set { this.can_overflow = value; }
110                 }
111                 
112                 [Browsable (false)]
113                 [EditorBrowsable (EditorBrowsableState.Never)]
114                 public new ContextMenu ContextMenu {
115                         get { return null; }
116                         set { }
117                 }
118
119                 [Browsable (false)]
120                 [EditorBrowsable (EditorBrowsableState.Never)]
121                 public new ContextMenuStrip ContextMenuStrip {
122                         get { return null; }
123                         set { }
124                 }
125
126                 public override ToolStripDropDownDirection DefaultDropDownDirection {
127                         get { return base.DefaultDropDownDirection; }
128                         set { base.DefaultDropDownDirection = value; }
129                 }
130                 
131                 [Browsable (false)]
132                 [EditorBrowsable (EditorBrowsableState.Always)]
133                 [DefaultValue (DockStyle.None)]
134                 public override DockStyle Dock {
135                         get { return base.Dock; }
136                         set { base.Dock = value; }
137                 }
138                 
139                 public bool DropShadowEnabled {
140                         get { return this.drop_shadow_enabled; }
141                         set {
142                                 if (this.drop_shadow_enabled == value)
143                                         return;
144                                         
145                                 this.drop_shadow_enabled = value;
146                                 UpdateStyles ();        // Re-CreateParams
147                         }
148                 }
149
150                 public override Font Font {
151                         get { return base.Font; }
152                         set { base.Font = value; }
153                 }
154
155                 [Browsable (false)]
156                 [EditorBrowsable (EditorBrowsableState.Never)]
157                 public new ToolStripGripDisplayStyle GripDisplayStyle {
158                         get { return ToolStripGripDisplayStyle.Vertical; }
159                 }
160
161                 [Browsable (false)]
162                 [EditorBrowsable (EditorBrowsableState.Never)]
163                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
164                 public new Padding GripMargin {
165                         get { return Padding.Empty; }
166                         set { }
167                 }
168
169                 [Browsable (false)]
170                 [EditorBrowsable (EditorBrowsableState.Never)]
171                 public new Rectangle GripRectangle {
172                         get { return Rectangle.Empty; }
173                 }
174
175                 [Browsable (false)]
176                 [EditorBrowsable (EditorBrowsableState.Never)]
177                 [DefaultValue (ToolStripGripStyle.Hidden)]
178                 public new ToolStripGripStyle GripStyle {
179                         get { return base.GripStyle; }
180                         set { base.GripStyle = value; }
181                 }
182
183                 [Browsable (false)]
184                 public bool IsAutoGenerated {
185                         get { return this is ToolStripOverflow; }
186                 }
187                 
188                 [Browsable (false)]
189                 [EditorBrowsable (EditorBrowsableState.Never)]
190                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
191                 public new Point Location {
192                         get { return base.Location; }
193                         set { base.Location = value; }
194                 }
195
196                 [DefaultValue (1D)]
197                 [TypeConverter (typeof (OpacityConverter))]
198                 [Browsable (false)]
199                 [EditorBrowsable (EditorBrowsableState.Advanced)]
200                 public double Opacity {
201                         get { return this.opacity; }
202                         set {
203                                         if (this.opacity == value)
204                                                 return;
205                                                 
206                                         this.opacity = value;
207                                         this.allow_transparency = true;
208                                         
209                                         if (this.IsHandleCreated) {
210                                                 UpdateStyles ();
211                                                 XplatUI.SetWindowTransparency (Handle, opacity, Color.Empty);
212                                         }
213                         }
214                 }
215
216                 [Browsable (false)]
217                 [EditorBrowsable (EditorBrowsableState.Never)]
218                 public new ToolStripOverflowButton OverflowButton {
219                         get { return base.OverflowButton; }
220                 }
221
222                 [Browsable (false)]
223                 [DefaultValue (null)]
224                 public ToolStripItem OwnerItem {
225                         get { return this.owner_item; }
226                         set { this.owner_item = value; 
227                                 
228                                 if (this.owner_item != null)
229                                         if (this.owner_item.Owner != null && this.owner_item.Owner.RenderMode != ToolStripRenderMode.ManagerRenderMode)
230                                                 this.Renderer = this.owner_item.Owner.Renderer;
231                         }
232                 }
233
234                 [Browsable (false)]
235                 [EditorBrowsable (EditorBrowsableState.Always)]
236                 public new Region Region {
237                         get { return base.Region; }
238                         set { base.Region = value; }
239                 }
240
241                 [Localizable (true)]
242                 [AmbientValue (RightToLeft.Inherit)]
243                 public override RightToLeft RightToLeft {
244                         get { return base.RightToLeft; }
245                         set { base.RightToLeft = value; }
246                 }
247
248                 [Browsable (false)]
249                 [EditorBrowsable (EditorBrowsableState.Never)]
250                 public new bool Stretch {
251                         get { return false; }
252                         set { }
253                 }
254
255                 [Browsable (false)]
256                 [EditorBrowsable (EditorBrowsableState.Never)]
257                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
258                 public new int TabIndex {
259                         get { return 0; }
260                         set { }
261                 }
262
263                 [Browsable (false)]
264                 [DefaultValue (ToolStripTextDirection.Horizontal)]
265                 public override ToolStripTextDirection TextDirection {
266                         get { return base.TextDirection; }
267                         set { base.TextDirection = value; }
268                 }
269
270                 [Browsable (false)]
271                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
272                 [EditorBrowsable (EditorBrowsableState.Advanced)]
273                 public bool TopLevel {
274                         get { return GetTopLevel (); }
275                         set { SetTopLevel (value); }
276                 }
277                 
278                 [Browsable (false)]
279                 [Localizable (true)]
280                 [DefaultValue (false)]
281                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
282                 public new bool Visible {
283                         get { return base.Visible; }
284                         set { base.Visible = value; }
285                 }
286                 #endregion
287
288                 #region Protected Properties
289                 protected override CreateParams CreateParams {
290                         get {
291                                 CreateParams cp = base.CreateParams;
292
293                                 cp.Style = unchecked ((int)(WindowStyles.WS_POPUP | WindowStyles.WS_CLIPCHILDREN));
294                                 cp.ClassStyle |= (int)XplatUIWin32.ClassStyle.CS_DROPSHADOW;
295                                 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_TOPMOST);
296
297                                 if (Opacity < 1.0 && allow_transparency)
298                                         cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
299                                 if (TopMost)
300                                         cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
301
302                                 return cp;
303                         }
304                 }
305
306                 protected override DockStyle DefaultDock {
307                         get { return DockStyle.None; }
308                 }
309
310                 protected override Padding DefaultPadding {
311                         get { return new Padding (1, 2, 1, 2); }
312                 }
313
314                 protected override bool DefaultShowItemToolTips {
315                         get { return true; }
316                 }
317
318                 protected internal override Size MaxItemSize {
319                         get { return new Size (Screen.PrimaryScreen.Bounds.Width - 2, Screen.PrimaryScreen.Bounds.Height - 34); }
320                 }
321
322                 protected virtual bool TopMost {
323                         get { return true; }
324                 }
325                 #endregion
326
327                 #region Public Methods
328                 public void Close ()
329                 {
330                         this.Close (ToolStripDropDownCloseReason.CloseCalled);
331                 }
332
333                 public void Close (ToolStripDropDownCloseReason reason)
334                 {
335                         if (!this.Visible)
336                                 return;
337                                 
338                         // Give users a chance to cancel the close
339                         ToolStripDropDownClosingEventArgs e = new ToolStripDropDownClosingEventArgs (reason);
340                         this.OnClosing (e);
341
342                         if (e.Cancel)
343                                 return;
344
345                         // Don't actually close if AutoClose == true unless explicitly called
346                         if (!this.auto_close && reason != ToolStripDropDownCloseReason.CloseCalled)
347                                 return;
348
349                         // Detach from the tracker
350                         ToolStripManager.AppClicked -= new EventHandler (ToolStripMenuTracker_AppClicked); ;
351                         ToolStripManager.AppFocusChange -= new EventHandler (ToolStripMenuTracker_AppFocusChange);
352
353                         // Hide this dropdown
354                         this.Hide ();
355
356                         // Owner MenuItem needs to be told to redraw (it's no longer selected)
357                         if (owner_item != null)
358                                 owner_item.Invalidate ();
359
360                         // Recursive hide all child dropdowns
361                         foreach (ToolStripItem tsi in this.Items)
362                                 tsi.Dismiss (reason);
363                         
364                         this.OnClosed (new ToolStripDropDownClosedEventArgs (reason));
365                 }
366
367                 [Browsable (false)]
368                 [EditorBrowsable (EditorBrowsableState.Never)]
369                 public new void Show ()
370                 {
371                         CancelEventArgs e = new CancelEventArgs ();
372                         this.OnOpening (e);
373                         
374                         if (e.Cancel)
375                                 return;
376
377                         // The tracker lets us know when the form is clicked or loses focus
378                         ToolStripManager.AppClicked += new EventHandler (ToolStripMenuTracker_AppClicked);
379                         ToolStripManager.AppFocusChange += new EventHandler (ToolStripMenuTracker_AppFocusChange);
380
381                         base.Show ();
382                         
383                         ToolStripManager.SetActiveToolStrip (this);
384                         
385                         this.OnOpened (EventArgs.Empty);
386                 }
387                 
388                 public void Show (Point screenLocation)
389                 {
390                         this.Location = screenLocation;
391                         Show ();
392                 }
393                 
394                 public void Show (Control control, Point position)
395                 {
396                         if (control == null)
397                                 throw new ArgumentNullException ("control");
398                                 
399                         this.Location = control.PointToScreen (position);
400                         Show ();
401                 }
402                 
403                 public void Show (int x, int y)
404                 {
405                         this.Location = new Point (x, y);
406                         Show ();
407                 }
408                 
409                 public void Show (Point position, ToolStripDropDownDirection direction)
410                 {
411                         this.PerformLayout ();
412                         
413                         Point show_point = position;
414
415                         switch (direction) {
416                                 case ToolStripDropDownDirection.AboveLeft:
417                                         show_point.Y -= this.Height;
418                                         show_point.X -= this.Width;
419                                         break;
420                                 case ToolStripDropDownDirection.AboveRight:
421                                         show_point.Y -= this.Height;
422                                         break;
423                                 case ToolStripDropDownDirection.BelowLeft:
424                                         show_point.X -= this.Width;
425                                         break;
426                                 case ToolStripDropDownDirection.Left:
427                                         show_point.X -= this.Width;
428                                         break;
429                                 case ToolStripDropDownDirection.Right:
430                                         break;
431                         }
432                         
433                         if (this.Location != show_point)
434                                 this.Location = show_point;
435                                 
436                         Show ();
437                 }
438                 
439                 public void Show (Control control, int x, int y)
440                 {
441                         if (control == null)
442                                 throw new ArgumentNullException ("control");
443
444                         Show (control, new Point (x, y));
445                 }
446                 
447                 public void Show (Control control, Point position, ToolStripDropDownDirection direction)
448                 {
449                         if (control == null)
450                                 throw new ArgumentNullException ("control");
451
452                         Show (control.PointToScreen (position), direction);
453                 }
454                 #endregion
455
456                 #region Protected Methods
457                 protected override AccessibleObject CreateAccessibilityInstance ()
458                 {
459                         return new ToolStripDropDownAccessibleObject ();
460                 }
461                 
462                 protected override void CreateHandle ()
463                 {
464                         base.CreateHandle ();
465                 }
466
467                 protected override LayoutSettings CreateLayoutSettings (ToolStripLayoutStyle style)
468                 {
469                         return base.CreateLayoutSettings (style);
470                 }
471                 
472                 protected override void Dispose (bool disposing)
473                 {
474                         base.Dispose (disposing);
475                 }
476
477                 protected virtual void OnClosed (ToolStripDropDownClosedEventArgs e)
478                 {
479                         ToolStripDropDownClosedEventHandler eh = (ToolStripDropDownClosedEventHandler)(Events [ClosedEvent]);
480                         if (eh != null)
481                                 eh (this, e);
482                 }
483
484                 protected virtual void OnClosing (ToolStripDropDownClosingEventArgs e)
485                 {
486                         ToolStripDropDownClosingEventHandler eh = (ToolStripDropDownClosingEventHandler)(Events [ClosingEvent]);
487                         if (eh != null)
488                                 eh (this, e);
489                 }
490
491                 protected override void OnHandleCreated (EventArgs e)
492                 {
493                         base.OnHandleCreated (e);
494
495                         XplatUI.SetOwner (this.Handle, Application.MWFThread.Current.Context.MainForm.Handle);
496                 }
497
498                 protected override void OnItemClicked (ToolStripItemClickedEventArgs e)
499                 {
500                         base.OnItemClicked (e);
501                 }
502
503                 protected override void OnLayout (LayoutEventArgs e)
504                 {
505                         // Find the widest menu item
506                         int widest = 0;
507
508                         foreach (ToolStripItem tsi in this.Items) {
509                                 if (!tsi.Available) 
510                                         continue;
511                                         
512                                 tsi.SetPlacement (ToolStripItemPlacement.Main);
513                                 
514                                 if (tsi.GetPreferredSize (Size.Empty).Width > widest)
515                                         widest = tsi.GetPreferredSize (Size.Empty).Width;
516                         }
517                         
518                         int x = this.Padding.Left;
519                         widest += 68 - this.Padding.Horizontal;
520                         int y = this.Padding.Top;
521
522                         foreach (ToolStripItem tsi in this.Items) {
523                                 if (!tsi.Available)
524                                         continue;
525
526                                 y += tsi.Margin.Top;
527
528                                 int height = 0;
529
530                                 if (tsi is ToolStripSeparator)
531                                         height = 7;
532                                 else
533                                         height = 22;
534
535                                 tsi.SetBounds (new Rectangle (x, y, widest, height));
536                                 y += tsi.Height + tsi.Margin.Bottom;
537                         }
538
539                         this.Size = new Size (widest + this.Padding.Horizontal, y + this.Padding.Bottom);// + 2);
540                         this.SetDisplayedItems ();
541                         this.OnLayoutCompleted (EventArgs.Empty);
542                         this.Invalidate ();
543                 }
544
545                 protected override void OnMouseUp (MouseEventArgs mea)
546                 {
547                         base.OnMouseUp (mea);
548                 }
549
550                 protected virtual void OnOpened (EventArgs e)
551                 {
552                         EventHandler eh = (EventHandler)(Events [OpenedEvent]);
553                         if (eh != null)
554                                 eh (this, e);
555                 }
556
557                 protected virtual void OnOpening (CancelEventArgs e)
558                 {
559                         CancelEventHandler eh = (CancelEventHandler)(Events [OpeningEvent]);
560                         if (eh != null)
561                                 eh (this, e);
562                 }
563
564                 protected override void OnParentChanged (EventArgs e)
565                 {
566                         base.OnParentChanged (e);
567                         
568                         if (Parent is ToolStrip)
569                                 this.Renderer = (Parent as ToolStrip).Renderer;
570                 }
571
572                 protected override void OnVisibleChanged (EventArgs e)
573                 {
574                         base.OnVisibleChanged (e);
575                 }
576
577                 [EditorBrowsable (EditorBrowsableState.Advanced)]
578                 protected override bool ProcessDialogChar (char charCode)
579                 {
580                         return base.ProcessDialogChar (charCode);
581                 }
582
583                 protected override bool ProcessDialogKey (Keys keyData)
584                 {
585                         // We don't want to let our base change the active ToolStrip
586                         switch (keyData) {
587                                 case Keys.Control | Keys.Tab:
588                                 case Keys.Control | Keys.Shift | Keys.Tab:
589                                         return true;
590                         }
591                         
592                         return base.ProcessDialogKey (keyData);
593                 }
594
595                 protected override bool ProcessMnemonic (char charCode)
596                 {
597                         return base.ProcessMnemonic (charCode);
598                 }
599
600                 protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
601                 {
602                         base.ScaleControl (factor, specified);
603                 }
604                 
605                 [EditorBrowsable (EditorBrowsableState.Never)]
606                 protected override void ScaleCore (float dx, float dy)
607                 {
608                         base.ScaleCore (dx, dy);
609                 }
610
611                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
612                 {
613                         base.SetBoundsCore (x, y, width, height, specified);
614                 }
615
616                 protected override void SetVisibleCore (bool value)
617                 {
618                         base.SetVisibleCore (value);
619                 }
620
621                 protected override void WndProc (ref Message m)
622                 {
623                         const int MA_NOACTIVATE = 0x0003;
624
625                         // Don't activate when the WM tells us to
626                         if ((Msg)m.Msg == Msg.WM_MOUSEACTIVATE) {
627                                 m.Result = (IntPtr)MA_NOACTIVATE;
628                                 return;
629                         }
630
631                         base.WndProc (ref m);
632                 }
633                 #endregion
634
635                 #region Public Events
636                 static object ClosedEvent = new object ();
637                 static object ClosingEvent = new object ();
638                 static object OpenedEvent = new object ();
639                 static object OpeningEvent = new object ();
640                 static object ScrollEvent = new object ();
641
642                 [Browsable (false)]
643                 public new event EventHandler BackgroundImageChanged {
644                         add { base.BackgroundImageChanged += value; }
645                         remove { base.BackgroundImageChanged -= value; }
646                 }
647
648                 [Browsable (false)]
649                 public new event EventHandler BackgroundImageLayoutChanged {
650                         add { base.BackgroundImageLayoutChanged += value; }
651                         remove { base.BackgroundImageLayoutChanged -= value; }
652                 }
653
654                 [Browsable (false)]
655                 public new event EventHandler BindingContextChanged {
656                         add { base.BindingContextChanged += value; }
657                         remove { base.BindingContextChanged -= value; }
658                 }
659
660                 [Browsable (false)]
661                 [EditorBrowsable (EditorBrowsableState.Always)]
662                 public new event UICuesEventHandler ChangeUICues {
663                         add { base.ChangeUICues += value; }
664                         remove { base.ChangeUICues -= value; }
665                 }
666
667                 public event ToolStripDropDownClosedEventHandler Closed {
668                         add { Events.AddHandler (ClosedEvent, value); }
669                         remove { Events.RemoveHandler (ClosedEvent, value); }
670                 }
671
672                 public event ToolStripDropDownClosingEventHandler Closing {
673                         add { Events.AddHandler (ClosingEvent, value); }
674                         remove { Events.RemoveHandler (ClosingEvent, value); }
675                 }
676
677                 [Browsable (false)]
678                 [EditorBrowsable (EditorBrowsableState.Never)]
679                 public new event EventHandler ContextMenuChanged {
680                         add { base.ContextMenuChanged += value; }
681                         remove { base.ContextMenuChanged -= value; }
682                 }
683
684                 [Browsable (false)]
685                 [EditorBrowsable (EditorBrowsableState.Always)]
686                 public new event EventHandler ContextMenuStripChanged {
687                         add { base.ContextMenuStripChanged += value; }
688                         remove { base.ContextMenuStripChanged -= value; }
689                 }
690
691                 [Browsable (false)]
692                 [EditorBrowsable (EditorBrowsableState.Always)]
693                 public new event EventHandler DockChanged {
694                         add { base.DockChanged += value; }
695                         remove { base.DockChanged -= value; }
696                 }
697
698                 [Browsable (false)]
699                 [EditorBrowsable (EditorBrowsableState.Always)]
700                 public new event EventHandler Enter {
701                         add { base.Enter += value; }
702                         remove { base.Enter -= value; }
703                 }
704
705                 [Browsable (false)]
706                 [EditorBrowsable (EditorBrowsableState.Always)]
707                 public new event EventHandler FontChanged {
708                         add { base.FontChanged += value; }
709                         remove { base.FontChanged -= value; }
710                 }
711
712                 [Browsable (false)]
713                 [EditorBrowsable (EditorBrowsableState.Never)]
714                 public new event EventHandler ForeColorChanged {
715                         add { base.ForeColorChanged += value; }
716                         remove { base.ForeColorChanged -= value; }
717                 }
718
719                 [Browsable (false)]
720                 [EditorBrowsable (EditorBrowsableState.Never)]
721                 public new event GiveFeedbackEventHandler GiveFeedback {
722                         add { base.GiveFeedback += value; }
723                         remove { base.GiveFeedback -= value; }
724                 }
725
726                 [Browsable (false)]
727                 [EditorBrowsable (EditorBrowsableState.Always)]
728                 public new event HelpEventHandler HelpRequested {
729                         add { base.HelpRequested += value; }
730                         remove { base.HelpRequested -= value; }
731                 }
732
733                 [Browsable (false)]
734                 [EditorBrowsable (EditorBrowsableState.Always)]
735                 public new event EventHandler ImeModeChanged {
736                         add { base.ImeModeChanged += value; }
737                         remove { base.ImeModeChanged -= value; }
738                 }
739
740                 [Browsable (false)]
741                 [EditorBrowsable (EditorBrowsableState.Always)]
742                 public new event KeyEventHandler KeyDown {
743                         add { base.KeyDown += value; }
744                         remove { base.KeyDown -= value; }
745                 }
746
747                 [Browsable (false)]
748                 [EditorBrowsable (EditorBrowsableState.Always)]
749                 public new event KeyPressEventHandler KeyPress {
750                         add { base.KeyPress += value; }
751                         remove { base.KeyPress -= value; }
752                 }
753
754                 [Browsable (false)]
755                 [EditorBrowsable (EditorBrowsableState.Always)]
756                 public new event KeyEventHandler KeyUp {
757                         add { base.KeyUp += value; }
758                         remove { base.KeyUp -= value; }
759                 }
760
761                 [Browsable (false)]
762                 [EditorBrowsable (EditorBrowsableState.Always)]
763                 public new event EventHandler Leave {
764                         add { base.Leave += value; }
765                         remove { base.Leave -= value; }
766                 }
767
768                 public event EventHandler Opened {
769                         add { Events.AddHandler (OpenedEvent, value); }
770                         remove { Events.RemoveHandler (OpenedEvent, value); }
771                 }
772
773                 public event CancelEventHandler Opening {
774                         add { Events.AddHandler (OpeningEvent, value); }
775                         remove { Events.RemoveHandler (OpeningEvent, value); }
776                 }
777
778                 [Browsable (false)]
779                 [EditorBrowsable (EditorBrowsableState.Always)]
780                 public new event EventHandler RegionChanged {
781                         add { base.RegionChanged += value; }
782                         remove { base.RegionChanged -= value; }
783                 }
784
785                 [Browsable (false)]
786                 [EditorBrowsable (EditorBrowsableState.Never)]
787                 public new event ScrollEventHandler Scroll {
788                         add { Events.AddHandler (ScrollEvent, value); }
789                         remove { Events.RemoveHandler (ScrollEvent, value); }
790                 }
791
792                 [Browsable (false)]
793                 [EditorBrowsable (EditorBrowsableState.Always)]
794                 public new event EventHandler StyleChanged {
795                         add { base.StyleChanged += value; }
796                         remove { base.StyleChanged -= value; }
797                 }
798
799                 [Browsable (false)]
800                 [EditorBrowsable (EditorBrowsableState.Never)]
801                 public new event EventHandler TabIndexChanged {
802                         add { base.TabIndexChanged += value; }
803                         remove { base.TabIndexChanged -= value; }
804                 }
805
806                 [Browsable (false)]
807                 [EditorBrowsable (EditorBrowsableState.Never)]
808                 public new event EventHandler TabStopChanged {
809                         add { base.TabStopChanged += value; }
810                         remove { base.TabStopChanged -= value; }
811                 }
812
813                 [Browsable (false)]
814                 [EditorBrowsable (EditorBrowsableState.Never)]
815                 public new event EventHandler TextChanged {
816                         add { base.TextChanged += value; }
817                         remove { base.TextChanged -= value; }
818                 }
819
820                 [Browsable (false)]
821                 [EditorBrowsable (EditorBrowsableState.Never)]
822                 public new event EventHandler Validated {
823                         add { base.Validated += value; }
824                         remove { base.Validated -= value; }
825                 }
826
827                 [Browsable (false)]
828                 [EditorBrowsable (EditorBrowsableState.Never)]
829                 public new event CancelEventHandler Validating {
830                         add { base.Validating += value; }
831                         remove { base.Validating -= value; }
832                 }
833                 #endregion
834
835                 #region Private Methods
836                 internal override void Dismiss (ToolStripDropDownCloseReason reason)
837                 {
838                         this.Close (reason);
839                         base.Dismiss (reason);
840                 }
841
842                 internal override ToolStrip GetTopLevelToolStrip ()
843                 {
844                         if (this.OwnerItem == null)
845                                 return this;
846                                 
847                         return this.OwnerItem.GetTopLevelToolStrip ();
848                 }
849
850                 internal override bool ProcessArrowKey (Keys keyData)
851                 {
852                         switch (keyData) {
853                                 case Keys.Down:
854                                 case Keys.Tab:
855                                         this.SelectNextToolStripItem (this.GetCurrentlySelectedItem (), true);
856                                         return true;
857                                 case Keys.Up:
858                                 case Keys.Shift | Keys.Tab:
859                                         this.SelectNextToolStripItem (this.GetCurrentlySelectedItem (), false);
860                                         return true;
861                                 case Keys.Right:
862                                         this.GetTopLevelToolStrip ().SelectNextToolStripItem (this.TopLevelOwnerItem, true);
863                                         return true;
864                                 case Keys.Left:
865                                 case Keys.Escape:
866                                         this.Dismiss (ToolStripDropDownCloseReason.Keyboard);
867                                         
868                                         ToolStrip parent_strip = this.OwnerItem.Parent;
869                                         ToolStripManager.SetActiveToolStrip (parent_strip);
870                                         
871                                         if (parent_strip is MenuStrip && keyData == Keys.Left) {
872                                                 parent_strip.SelectNextToolStripItem (this.TopLevelOwnerItem, false);
873                                                 this.TopLevelOwnerItem.Invalidate ();
874                                         } else if (parent_strip is MenuStrip && keyData == Keys.Escape) {
875                                                 (parent_strip as MenuStrip).MenuDroppedDown = false;
876                                                 this.TopLevelOwnerItem.Select ();
877                                         }                               
878                                         return true;
879                         }
880                         
881                         return false;
882                 }
883
884                 internal override ToolStripItem SelectNextToolStripItem (ToolStripItem start, bool forward)
885                 {
886                         ToolStripItem next_item = this.GetNextItem (start, forward ? ArrowDirection.Down : ArrowDirection.Up);
887
888                         if (next_item != null)
889                                 this.ChangeSelection (next_item);
890                                 
891                         return (next_item);
892                 }
893                 
894                 private void ToolStripMenuTracker_AppFocusChange (object sender, EventArgs e)
895                 {
896                         this.GetTopLevelToolStrip ().Dismiss (ToolStripDropDownCloseReason.AppFocusChange);
897                 }
898
899                 private void ToolStripMenuTracker_AppClicked (object sender, EventArgs e)
900                 {
901                         this.GetTopLevelToolStrip ().Dismiss (ToolStripDropDownCloseReason.AppClicked);
902                 }
903                 #endregion
904
905                 #region Internal Properties
906                 internal override bool ActivateOnShow { get { return false; } }
907                 
908                 internal ToolStripItem TopLevelOwnerItem {
909                         get {
910                                 ToolStripItem owner_item = this.OwnerItem;
911                                 ToolStrip ts = null;
912
913                                 while (owner_item != null) {
914                                         ts = owner_item.Owner;
915
916                                         if (ts != null && (ts is ToolStripDropDown))
917                                                 owner_item = (ts as ToolStripDropDown).OwnerItem;
918                                         else
919                                                 return owner_item;
920                                 }
921
922                                 return null;
923                         }
924                 }
925                 #endregion
926
927                 #region ToolStripDropDownAccessibleObject
928                 private class ToolStripDropDownAccessibleObject : AccessibleObject
929                 {
930                 }
931                 #endregion
932         }
933 }
934 #endif