Browse Source

2006-10-31 Jonathan Pobst <[email protected]>

	* ToolStrip*: Version 0.2.

	* MenuStrip.cs: Version 0.1.

	* Form.cs: Add a 2.0 MenuStrip tracker like the 1.1 Menu one.

svn path=/trunk/mcs/; revision=67177
Jonathan Pobst 19 years ago
parent
commit
a8143f480b
19 changed files with 1524 additions and 193 deletions
  1. 4 0
      mcs/class/Managed.Windows.Forms/ChangeLog
  2. 3 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms.dll.sources
  3. 8 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
  4. 27 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
  5. 121 5
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs
  6. 5 1
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs
  7. 104 43
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
  8. 3 3
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripControlHost.cs
  9. 543 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs
  10. 177 4
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDownItem.cs
  11. 45 43
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs
  12. 4 4
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItemCollection.cs
  13. 43 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItemEventType.cs
  14. 270 4
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs
  15. 50 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuTracker.cs
  16. 107 82
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripProfessionalRenderer.cs
  17. 6 0
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripRenderEventArgs.cs
  18. 1 1
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitStackLayout.cs
  19. 3 3
      mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripTextBox.cs

+ 4 - 0
mcs/class/Managed.Windows.Forms/ChangeLog

@@ -1,3 +1,7 @@
+2006-10-30  Jonathan Pobst  <[email protected]>
+	* System.Windows.Forms.dll.sources: Add ToolStripDropDown.cs,
+	  ToolStripItemEventType.cs, ToolStripMenuTracker.cs.
+
 2006-10-30  Alexander Olk  <[email protected]>
 
 	* System.Windows.Forms_test.dll.sources: Added UpDownTest.cs.

+ 3 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms.dll.sources

@@ -613,6 +613,7 @@ System.Windows.Forms/ToolStripContentPanel.cs
 System.Windows.Forms/ToolStripContentPanelRenderEventArgs.cs
 System.Windows.Forms/ToolStripContentPanelRenderEventHandler.cs
 System.Windows.Forms/ToolStripControlHost.cs
+System.Windows.Forms/ToolStripDropDown.cs
 System.Windows.Forms/ToolStripDropDownCloseReason.cs
 System.Windows.Forms/ToolStripDropDownClosedEventArgs.cs
 System.Windows.Forms/ToolStripDropDownClosedEventHandler.cs
@@ -632,6 +633,7 @@ System.Windows.Forms/ToolStripItemCollection.cs
 System.Windows.Forms/ToolStripItemDisplayStyle.cs
 System.Windows.Forms/ToolStripItemEventArgs.cs
 System.Windows.Forms/ToolStripItemEventHandler.cs
+System.Windows.Forms/ToolStripItemEventType.cs
 System.Windows.Forms/ToolStripItemImageRenderEventArgs.cs
 System.Windows.Forms/ToolStripItemImageRenderEventHandler.cs
 System.Windows.Forms/ToolStripItemImageScaling.cs
@@ -645,6 +647,7 @@ System.Windows.Forms/ToolStripLabel.cs
 System.Windows.Forms/ToolStripLayoutStyle.cs
 System.Windows.Forms/ToolStripManagerRenderMode.cs
 System.Windows.Forms/ToolStripMenuItem.cs
+System.Windows.Forms/ToolStripMenuTracker.cs
 System.Windows.Forms/ToolStripPanel.cs
 System.Windows.Forms/ToolStripPanelRenderEventArgs.cs
 System.Windows.Forms/ToolStripPanelRenderEventHandler.cs

+ 8 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,11 @@
+2006-10-31  Jonathan Pobst  <[email protected]>
+
+	* ToolStrip*: Version 0.2.
+
+	* MenuStrip.cs: Version 0.1.
+
+	* Form.cs: Add a 2.0 MenuStrip tracker like the 1.1 Menu one.
+
 2006-10-30  Chris Toshok  <[email protected]>
 
 	[ fixes the oversized notify icon issue in bug #79745 ]

+ 27 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs

@@ -1792,11 +1792,27 @@ namespace System.Windows.Forms {
 					return;
 				}
 
+#if NET_2_0
+				case Msg.WM_SYSCOMMAND: {
+					// Let *Strips know the app's title bar was clicked
+					if (XplatUI.IsEnabled (Handle))
+						ToolStripMenuTracker.FireAppClicked ();
+						
+					base.WndProc(ref m);
+					break;
+				}
+#endif
+	
 				case Msg.WM_ACTIVATE: {
 					if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
 						OnActivated(EventArgs.Empty);
 					} else {
 						OnDeactivate(EventArgs.Empty);
+#if NET_2_0
+						// Let *Strips know the app lost focus
+						if (XplatUI.IsEnabled (Handle))
+							ToolStripMenuTracker.FireAppFocusChanged ();
+#endif
 					}
 					return;
 				}
@@ -1944,6 +1960,17 @@ namespace System.Windows.Forms {
 					}
 					break;
 				}
+				
+#if NET_2_0
+				case Msg.WM_MOUSEACTIVATE: {
+					// Let *Strips know the form or another control has been clicked
+					if (XplatUI.IsEnabled (Handle))
+						ToolStripMenuTracker.FireAppClicked ();
+						
+					base.WndProc (ref m);
+					break;				
+				}
+#endif
 
 				default: {
 					base.WndProc (ref m);

+ 121 - 5
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs

@@ -1,3 +1,6 @@
+//
+// MenuStrip.cs
+//
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -17,19 +20,132 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2006 Novell, Inc.
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+//	Jonathan Pobst ([email protected])
 //
 #if NET_2_0
 
 using System;
 using System.Drawing;
 using System.ComponentModel;
+using System.Runtime.InteropServices;
+
+namespace System.Windows.Forms
+{
+	[ClassInterface (ClassInterfaceType.AutoDispatch)]
+	[ComVisible (true)]
+	public class MenuStrip : ToolStrip
+	{
+		private bool can_overflow;
+		private bool stretch;
+
+		public MenuStrip () : base ()
+		{
+			this.GripStyle = ToolStripGripStyle.Hidden;
+			this.stretch = true;
+		}
+
+		#region Public Properties
+		[DefaultValue (false)]
+		public bool CanOverflow
+		{
+			get { return this.can_overflow; }
+			set { this.can_overflow = value; }
+		}
+
+		[DefaultValue (ToolStripGripStyle.Hidden)]
+		public ToolStripGripStyle GripStyle
+		{
+			get { return base.GripStyle; }
+			set { base.GripStyle = value; }
+		}
+
+		[DefaultValue (false)]
+		public bool ShowItemToolTips
+		{
+			get { return base.ShowItemToolTips; }
+			set { base.ShowItemToolTips = value; }
+		}
+
+		[MonoTODO ()]
+		[DefaultValue (true)]
+		public bool Stretch
+		{
+			get { return this.stretch; }
+			set { this.stretch = value; }
+		}
+		#endregion
+
+		#region Protected Properties
+		protected override Padding DefaultGripMargin { get { return new Padding (2, 2, 0, 2); } }
+		protected override Padding DefaultPadding { get { return new Padding (6, 2, 0, 2); } }
+		protected override bool DefaultShowItemToolTips { get { return false; } }
+		protected override Size DefaultSize { get { return new Size (200, 24); } }
+		#endregion
 
-namespace System.Windows.Forms {
-	
-	public class MenuStrip : ScrollableControl, IComponent, IDisposable {
-		public MenuStrip () {}
+		#region Protected Methods
+		protected internal override ToolStripItem CreateDefaultItem (string text, Image image, EventHandler onClick)
+		{
+			return new ToolStripMenuItem (text, image, onClick);
+		}
+
+		protected virtual void OnMenuActivate (EventArgs e)
+		{
+			if (MenuActivate != null) MenuActivate (this, e);
+		}
+
+		protected virtual void OnMenuDeactivate (EventArgs e)
+		{
+			if (MenuDeactivate != null) MenuDeactivate (this, e);
+		}
+
+		protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
+		{
+			return base.ProcessCmdKey (ref msg, keyData);
+		}
+
+		protected override void WndProc (ref Message m)
+		{
+			base.WndProc (ref m);
+		}
+		#endregion
+
+		#region Public Events
+		public event EventHandler MenuActivate;
+		public event EventHandler MenuDeactivate;
+		#endregion
 		
+		#region Internal Methods
+		internal void FireMenuActivate ()
+		{
+			// The tracker lets us know when the form is clicked or loses focus
+			ToolStripMenuTracker.AppClicked += new EventHandler (ToolStripMenuTracker_AppClicked);
+			ToolStripMenuTracker.AppFocusChange += new EventHandler (ToolStripMenuTracker_AppFocusChange);
+			
+			this.OnMenuActivate (EventArgs.Empty);
+		}
+
+		internal void FireMenuDeactivate ()
+		{
+			// Detach from the tracker
+			ToolStripMenuTracker.AppClicked -= new EventHandler (ToolStripMenuTracker_AppClicked); ;
+			ToolStripMenuTracker.AppFocusChange -= new EventHandler (ToolStripMenuTracker_AppFocusChange);
+		
+			this.OnMenuDeactivate (EventArgs.Empty);
+		}
+
+		private void ToolStripMenuTracker_AppFocusChange (object sender, EventArgs e)
+		{
+			this.HideMenus (true, ToolStripDropDownCloseReason.AppFocusChange);
+		}
+
+		private void ToolStripMenuTracker_AppClicked (object sender, EventArgs e)
+		{
+			this.HideMenus (true, ToolStripDropDownCloseReason.AppClicked);
+		}
+		#endregion
 	}
 }
 #endif

+ 5 - 1
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs

@@ -36,6 +36,10 @@ namespace System.Windows.Forms
 {
 	public sealed class TextRenderer
 	{
+		private TextRenderer ()
+		{
+		}
+		
 		#region Public Methods
 		[MonoTODO("This should be correct for Windows, other platforms need a more accurate fallback method than the one provided")]
 		public static void DrawText (IDeviceContext dc, string text, Font font, Rectangle bounds, Color foreColor, TextFormatFlags flags)
@@ -236,4 +240,4 @@ namespace System.Windows.Forms
 	}
 
 }
-#endif
+#endif

+ 104 - 43
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs

@@ -57,6 +57,8 @@ namespace System.Windows.Forms
 		private bool show_item_tool_tips;
 
 		private ToolStripItem mouse_currently_over;
+		private bool menu_selected;
+		private bool need_to_release_menu;
 		#endregion
 
 		#region Public Constructors
@@ -111,7 +113,7 @@ namespace System.Windows.Forms
 					if (this.grip_style == ToolStripGripStyle.Hidden)
 						return new Rectangle (this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical);
 					else
-						return new Rectangle (this.GripRectangle.Right + this.GripMargin.Right + this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal - this.GripRectangle.Right - this.GripMargin.Right, this.Height - this.Padding.Vertical);
+						return new Rectangle (this.GripRectangle.Right + this.GripMargin.Right, this.Padding.Top, this.Width - this.Padding.Horizontal - this.GripRectangle.Right - this.GripMargin.Right, this.Height - this.Padding.Vertical);
 				else
 					if (this.grip_style == ToolStripGripStyle.Hidden)
 						return new Rectangle (this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - this.Padding.Vertical);
@@ -328,6 +330,9 @@ namespace System.Windows.Forms
 			if (text == "-")
 				return new ToolStripSeparator ();
 
+			if (this is ToolStripDropDown)
+				return new ToolStripMenuItem (text, image, onClick);
+				
 			return new ToolStripButton (text, image, onClick);
 		}
 
@@ -407,7 +412,31 @@ namespace System.Windows.Forms
 			base.OnMouseDown (mea);
 
 			if (mouse_currently_over != null)
-				mouse_currently_over.DoMouseDown (mea);
+			{
+				if (this is MenuStrip && !(mouse_currently_over as ToolStripMenuItem).HasDropDownItems) {
+					if (!menu_selected)
+						(this as MenuStrip).FireMenuActivate ();
+					
+					need_to_release_menu = true; 
+					return;
+				}
+					
+				mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseDown);
+				
+				need_to_release_menu = false;
+
+				if (this is MenuStrip && !menu_selected) {
+					(this as MenuStrip).FireMenuActivate ();
+					menu_selected = true;				
+				} else if (this is MenuStrip && menu_selected)
+					need_to_release_menu = true;
+			} else {
+				if (this is MenuStrip)
+					this.HideMenus (true, ToolStripDropDownCloseReason.AppClicked);
+			}
+			
+			if (this is MenuStrip)
+				this.Capture = false;
 		}
 
 		protected override void OnMouseLeave (EventArgs e)
@@ -415,7 +444,7 @@ namespace System.Windows.Forms
 			base.OnMouseLeave (e);
 
 			if (mouse_currently_over != null) {
-				mouse_currently_over.DoMouseLeave (e);
+				mouse_currently_over.FireEvent (e, ToolStripItemEventType.MouseLeave);
 				mouse_currently_over = null;
 			}
 		}
@@ -428,19 +457,32 @@ namespace System.Windows.Forms
 
 			if (tsi != null) {
 				if (tsi == mouse_currently_over) 
-					tsi.DoMouseMove (mea);
+					tsi.FireEvent (mea, ToolStripItemEventType.MouseMove);
 				else {
-					if (mouse_currently_over != null)
-						mouse_currently_over.DoMouseLeave (mea);
-
+					if (mouse_currently_over != null) {
+						mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseLeave);
+						
+						if (mouse_currently_over is ToolStripMenuItem)
+							(mouse_currently_over as ToolStripMenuItem).HideDropDown(ToolStripDropDownCloseReason.Keyboard);
+					} else {
+						foreach (ToolStripItem tsi2 in this.Items)
+							if (tsi2 is ToolStripMenuItem)
+								(tsi2 as ToolStripMenuItem).HideDropDown (ToolStripDropDownCloseReason.Keyboard);
+					}
+						
 					mouse_currently_over = tsi;
-					tsi.DoMouseEnter (mea);
-					tsi.DoMouseMove (mea);
+					
+					tsi.FireEvent (mea, ToolStripItemEventType.MouseEnter);
+					tsi.FireEvent (mea, ToolStripItemEventType.MouseMove);
+
+					if (menu_selected && mouse_currently_over is ToolStripDropDownItem && (mouse_currently_over as ToolStripDropDownItem).HasDropDownItems) {
+						(mouse_currently_over as ToolStripDropDownItem).DropDown.OwnerItem = (ToolStripMenuItem)mouse_currently_over;
+						(mouse_currently_over as ToolStripDropDownItem).DropDown.Show ((mouse_currently_over as ToolStripDropDownItem).DropDownLocation);
+					}
 				}
-			}
-			else {
+			} else {
 				if (mouse_currently_over != null) {
-					mouse_currently_over.DoMouseLeave (mea);
+					mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseLeave);
 					mouse_currently_over = null;
 				}
 			}
@@ -450,8 +492,25 @@ namespace System.Windows.Forms
 		{
 			base.OnMouseUp (mea);
 
-			if (mouse_currently_over != null)
-				mouse_currently_over.DoMouseUp (mea);
+			if (mouse_currently_over != null) {
+				mouse_currently_over.FireEvent (mea, ToolStripItemEventType.MouseUp);
+
+				// The event handler may have blocked until the mouse moved off of the ToolStripItem
+				if (mouse_currently_over == null)
+					return;
+					
+				OnItemClicked (new ToolStripItemClickedEventArgs (mouse_currently_over));
+				
+				if (mouse_currently_over.IsOnDropDown)
+					need_to_release_menu = true;
+					
+				if (this is MenuStrip)
+					if (!(mouse_currently_over as ToolStripMenuItem).HasDropDownItems && !(need_to_release_menu && menu_selected))
+						(this as MenuStrip).FireMenuDeactivate ();
+			}
+
+			if (this is MenuStrip && need_to_release_menu)
+				this.HideMenus (true, ToolStripDropDownCloseReason.ItemClicked);
 		}
 
 		protected override void OnPaint (PaintEventArgs e)
@@ -467,7 +526,7 @@ namespace System.Windows.Forms
 					continue;
 
 				e.Graphics.TranslateTransform (tsi.Bounds.Left, tsi.Bounds.Top);
-				tsi.DoPaint (e);
+				tsi.FireEvent (e, ToolStripItemEventType.Paint);
 				e.Graphics.ResetTransform ();
 			}
 		}
@@ -477,20 +536,29 @@ namespace System.Windows.Forms
 			base.OnPaintBackground (pevent);
 
 			Rectangle affected_bounds = new Rectangle (new Point (0, 0), this.Size);
+			Rectangle connected_area = Rectangle.Empty;
 
-			this.renderer.DrawToolStripBackground (new ToolStripRenderEventArgs (pevent.Graphics, this, affected_bounds, Color.Empty));
-			this.renderer.DrawToolStripBorder (new ToolStripRenderEventArgs (pevent.Graphics, this, affected_bounds, Color.Empty));
+			if (this is ToolStripDropDown && !(this as ToolStripDropDown).OwnerItem.IsOnDropDown)
+				connected_area = new Rectangle (1, 0, (this as ToolStripDropDown).OwnerItem.Width - 2, 2);
+			
+			ToolStripRenderEventArgs e = new ToolStripRenderEventArgs (pevent.Graphics, this, affected_bounds, Color.Empty);
+			e.InternalConnectedArea = connected_area;
+			
+			this.renderer.DrawToolStripBackground (e);
+			this.renderer.DrawToolStripBorder (e);
 		}
 
 		protected internal virtual void OnPaintGrip (PaintEventArgs e)
 		{
 			if (PaintGrip != null) PaintGrip (this, e);
 
-			if (this.orientation == Orientation.Horizontal)
-				e.Graphics.TranslateTransform (2, 0);
-			else
-				e.Graphics.TranslateTransform (0, 2);
-				
+			if (!(this is MenuStrip)) {
+				if (this.orientation == Orientation.Horizontal)
+					e.Graphics.TranslateTransform (2, 0);
+				else
+					e.Graphics.TranslateTransform (0, 2);
+			}
+			
 			this.renderer.DrawGrip (new ToolStripGripRenderEventArgs (e.Graphics, this, this.GripRectangle, this.grip_display_style, this.grip_style));
 			e.Graphics.ResetTransform ();
 		}
@@ -551,31 +619,11 @@ namespace System.Windows.Forms
 			base.OnMouseHover (e);
 
 			if (mouse_currently_over != null)
-				mouse_currently_over.DoMouseHover (e);
-		}
-
-		protected override void OnClick (EventArgs e)
-		{
-			base.OnClick (e);
-
-			if (mouse_currently_over != null) {
-				mouse_currently_over.PerformClick ();
-				OnItemClicked (new ToolStripItemClickedEventArgs (mouse_currently_over));
-			}
-		}
-
-		protected override void OnDoubleClick (EventArgs e)
-		{
-			base.OnDoubleClick (e);
-
-			if (mouse_currently_over != null)
-				mouse_currently_over.DoDoubleClick (e);
+				mouse_currently_over.FireEvent (e, ToolStripItemEventType.MouseHover);
 		}
 		#endregion
 
 		#region Public Events
-		[Browsable (false)]
-		[EditorBrowsable (EditorBrowsableState.Never)]
 		public event EventHandler AutoSizeChanged;
 		[Browsable (false)]
 		public event EventHandler ForeColorChanged;
@@ -617,6 +665,19 @@ namespace System.Windows.Forms
 
 			return new_size;
 		}
+		
+		internal void HideMenus (bool release, ToolStripDropDownCloseReason reason)
+		{
+			if (this is MenuStrip && release && menu_selected)
+				(this as MenuStrip).FireMenuDeactivate ();
+				
+			if (release)
+				menu_selected = false;
+				
+			foreach (ToolStripDropDownItem tsi in this.Items)
+				if (tsi.Visible)
+					tsi.DropDown.Close ();
+		}
 		#endregion
 	}
 }

+ 3 - 3
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripControlHost.cs

@@ -166,7 +166,7 @@ namespace System.Windows.Forms
 			get { return base.Selected; }
 		}
 
-		[EditorBrowsable (EditorBrowsableState.Never)]
+		[EditorBrowsable (EditorBrowsableState.Advanced)]
 		public override ISite Site {
 			get { return base.Site; }
 			set { 
@@ -347,14 +347,14 @@ namespace System.Windows.Forms
 		public event EventHandler DisplayStyleChanged;
 		public event EventHandler Enter;
 		[Browsable (false)]
-		[EditorBrowsable (EditorBrowsableState.Never)]
+		[EditorBrowsable (EditorBrowsableState.Advanced)]
 		public event EventHandler GotFocus;
 		public event KeyEventHandler KeyDown;
 		public event KeyPressEventHandler KeyPress;
 		public event KeyEventHandler KeyUp;
 		public event EventHandler Leave;
 		[Browsable (false)]
-		[EditorBrowsable (EditorBrowsableState.Never)]
+		[EditorBrowsable (EditorBrowsableState.Advanced)]
 		public event EventHandler LostFocus;
 		public event EventHandler Validated;
 		public event CancelEventHandler Validating;

+ 543 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs

@@ -0,0 +1,543 @@
+//
+// ToolStripDropDown.cs
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+//	Jonathan Pobst ([email protected])
+//
+
+#if NET_2_0
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.ComponentModel;
+
+namespace System.Windows.Forms
+{
+	[ClassInterface (ClassInterfaceType.AutoDispatch)]
+	[ComVisible (true)]
+	public class ToolStripDropDown : ToolStrip
+	{
+		private bool allow_transparency;
+		private bool auto_close;
+		private bool drop_shadow_enabled = true;
+		private double opacity = 1D;
+		private ToolStripItem owner_item;
+
+		#region Public Constructor
+		public ToolStripDropDown () : base ()
+		{
+			SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
+			SetStyle (ControlStyles.ResizeRedraw, true);
+
+			this.auto_close = true;
+			is_visible = false;
+			this.GripStyle = ToolStripGripStyle.Hidden;
+		}
+		#endregion
+
+		#region Public Properties
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public bool AllowTransparency {
+			get { return allow_transparency; }
+			set {
+				if (value == allow_transparency)
+					return;
+
+				if (XplatUI.SupportsTransparency ()) {
+					allow_transparency = value;
+
+					if (value) 
+						XplatUI.SetWindowTransparency (Handle, Opacity, Color.Empty);
+					else
+						UpdateStyles (); // Remove the WS_EX_LAYERED style
+				}
+			}
+		}
+
+		[Browsable (false)]
+		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+		public override AnchorStyles Anchor {
+			get { return base.Anchor; }
+			set { base.Anchor = value; }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public bool AutoClose
+		{
+			get { return this.auto_close; }
+			set { this.auto_close = value; }
+		}
+
+		[DefaultValue (true)]
+		public override bool AutoSize {
+			get { return base.AutoSize; }
+			set { base.AutoSize = value; }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public ContextMenu ContextMenu {
+			get { return null; }
+			set { }
+		}
+
+		//[Browsable (false)]
+		//[EditorBrowsable (EditorBrowsableState.Never)]
+		//public ContextMenuStrip ContextMenuStrip {
+		//        get { return null; }
+		//        set { }
+		//}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public override DockStyle Dock {
+			get { return base.Dock; }
+			set { base.Dock = value; }
+		}
+		
+		public bool DropShadowEnabled {
+			get { return this.drop_shadow_enabled; }
+			set {
+				if (this.drop_shadow_enabled == value)
+					return;
+					
+				this.drop_shadow_enabled = value;
+				UpdateStyles ();	// Re-CreateParams
+			}
+		}
+
+		public override Font Font {
+			get { return base.Font; }
+			set { base.Font = value; }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public ToolStripGripDisplayStyle GripDisplayStyle {
+			get { return ToolStripGripDisplayStyle.Vertical; }
+			set { }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public Padding GripMargin {
+			get { return Padding.Empty; }
+			set { }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public Rectangle GripRectangle {
+			get { return Rectangle.Empty; }
+			set { }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public ToolStripGripStyle GripStyle {
+			get { return base.GripStyle; }
+			set { base.GripStyle = value; }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public Point Location {
+			get { return base.Location; }
+			set { base.Location = value; }
+		}
+
+		public double Opacity {
+			get { return this.opacity; }
+			set {
+				if (this.opacity == value)
+					return;
+					
+				this.opacity = value;
+				this.allow_transparency = true;
+
+				UpdateStyles ();
+				XplatUI.SetWindowTransparency (Handle, opacity, Color.Empty);
+			}
+		}
+
+		public ToolStripItem OwnerItem {
+			get { return this.owner_item; }
+			set { this.owner_item = value; }
+		}
+		
+		public Region Region {
+			get { return base.Region; }
+			set { base.Region = value; }
+		}
+
+		[Localizable (true)]
+		public override RightToLeft RightToLeft {
+			get { return base.RightToLeft; }
+			set { base.RightToLeft = value; }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public bool Stretch {
+			get { return false; }
+			set { }
+		}
+
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public int TabIndex {
+			get { return 0; }
+			set { }
+		}
+
+		public bool TopLevel {
+			get { return this.TopMost; }
+			set { }
+		}
+		
+		[Localizable (true)]
+		public bool Visible {
+			get { return base.Visible; }
+			set { base.Visible = value; }
+		}
+		#endregion
+
+		#region Protected Properties
+		protected override CreateParams CreateParams {
+			get {
+				CreateParams cp = base.CreateParams;
+
+				cp.Style = unchecked ((int)(WindowStyles.WS_POPUP | WindowStyles.WS_CLIPCHILDREN));
+				cp.ClassStyle = unchecked ((int)0x82000000);
+				cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_TOPMOST);
+
+				if (Opacity < 1.0 && allow_transparency)
+					cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
+
+				return cp;
+			}
+		}
+
+		protected override DockStyle DefaultDock {
+			get { return DockStyle.None; }
+		}
+
+		protected override Padding DefaultPadding {
+			get { return new Padding (1, 2, 1, 2); }
+		}
+
+		protected override bool DefaultShowItemToolTips {
+			get { return true; }
+		}
+
+		//protected internal override Size MaxItemSize {
+		//        get {  return new Size (Screen.PrimaryScreen.Bounds.Width - 2, Screen.PrimaryScreen.Bounds.Height - 34); }
+		//}
+
+		protected virtual bool TopMost {
+			get { return true; }
+		}
+		#endregion
+
+		#region Public Methods
+		public void Close ()
+		{
+			this.Close (ToolStripDropDownCloseReason.CloseCalled);
+		}
+
+		public void Close (ToolStripDropDownCloseReason reason)
+		{
+			// Give users a chance to cancel the close
+			ToolStripDropDownClosingEventArgs e = new ToolStripDropDownClosingEventArgs (reason);
+			this.OnClosing (e);
+
+			if (e.Cancel)
+				return;
+
+			// Don't actually close if AutoClose == true unless explicitly called
+			if (!this.auto_close && reason != ToolStripDropDownCloseReason.CloseCalled)
+				return;
+
+			// Owner MenuItem needs to be told to redraw (it's no longer selected)
+			if (owner_item != null)
+				(owner_item as ToolStripMenuItem).Invalidate ();
+
+			// Recursive hide all child dropdowns
+			foreach (ToolStripItem tsi in this.Items)
+				if (tsi is ToolStripMenuItem)
+					(tsi as ToolStripMenuItem).HideDropDown (reason);
+
+			// Hide this dropdown
+			this.Hide ();
+			
+			this.OnClosed (new ToolStripDropDownClosedEventArgs (reason));
+		}
+
+		public void Show ()
+		{
+			CancelEventArgs e = new CancelEventArgs ();
+			this.OnOpening (e);
+			
+			if (e.Cancel)
+				return;
+				
+			base.Show ();
+			
+			this.OnOpened (EventArgs.Empty);
+		}
+		
+		public void Show (Point screenLocation)
+		{
+			this.Location = screenLocation;
+			Show ();
+		}
+		
+		public void Show (Control control, Point position)
+		{
+			if (control == null)
+				throw new ArgumentNullException ("control");
+				
+			this.Location = control.PointToScreen (position);
+		}
+		
+		public void Show (int x, int y)
+		{
+			this.Location = new Point (x, y);
+			Show ();
+		}
+		#endregion
+
+		#region Protected Methods
+		protected override void CreateHandle ()
+		{
+			base.CreateHandle ();
+		}
+
+		protected override void Dispose (bool disposing)
+		{
+			base.Dispose (disposing);
+		}
+
+		protected virtual void OnClosed (ToolStripDropDownClosedEventArgs e)
+		{
+			if (Closed != null) Closed (this, e);
+		}
+
+		protected virtual void OnClosing (ToolStripDropDownClosingEventArgs e)
+		{
+			if (Closing != null) Closing (this, e);
+		}
+
+		protected override void OnHandleCreated (EventArgs e)
+		{
+			base.OnHandleCreated (e);
+		}
+
+		protected override void OnItemClicked (ToolStripItemClickedEventArgs e)
+		{
+			base.OnItemClicked (e);
+		}
+
+		protected override void OnLayout (LayoutEventArgs e)
+		{
+			base.OnLayout (e);
+
+			// Find the widest menu item
+			int widest = 0;
+
+			foreach (ToolStripItem tsi in this.Items)
+				if (tsi.GetPreferredSize (Size.Empty).Width > widest)
+					widest = tsi.GetPreferredSize (Size.Empty).Width;
+
+			int x = this.Padding.Left;
+			widest += 68 - this.Padding.Horizontal;
+			int y = this.Padding.Top;
+
+			foreach (ToolStripItem tsi in this.Items) {
+				y += tsi.Margin.Top;
+
+				int height = 0;
+
+				if (tsi is ToolStripSeparator)
+					height = 7;
+				else
+					height = 22;
+
+				tsi.SetBounds (new Rectangle (x, y, widest, height));
+				y += tsi.Height + tsi.Margin.Bottom;
+			}
+
+			this.Size = new Size (widest + this.Padding.Horizontal, y + this.Padding.Bottom);// + 2);
+		}
+
+		protected override void OnMouseUp (MouseEventArgs mea)
+		{
+			base.OnMouseUp (mea);
+		}
+
+		protected virtual void OnOpened (EventArgs e)
+		{
+			if (Opened != null) Opened (this, e);
+		}
+
+		protected virtual void OnOpening (CancelEventArgs e)
+		{
+			if (Opening != null) Opening (this, e);
+		}
+
+		protected override void OnParentChanged (EventArgs e)
+		{
+			base.OnParentChanged (e);
+		}
+
+		protected override void OnVisibleChanged (EventArgs e)
+		{
+			base.OnVisibleChanged (e);
+		}
+
+		protected override bool ProcessDialogChar (char charCode)
+		{
+			return base.ProcessDialogChar (charCode);
+		}
+
+		protected override bool ProcessDialogKey (Keys keyData)
+		{
+			return base.ProcessDialogKey (keyData);
+		}
+
+		protected override bool ProcessMnemonic (char charCode)
+		{
+			return base.ProcessMnemonic (charCode);
+		}
+
+		protected override void ScaleCore (float dx, float dy)
+		{
+			base.ScaleCore (dx, dy);
+		}
+
+		protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
+		{
+			base.SetBoundsCore (x, y, width, height, specified);
+		}
+
+		protected override void SetVisibleCore (bool value)
+		{
+			// Copied from Control.cs, changed XPlatUI.SetVisible(,,) to NO_ACTIVATE
+			if (value != is_visible) {
+				if (value && (window.Handle == IntPtr.Zero) || !is_created)
+					CreateControl ();
+
+				is_visible = value;
+
+				if (IsHandleCreated)
+					XplatUI.SetVisible (Handle, value, false);
+
+				OnVisibleChanged (EventArgs.Empty);
+
+				if (value == false && parent != null && Focused) {
+					Control container;
+
+					// Need to start at parent, GetContainerControl might return ourselves if we're a container
+					container = (Control)parent.GetContainerControl ();
+					
+					if (container != null)
+						container.SelectNextControl (this, true, true, true, true);
+				}
+
+				if (parent != null)
+					parent.PerformLayout (this, "visible");
+				else
+					PerformLayout (this, "visible");
+			}
+		}
+
+		protected override void WndProc (ref Message m)
+		{
+			const int MA_NOACTIVATE = 0x0003;
+
+			// Don't activate when the WM tells us to
+			if ((Msg)m.Msg == Msg.WM_MOUSEACTIVATE) {
+				m.Result = (IntPtr)MA_NOACTIVATE;
+				return;
+			}
+
+			base.WndProc (ref m);
+		}
+		#endregion
+
+		#region Public Events
+		public event EventHandler BackgroundImageChanged;
+		public event EventHandler BackgroundImageLayoutChanged;
+		public event EventHandler BindingContextChanged;
+		public event UICuesEventHandler ChangeUICues;
+		public event ToolStripDropDownClosedEventHandler Closed;
+		public event ToolStripDropDownClosingEventHandler Closing;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler ContextMenuChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler ContextMenuStripChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler DockChanged;
+		public event EventHandler Enter;
+		public event EventHandler FontChanged;
+		public event EventHandler ForeColorChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event GiveFeedbackEventHandler GiveFeedback;
+		public event HelpEventHandler HelpRequested;
+		public event EventHandler ImeModeChanged;
+		public event KeyEventHandler KeyDown;
+		public event KeyPressEventHandler KeyPress;
+		public event KeyEventHandler KeyUp;
+		public event EventHandler Leave;
+		public event EventHandler Opened;
+		public event CancelEventHandler Opening;
+		public event EventHandler RegionChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event ScrollEventHandler Scroll;
+		public event EventHandler StyleChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler TabIndexChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler TabStopChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler TextChanged;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event EventHandler Validated;
+		[Browsable (false)]
+		[EditorBrowsable (EditorBrowsableState.Never)]
+		public event CancelEventHandler Validating;
+		#endregion
+	}
+}
+#endif

+ 177 - 4
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDownItem.cs

@@ -1,3 +1,6 @@
+//
+// ToolStripDropDownItem.cs
+//
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -17,18 +20,188 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2006 Novell, Inc.
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+//	Jonathan Pobst ([email protected])
 //
 #if NET_2_0
 
 using System;
 using System.Drawing;
 using System.ComponentModel;
+using System.Threading;
+
+namespace System.Windows.Forms
+{
+	public abstract class ToolStripDropDownItem : ToolStripItem
+	{
+		private ToolStripDropDown drop_down;
+		private ToolStripDropDownDirection drop_down_direction;
+
+		#region Protected Constructors
+		protected ToolStripDropDownItem () : this (string.Empty, null, null, string.Empty)
+		{
+		}
+
+		protected ToolStripDropDownItem (string text, Image image, EventHandler onClick)
+			: this (text, image, onClick, string.Empty)
+		{
+		}
+
+		protected ToolStripDropDownItem (string text, Image image, params ToolStripItem[] dropDownItems)
+			: this (text, image, null, string.Empty)
+		{
+		}
+
+		protected ToolStripDropDownItem (string text, Image image, EventHandler onClick, string name)
+			: base (text, image, onClick, name)
+		{
+			this.drop_down = CreateDefaultDropDown ();
+			this.drop_down.ItemAdded += new ToolStripItemEventHandler (DropDown_ItemAdded);
+		}
+		#endregion
+
+		#region Public Properties
+		public ToolStripDropDown DropDown {
+			get { return this.drop_down; }
+			set { this.drop_down = value; }
+		}
+
+		public ToolStripDropDownDirection DropDownDirection {
+			get { return this.drop_down_direction; }
+			set {
+				if (!Enum.IsDefined (typeof (ToolStripDropDownDirection), value))
+					throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripDropDownDirection", value));
+
+				this.drop_down_direction = value;
+			}
+		}
+
+		public ToolStripItemCollection DropDownItems {
+			get { return this.drop_down.Items; }
+		}
+
+		public virtual bool HasDropDownItems {
+			get { return this.drop_down.Items.Count != 0; }
+		}
+
+		public override bool Pressed {
+			get { return base.Pressed && this.HasDropDownItems; }
+		}
+		#endregion
+
+		#region Protected Properties
+		protected internal virtual Point DropDownLocation {
+			get {
+				Point p;
+
+				if (this.IsOnDropDown) {
+					p = Parent.PointToScreen (new Point (this.Bounds.Left, this.Bounds.Top - 1));
+					p.X += this.Bounds.Width;
+					p.Y += this.Bounds.Left;
+					return p;
+				}
+				else
+					p = new Point (this.Bounds.Left, this.Bounds.Bottom - 1);
+
+				return Parent.PointToScreen (p);
+			}
+		}
+		#endregion
+
+		#region Public Methods
+		public void HideDropDown ()
+		{
+			if (!this.DropDown.Visible)
+				return;
+
+			this.DropDown.Close (ToolStripDropDownCloseReason.CloseCalled);
+			this.is_pressed = false;
+			this.Invalidate ();
+			this.OnDropDownHide (EventArgs.Empty);
+			this.OnDropDownClosed (EventArgs.Empty);
+		}
+
+		public void ShowDropDown ()
+		{
+			this.DropDown.OwnerItem = this;
+			
+			this.DropDown.Show (this.DropDownLocation);
+			this.OnDropDownShow (EventArgs.Empty);
+		}
+		#endregion
+
+		#region Protected Methods
+		protected virtual ToolStripDropDown CreateDefaultDropDown ()
+		{
+			return new ToolStripDropDown ();
+		}
+
+		protected override void Dispose (bool disposing)
+		{
+			base.Dispose (disposing);
+		}
+
+		protected override void OnBoundsChanged ()
+		{
+			base.OnBoundsChanged ();
+		}
+
+		protected internal virtual void OnDropDownClosed (EventArgs e)
+		{
+			if (DropDownClosed != null) DropDownClosed (this, e);
+		}
+
+		protected virtual void OnDropDownHide (EventArgs e)
+		{
+		}
+
+		protected internal virtual void OnDropDownItemClicked (ToolStripItemClickedEventArgs e)
+		{
+			if (DropDownItemClicked != null) DropDownItemClicked (this, e);
+		}
+
+		protected internal virtual void OnDropDownOpened (EventArgs e)
+		{
+			if (DropDownOpened != null) DropDownOpened (this, e);
+		}
+
+		protected virtual void OnDropDownShow (EventArgs e)
+		{
+		}
+
+		protected override void OnFontChanged (EventArgs e)
+		{
+			base.OnFontChanged (e);
+		}
+		#endregion
+
+		#region Public Events
+		public event EventHandler DropDownClosed;
+		public event ToolStripItemClickedEventHandler DropDownItemClicked;
+		public event EventHandler DropDownOpened;
+		public event EventHandler DropDownOpening;
+		#endregion
+
+		#region Internal Methods
+		internal void HideDropDown (ToolStripDropDownCloseReason reason)
+		{
+			if (!this.DropDown.Visible)
+				return;
 
-namespace System.Windows.Forms {
-	
-	public abstract class ToolStripDropDownItem : ToolStripItem {
+			this.DropDown.Close (reason);
+			this.is_pressed = false;
+			this.Invalidate ();
+			this.OnDropDownHide (EventArgs.Empty);
+			this.OnDropDownClosed (EventArgs.Empty);
+		}
 		
+		private void DropDown_ItemAdded (object sender, ToolStripItemEventArgs e)
+		{
+			e.Item.owner_item = this;
+		}
+		#endregion
 	}
 }
 #endif

+ 45 - 43
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs

@@ -59,12 +59,12 @@ namespace System.Windows.Forms
 		private ContentAlignment image_align;
 		private int image_index;
 		private ToolStripItemImageScaling image_scaling;
-		private bool is_pressed;
+		protected bool is_pressed;
 		private bool is_selected;
 		private Padding margin;
 		private string name;
 		private ToolStrip owner;
-		private ToolStripItem owner_item;
+		internal ToolStripItem owner_item;
 		private Padding padding;
 		private Object tag;
 		private string text;
@@ -195,7 +195,7 @@ namespace System.Windows.Forms
 		}
 
 		[MonoTODO ("Need 2.0 ToolTip to implement tool tips.")]
-		[DefaultValue (true)]
+		[DefaultValue (false)]
 		public bool AutoToolTip {
 			get { return this.auto_tool_tip; }
 			set { this.auto_tool_tip = value; }
@@ -341,7 +341,7 @@ namespace System.Windows.Forms
 		}
 
 		[Localizable (true)]
-		[DefaultValue (ContentAlignment.MiddleLeft)]
+		[DefaultValue (ContentAlignment.MiddleCenter)]
 		public ContentAlignment ImageAlign {
 			get { return this.image_align; }
 			set {
@@ -380,8 +380,8 @@ namespace System.Windows.Forms
 		[Browsable (false)]
 		public bool IsOnDropDown {
 			get {
-				//if (this.owner != null && this.owner is ToolStripDropDown)
-				//	return true;
+				if (this.owner != null && this.owner is ToolStripDropDown)
+					return true;
 
 				return false;
 			}
@@ -471,7 +471,7 @@ namespace System.Windows.Forms
 		}
 
 		[Localizable (true)]
-		[DefaultValue (ContentAlignment.MiddleRight)]
+		[DefaultValue (ContentAlignment.MiddleCenter)]
 		public virtual ContentAlignment TextAlign {
 			get { return this.text_align; }
 			set {
@@ -683,12 +683,11 @@ namespace System.Windows.Forms
 
 		protected virtual void OnMouseEnter (EventArgs e)
 		{
-			if (this.Enabled) {
-				if (MouseEnter != null) MouseEnter (this, e);
-				if (this.CanSelect) {
-					this.is_selected = true;
-					this.Invalidate ();
-				}
+			if (MouseEnter != null) MouseEnter (this, e);
+			
+			if (this.CanSelect) {
+				this.is_selected = true;
+				this.Invalidate ();
 			}
 		}
 
@@ -700,13 +699,12 @@ namespace System.Windows.Forms
 
 		protected virtual void OnMouseLeave (EventArgs e)
 		{
-			if (this.Enabled) {
-				if (MouseLeave != null) MouseLeave (this, e);
-				if (this.CanSelect) {
-					this.is_selected = false;
-					this.is_pressed = false;
-					this.Invalidate ();
-				}
+			if (MouseLeave != null) MouseLeave (this, e);
+			
+			if (this.CanSelect) {
+				this.is_selected = false;
+				this.is_pressed = false;
+				this.Invalidate ();
 			}
 		}
 
@@ -949,29 +947,33 @@ namespace System.Windows.Forms
 			}
 		}
 
-		internal void DoDoubleClick (EventArgs e)
-		{ this.OnDoubleClick (e); }
-
-		internal void DoMouseDown (MouseEventArgs e)
-		{ this.OnMouseDown (e); }
-
-		internal void DoMouseEnter (EventArgs e)
-		{ this.OnMouseEnter (e); }
-
-		internal void DoMouseHover (EventArgs e)
-		{ this.OnMouseHover (e); }
-
-		internal void DoMouseLeave (EventArgs e)
-		{ this.OnMouseLeave (e); }
-
-		internal void DoMouseMove (MouseEventArgs e)
-		{ this.OnMouseMove (e); }
-
-		internal void DoMouseUp (MouseEventArgs e)
-		{ this.OnMouseUp (e); }
-
-		internal void DoPaint (PaintEventArgs e)
-		{ this.OnPaint (e); }
+		internal void FireEvent (EventArgs e, ToolStripItemEventType met)
+		{
+			switch (met) {
+				case ToolStripItemEventType.MouseUp:
+					this.OnMouseUp ((MouseEventArgs)e);
+					this.OnClick ((MouseEventArgs)e);
+					break;
+				case ToolStripItemEventType.MouseDown:
+					this.OnMouseDown ((MouseEventArgs)e);
+					break;
+				case ToolStripItemEventType.MouseEnter:
+					this.OnMouseEnter (e);
+					break;
+				case ToolStripItemEventType.MouseHover:
+					this.OnMouseHover (e);
+					break;
+				case ToolStripItemEventType.MouseLeave:
+					this.OnMouseLeave (e);
+					break;
+				case ToolStripItemEventType.MouseMove:
+					this.OnMouseMove ((MouseEventArgs)e);
+					break;
+				case ToolStripItemEventType.Paint:
+					this.OnPaint ((PaintEventArgs)e);
+					break;
+			}
+		}
 		#endregion
 		
 		public class ToolStripItemAccessibleObject : AccessibleObject

+ 4 - 4
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItemCollection.cs

@@ -70,14 +70,14 @@ namespace System.Windows.Forms
 		#region Public Methods
 		public ToolStripItem Add (Image image)
 		{
-			ToolStripButton tsb = new ToolStripButton (image);
+			ToolStripItem tsb = owner.CreateDefaultItem (string.Empty, image, null);
 			this.Add (tsb);
 			return tsb;
 		}
 
 		public ToolStripItem Add (string text)
 		{
-			ToolStripButton tsb = new ToolStripButton (text);
+			ToolStripItem tsb = owner.CreateDefaultItem (text, null, null);
 			this.Add (tsb);
 			return tsb;
 		}
@@ -96,14 +96,14 @@ namespace System.Windows.Forms
 
 		public ToolStripItem Add (string text, Image image)
 		{
-			ToolStripButton tsb = new ToolStripButton (text, image);
+			ToolStripItem tsb = owner.CreateDefaultItem (text, image, null);
 			this.Add (tsb);
 			return tsb;
 		}
 
 		public ToolStripItem Add (string text, Image image, EventHandler onClick)
 		{
-			ToolStripButton tsb = new ToolStripButton (text, image, onClick);
+			ToolStripItem tsb = owner.CreateDefaultItem (text, image, onClick);
 			this.Add (tsb);
 			return tsb;
 		}

+ 43 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItemEventType.cs

@@ -0,0 +1,43 @@
+//
+// ToolStripItemEventType.cs
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+//	Jonathan Pobst ([email protected])
+//
+
+#if NET_2_0
+namespace System.Windows.Forms
+{
+	internal enum ToolStripItemEventType
+	{
+		MouseDown = 1,
+		MouseEnter = 2,
+		MouseHover = 3,
+		MouseLeave = 4,
+		MouseMove = 5,
+		MouseUp = 6,
+		Paint = 7
+	}
+}
+#endif

+ 270 - 4
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs

@@ -1,3 +1,6 @@
+//
+// ToolStripMenuItem.cs
+//
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -17,7 +20,10 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2006 Novell, Inc.
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+//	Jonathan Pobst ([email protected])
 //
 #if NET_2_0
 
@@ -25,9 +31,269 @@ using System;
 using System.Drawing;
 using System.ComponentModel;
 
-namespace System.Windows.Forms {
-	
-	public class ToolStripMenuItem : ToolStripDropDownItem {
+namespace System.Windows.Forms
+{
+	public class ToolStripMenuItem : ToolStripDropDownItem
+	{
+		private CheckState checked_state;
+		private bool check_on_click;
+
+		#region Public Constructors
+		public ToolStripMenuItem ()
+			: base ()
+		{
+		}
+
+		public ToolStripMenuItem (Image image)
+			: base (string.Empty, image, null, string.Empty)
+		{
+		}
+
+		public ToolStripMenuItem (string text)
+			: base (text, null, null, string.Empty)
+		{
+		}
+
+		public ToolStripMenuItem (string text, Image image)
+			: base (text, image, null, string.Empty)
+		{
+		}
+
+		public ToolStripMenuItem (string text, Image image, EventHandler onClick)
+			: base (text, image, onClick, string.Empty)
+		{
+		}
+
+		public ToolStripMenuItem (string text, Image image, params ToolStripItem[] dropDownItems)
+			: base (text, image, null, string.Empty)
+		{
+			if (dropDownItems != null)
+				foreach (ToolStripItem tsi in dropDownItems)
+					this.DropDownItems.Add (tsi);
+		}
+
+		public ToolStripMenuItem (string text, Image image, EventHandler onClick, Keys shortcutKeys)
+			: base (text, image, onClick, string.Empty)
+		{
+		}
+
+		public ToolStripMenuItem (string text, Image image, EventHandler onClick, string name)
+			: base (text, image, onClick, name)
+		{
+		}
+		#endregion
+
+		#region Public Properties
+		[Bindable (true)]
+		[DefaultValue (false)]
+		public bool Checked {
+			get {
+				switch (this.checked_state) {
+					case CheckState.Unchecked:
+					default:
+						return false;
+					case CheckState.Checked:
+					case CheckState.Indeterminate:
+						return true;
+				}
+			}
+			set {
+				if (this.checked_state != (value ? CheckState.Checked : CheckState.Unchecked)) {
+					this.checked_state = value ? CheckState.Checked : CheckState.Unchecked;
+					this.OnCheckedChanged (EventArgs.Empty);
+					this.Invalidate ();
+				}
+			}
+		}
+
+		[DefaultValue (false)]
+		public bool CheckOnClick {
+			get { return this.check_on_click; }
+			set { this.check_on_click = value; }
+		}
+
+		[Bindable (true)]
+		[DefaultValue (CheckState.Unchecked)]
+		public CheckState CheckState
+		{
+			get { return this.checked_state; }
+			set
+			{
+				if (!Enum.IsDefined (typeof (CheckState), value))
+					throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for CheckState", value));
+
+				this.checked_state = value;
+				OnCheckStateChanged (EventArgs.Empty);
+				this.Invalidate ();
+			}
+		}
+
+		public override bool Enabled {
+			get { return base.Enabled; }
+			set { base.Enabled = value; }
+		}
+		#endregion
+
+		#region Protected Properties
+		protected internal override Padding DefaultMargin {
+			get { return new Padding (0); }
+		}
+
+		protected override Padding DefaultPadding {
+			get { return new Padding (4, 0, 4, 0); }
+		}
+
+		protected override Size DefaultSize {
+			get { return new Size (32, 19); }
+		}
+		#endregion
+
+		#region Protected Methods
+		protected override ToolStripDropDown CreateDefaultDropDown ()
+		{
+			return base.CreateDefaultDropDown ();
+		}
+
+		protected override void Dispose (bool disposing)
+		{
+			base.Dispose (disposing);
+		}
+
+		protected virtual void OnCheckedChanged (EventArgs e)
+		{
+			if (CheckedChanged != null) CheckedChanged (this, e);
+		}
+
+		protected virtual void OnCheckStateChanged (EventArgs e)
+		{
+			if (CheckStateChanged != null) CheckStateChanged (this, e);
+		}
+
+		protected override void OnClick (EventArgs e)
+		{
+			if (!this.Enabled)
+				return;
+				
+			base.OnClick (e);
+
+			if (this.IsOnDropDown) {
+				if (this.HasDropDownItems)
+					return;
+
+				this.HideDropDown (ToolStripDropDownCloseReason.ItemClicked);
+				(this.Parent as ToolStripDropDown).Close (ToolStripDropDownCloseReason.ItemClicked);
+
+				Object parent = this.Parent;
+
+				// Find the top level MenuStrip to inform it to close all open
+				// dropdowns because this one was clicked
+				while (parent != null) {
+					if (parent is MenuStrip)
+						(parent as MenuStrip).HideMenus (true, ToolStripDropDownCloseReason.ItemClicked);
+
+					if (parent is ToolStripDropDown)
+						parent = (parent as ToolStripDropDown).OwnerItem;
+					else if (parent is ToolStripItem)
+						parent = (parent as ToolStripItem).Parent;
+					else
+						break;
+				}
+			}
+
+			if (this.check_on_click)
+				this.Checked = !this.Checked;
+		}
+
+		protected override void OnDropDownHide (EventArgs e)
+		{
+			base.OnDropDownHide (e);
+		}
+
+		protected override void OnDropDownShow (EventArgs e)
+		{
+			base.OnDropDownShow (e);
+		}
+
+		protected override void OnFontChanged (EventArgs e)
+		{
+			base.OnFontChanged (e);
+		}
+
+		protected override void OnMouseDown (MouseEventArgs e)
+		{
+			base.OnMouseDown (e);
+
+			if (this.HasDropDownItems)
+				if (!this.DropDown.Visible)
+					this.ShowDropDown ();
+		}
+
+		protected override void OnMouseEnter (EventArgs e)
+		{
+			base.OnMouseEnter (e);
+
+			if (this.IsOnDropDown && this.HasDropDownItems)
+				this.ShowDropDown ();
+		}
+
+		protected override void OnMouseLeave (EventArgs e)
+		{
+			base.OnMouseLeave (e);
+		}
+
+		protected override void OnMouseUp (MouseEventArgs e)
+		{
+			base.OnMouseUp (e);
+		}
+
+		protected override void OnOwnerChanged (EventArgs e)
+		{
+			base.OnOwnerChanged (e);
+		}
+
+		protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
+		{
+			base.OnPaint (e);
+
+			if (this.Owner != null) {
+				Color font_color = this.Enabled ? this.ForeColor : SystemColors.GrayText;
+				Image draw_image = this.Enabled ? this.Image : ToolStripRenderer.CreateDisabledImage (this.Image);
+
+				if (this.IsOnDropDown)
+					this.Owner.Renderer.DrawMenuItemBackground (new System.Windows.Forms.ToolStripItemRenderEventArgs (e.Graphics, this));
+				else
+					this.Owner.Renderer.DrawButtonBackground (new System.Windows.Forms.ToolStripItemRenderEventArgs (e.Graphics, this));
+
+				Rectangle text_layout_rect;
+				Rectangle image_layout_rect;
+
+				this.CalculateTextAndImageRectangles (out text_layout_rect, out image_layout_rect);
+
+				if (this.IsOnDropDown) {
+					text_layout_rect = new Rectangle (35, text_layout_rect.Top, text_layout_rect.Width, text_layout_rect.Height);
+					if (image_layout_rect != Rectangle.Empty)
+						image_layout_rect = new Rectangle (4, 3, draw_image.Width, draw_image.Height);
+
+					if (this.Checked)
+						this.Owner.Renderer.DrawItemCheck (new ToolStripItemImageRenderEventArgs (e.Graphics, this, new Rectangle (2, 1, 19, 19)));
+				}
+				if (text_layout_rect != Rectangle.Empty)
+					this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
+
+				if (image_layout_rect != Rectangle.Empty)
+					this.Owner.Renderer.DrawItemImage (new System.Windows.Forms.ToolStripItemImageRenderEventArgs (e.Graphics, this, draw_image, image_layout_rect));
+
+				if (this.IsOnDropDown && this.HasDropDownItems)
+					this.Owner.Renderer.DrawArrow (new ToolStripArrowRenderEventArgs (e.Graphics, this, new Rectangle (this.Bounds.Width - 17, 2, 10, 20), Color.Black, ArrowDirection.Right));
+				return;
+			}
+		}
+		#endregion
+
+		#region Public Events
+		public event EventHandler CheckedChanged;
+		public event EventHandler CheckStateChanged;
+		#endregion
 	}
 }
 #endif

+ 50 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuTracker.cs

@@ -0,0 +1,50 @@
+//
+// ToolStripMenuTracker.cs
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+//	Jonathan Pobst ([email protected])
+//
+
+#if NET_2_0
+namespace System.Windows.Forms
+{
+	internal static class ToolStripMenuTracker
+	{
+		public static void FireAppClicked ()
+		{
+			if (AppClicked != null) AppClicked (null, EventArgs.Empty);
+		}
+
+		public static void FireAppFocusChanged ()
+		{
+			if (AppFocusChange != null) AppFocusChange (null, EventArgs.Empty);
+		}
+
+		#region Public Events
+		public static event EventHandler AppClicked;
+		public static event EventHandler AppFocusChange;
+		#endregion
+	}
+}
+#endif

+ 107 - 82
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripProfessionalRenderer.cs

@@ -39,9 +39,13 @@ namespace System.Windows.Forms
 		private bool rounded_edges;
 
 		#region Public Constructor
-		public ToolStripProfessionalRenderer () : base ()
+		public ToolStripProfessionalRenderer () : this (new ProfessionalColorTable ())
 		{
-			color_table = new ProfessionalColorTable ();
+		}
+		
+		public ToolStripProfessionalRenderer (ProfessionalColorTable professionalColorTable) : base ()
+		{
+			color_table = professionalColorTable;
 			rounded_edges = true;
 		}
 		#endregion
@@ -49,7 +53,6 @@ namespace System.Windows.Forms
 		#region Public Properties
 		public ProfessionalColorTable ColorTable {
 			get { return this.color_table; }
-			set { this.color_table = value; }
 		}
 
 		public bool RoundedEdges {
@@ -61,15 +64,32 @@ namespace System.Windows.Forms
 		#region Protected Methods
 		protected override void OnRenderArrow (ToolStripArrowRenderEventArgs e)
 		{
-			base.OnRenderArrow (e);
-			
-			using (Pen p = new Pen (e.ArrowColor)) {
-				int x = e.ArrowRectangle.Left + (e.ArrowRectangle.Width / 2) - 3;
-				int y = e.ArrowRectangle.Top + (e.ArrowRectangle.Height / 2) - 2;
-
-				e.Graphics.DrawLine (p, x + 1, y, x + 5, y);
-				e.Graphics.DrawLine (p, x + 2, y + 1, x + 4, y + 1);
-				e.Graphics.DrawLine (p, x + 3, y + 1, x + 3, y + 2);
+			switch (e.Direction) {
+				case ArrowDirection.Down:
+					using (Pen p = new Pen (e.ArrowColor)) {
+						int x = e.ArrowRectangle.Left + (e.ArrowRectangle.Width / 2) - 3;
+						int y = e.ArrowRectangle.Top + (e.ArrowRectangle.Height / 2) - 2;
+
+						e.Graphics.DrawLine (p, x + 1, y, x + 5, y);
+						e.Graphics.DrawLine (p, x + 2, y + 1, x + 4, y + 1);
+						e.Graphics.DrawLine (p, x + 3, y + 1, x + 3, y + 2);
+					}
+					break;
+				case ArrowDirection.Left:
+					break;
+				case ArrowDirection.Right:
+					using (Pen p = new Pen (e.ArrowColor)) {
+						int x = e.ArrowRectangle.Left + (e.ArrowRectangle.Width / 2) - 3;
+						int y = e.ArrowRectangle.Top + (e.ArrowRectangle.Height / 2) - 4;
+
+						e.Graphics.DrawLine (p, x, y, x, y + 6);
+						e.Graphics.DrawLine (p, x + 1, y + 1, x + 1, y + 5);
+						e.Graphics.DrawLine (p, x + 2, y + 2, x + 2, y + 4);
+						e.Graphics.DrawLine (p, x + 2, y + 3, x + 3, y + 3);
+					}
+					break;
+				case ArrowDirection.Up:
+					break;
 			}
 		}
 
@@ -86,8 +106,11 @@ namespace System.Windows.Forms
 			if (e.Item is ToolStripButton && (e.Item as ToolStripButton).Checked && !e.Item.Selected)
 				using (Brush b = new LinearGradientBrush (paint_here, this.ColorTable.ButtonCheckedGradientBegin, this.ColorTable.ButtonCheckedGradientEnd, LinearGradientMode.Vertical))
 					e.Graphics.FillRectangle (b, paint_here);
-			else 
-				if (e.Item.Pressed || (e.Item is ToolStripButton && (e.Item as ToolStripButton).Checked))
+			else
+				if (e.Item is ToolStripMenuItem && (e.Item.Pressed || (e.Item as ToolStripMenuItem).DropDown.Visible == true))
+					using (Brush b = new LinearGradientBrush (paint_here, this.ColorTable.ToolStripGradientBegin, this.ColorTable.ToolStripGradientEnd, LinearGradientMode.Vertical))
+						e.Graphics.FillRectangle (b, paint_here);
+				else if (e.Item.Pressed || (e.Item is ToolStripButton && (e.Item as ToolStripButton).Checked))
 					using (Brush b = new LinearGradientBrush (paint_here, this.ColorTable.ButtonPressedGradientBegin, this.ColorTable.ButtonPressedGradientEnd, LinearGradientMode.Vertical))
 						e.Graphics.FillRectangle (b, paint_here);
 				else if (e.Item.Selected && !e.Item.Pressed)
@@ -101,7 +124,7 @@ namespace System.Windows.Forms
 			if (e.Item.Selected && !e.Item.Pressed)
 				using (Pen p = new Pen (this.ColorTable.ButtonSelectedBorder))
 					e.Graphics.DrawRectangle (p, paint_here);
-			else if (e.Item.Pressed) // || (e.Item.Owner is MenuStrip && (e.Item as ToolStripMenuItem).DropDown.Visible == true))
+			else if (e.Item.Pressed || (e.Item.Owner is MenuStrip && (e.Item as ToolStripMenuItem).DropDown.Visible == true))
 				using (Pen p = new Pen (this.ColorTable.ButtonPressedBorder))
 					e.Graphics.DrawRectangle (p, paint_here);
 			else if (e.Item is ToolStripButton && (e.Item as ToolStripButton).Checked)
@@ -143,41 +166,33 @@ namespace System.Windows.Forms
 				return;
 
 			if (e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical) {
-				using (Brush light_brush = new SolidBrush (this.ColorTable.GripLight)) {
-					Rectangle r = new Rectangle (e.GripBounds.Left, e.GripBounds.Top + 5, 2, 2);
+				Rectangle r = new Rectangle (e.GripBounds.Left, e.GripBounds.Top + 5, 2, 2);
 
-					for (int i = 0; i < e.GripBounds.Height - 11; i += 4) {
-						e.Graphics.FillRectangle (light_brush, r);
-						r.Offset (0, 4);
-					}
-				}
+				for (int i = 0; i < e.GripBounds.Height - 12; i += 4) {
+					e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.GripLight), r);
+					r.Offset (0, 4);
+			}
 
-				using (Brush dark_brush = new SolidBrush (this.ColorTable.GripDark)) {
-					Rectangle r = new Rectangle (e.GripBounds.Left - 1, e.GripBounds.Top + 4, 2, 2);
+				Rectangle r2 = new Rectangle (e.GripBounds.Left - 1, e.GripBounds.Top + 4, 2, 2);
 
-					for (int i = 0; i < e.GripBounds.Height - 11; i += 4) {
-						e.Graphics.FillRectangle (dark_brush, r);
-						r.Offset (0, 4);
-					}
+				for (int i = 0; i < e.GripBounds.Height - 12; i += 4) {
+					e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.GripDark), r2);
+					r2.Offset (0, 4);
 				}
 			}
 			else {
-				using (Brush light_brush = new SolidBrush (this.ColorTable.GripLight)) {
-					Rectangle r = new Rectangle (e.GripBounds.Left + 5, e.GripBounds.Top, 2, 2);
+				Rectangle r = new Rectangle (e.GripBounds.Left + 5, e.GripBounds.Top, 2, 2);
 
-					for (int i = 0; i < e.GripBounds.Width - 11; i += 4) {
-						e.Graphics.FillRectangle (light_brush, r);
-						r.Offset (4, 0);
-					}
+				for (int i = 0; i < e.GripBounds.Width - 11; i += 4) {
+					e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.GripLight), r);
+					r.Offset (4, 0);
 				}
 
-				using (Brush dark_brush = new SolidBrush (this.ColorTable.GripDark)) {
-					Rectangle r = new Rectangle (e.GripBounds.Left + 4, e.GripBounds.Top - 1, 2, 2);
+				Rectangle r2 = new Rectangle (e.GripBounds.Left + 4, e.GripBounds.Top - 1, 2, 2);
 
-					for (int i = 0; i < e.GripBounds.Width - 11; i += 4) {
-						e.Graphics.FillRectangle (dark_brush, r);
-						r.Offset (4, 0);
-					}
+				for (int i = 0; i < e.GripBounds.Width - 11; i += 4) {
+					e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.GripDark), r2);
+					r2.Offset (4, 0);
 				}
 			}
 		}
@@ -190,6 +205,24 @@ namespace System.Windows.Forms
 		protected override void OnRenderItemCheck (ToolStripItemImageRenderEventArgs e)
 		{
 			base.OnRenderItemCheck (e);
+			
+			if (e.Item.Selected)
+			{
+				e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.CheckPressedBackground), e.ImageRectangle);
+				e.Graphics.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (this.ColorTable.ButtonPressedBorder), e.ImageRectangle);
+			}
+			else if (e.Item.Pressed)
+			{
+				e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.CheckSelectedBackground), e.ImageRectangle);
+				e.Graphics.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (this.ColorTable.ButtonSelectedBorder), e.ImageRectangle);
+			}
+			else
+			{
+				e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.CheckBackground), e.ImageRectangle);
+				e.Graphics.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (this.ColorTable.ButtonSelectedBorder), e.ImageRectangle);
+			}
+			if (e.Item.Image == null)
+				ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle (6,5,7,6), MenuGlyph.Checkmark);
 		}
 		
 		protected override void OnRenderItemImage (ToolStripItemImageRenderEventArgs e)
@@ -215,11 +248,10 @@ namespace System.Windows.Forms
 		{
 			base.OnRenderMenuItemBackground (e);
 
-			Rectangle paint_here = new Rectangle (2, 0, e.Item.Width - 4, e.Item.Height - 1);
+			Rectangle paint_here = new Rectangle (1, 0, e.Item.Width - 3, e.Item.Height - 1);
 
-			if (e.Item.Selected) {
-				using (Brush b = new SolidBrush (this.ColorTable.MenuItemSelected))
-					e.Graphics.FillRectangle (b, paint_here);
+			if (e.Item.Selected || (e.Item is ToolStripMenuItem && (e.Item as ToolStripMenuItem).DropDown.Visible)) {
+				if (e.Item.Enabled) e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.MenuItemSelected), paint_here);
 				
 				using (Pen p = new Pen (this.ColorTable.MenuItemBorder))
 					e.Graphics.DrawRectangle (p, paint_here);				
@@ -236,31 +268,24 @@ namespace System.Windows.Forms
 			base.OnRenderSeparator (e);
 
 			if (e.Vertical) {
-				using (Brush light_brush = new SolidBrush (this.ColorTable.SeparatorLight)) {
-					Rectangle r = new Rectangle (4, 6, 1, e.Item.Height - 10);
-					e.Graphics.FillRectangle (light_brush, r);
-				}
+				Rectangle r = new Rectangle (4, 6, 1, e.Item.Height - 10);
+				e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.SeparatorLight), r);
 
-				using (Brush dark_brush = new SolidBrush (this.ColorTable.SeparatorDark)) {
-					Rectangle r = new Rectangle (3, 5, 1, e.Item.Height - 10);
-					e.Graphics.FillRectangle (dark_brush, r);
-				}
+				Rectangle r2 = new Rectangle (3, 5, 1, e.Item.Height - 10);
+				e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.SeparatorDark), r2);
 			}
 			else {
-				if (!e.Item.IsOnDropDown)
-				using (Brush light_brush = new SolidBrush (this.ColorTable.SeparatorLight)) {
+				if (!e.Item.IsOnDropDown) {
 					Rectangle r = new Rectangle (6, 4, e.Item.Width - 10, 1);
-					e.Graphics.FillRectangle (light_brush, r);
+					e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.SeparatorLight), r);
 				}
 
-				using (Brush dark_brush = new SolidBrush (this.ColorTable.SeparatorDark)) {
-					Rectangle r;
-					if (e.Item.IsOnDropDown)
-						r = new Rectangle (35, 3, e.Item.Width - 36, 1);
-					else
-						r = new Rectangle (5, 3, e.Item.Width - 10, 1);
-					e.Graphics.FillRectangle (dark_brush, r);
-				}
+				Rectangle r3;
+				if (e.Item.IsOnDropDown)
+					r3 = new Rectangle (35, 3, e.Item.Width - 36, 1);
+				else
+					r3 = new Rectangle (5, 3, e.Item.Width - 10, 1);
+				e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (this.ColorTable.SeparatorDark), r3);
 			}
 		}
 
@@ -273,21 +298,21 @@ namespace System.Windows.Forms
 		{
 			base.OnRenderToolStripBackground (e);
 
-			//if (e.ToolStrip is ToolStripDropDown) {
-				//e.Graphics.Clear (this.ColorTable.ToolStripDropDownBackground);
-				//Rectangle side_gradient = new Rectangle (2, 2, 22, e.ToolStrip.Height - 4);
-				//using (LinearGradientBrush b = new LinearGradientBrush (side_gradient, this.ColorTable.ToolStripGradientBegin, this.ColorTable.ToolStripGradientEnd, LinearGradientMode.Horizontal))
-					//e.Graphics.FillRectangle (b, side_gradient);
-				//return;
-			//}
+			if (e.ToolStrip is ToolStripDropDown) {
+				e.Graphics.Clear (this.ColorTable.ToolStripDropDownBackground);
+				Rectangle side_gradient = new Rectangle (1, 2, 24, e.ToolStrip.Height - 3);
+				using (LinearGradientBrush b = new LinearGradientBrush (side_gradient, this.ColorTable.ToolStripGradientBegin, this.ColorTable.ToolStripGradientEnd, LinearGradientMode.Horizontal))
+					e.Graphics.FillRectangle (b, side_gradient);
+				return;
+			}
 			
-			//if (e.ToolStrip is MenuStrip)
-			//{
-				//using (LinearGradientBrush b = new LinearGradientBrush (e.AffectedBounds, this.ColorTable.MenuStripGradientBegin, this.ColorTable.MenuStripGradientEnd, e.ToolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Horizontal : LinearGradientMode.Vertical))
-					//e.Graphics.FillRectangle (b, e.AffectedBounds);
+			if (e.ToolStrip is MenuStrip)
+			{
+				using (LinearGradientBrush b = new LinearGradientBrush (e.AffectedBounds, this.ColorTable.MenuStripGradientBegin, this.ColorTable.MenuStripGradientEnd, e.ToolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Horizontal : LinearGradientMode.Vertical))
+					e.Graphics.FillRectangle (b, e.AffectedBounds);
 			
-			//}
-			//else
+			}
+			else
 				using (LinearGradientBrush b = new LinearGradientBrush (e.AffectedBounds, this.ColorTable.ToolStripGradientBegin, this.ColorTable.ToolStripGradientEnd, e.ToolStrip.Orientation == Orientation.Vertical ? LinearGradientMode.Horizontal : LinearGradientMode.Vertical))
 					e.Graphics.FillRectangle (b, e.AffectedBounds);
 		}
@@ -296,13 +321,13 @@ namespace System.Windows.Forms
 		{
 			base.OnRenderToolStripBorder (e);
 
-			//if (e.ToolStrip is ToolStripDropDown) {
-				//e.Graphics.DrawLines (new Pen (this.ColorTable.ToolStripBorder), new Point[] { e.AffectedBounds.Location, new Point (e.AffectedBounds.Left, e.AffectedBounds.Bottom - 1), new Point (e.AffectedBounds.Right - 1, e.AffectedBounds.Bottom - 1), new Point (e.AffectedBounds.Right - 1, e.AffectedBounds.Top), new Point (e.AffectedBounds.Left + e.ConnectedArea.Right, e.AffectedBounds.Top) });
-				//return;
-			//}
+			if (e.ToolStrip is ToolStripDropDown) {
+				e.Graphics.DrawLines (new Pen (this.ColorTable.ToolStripBorder), new Point[] { e.AffectedBounds.Location, new Point (e.AffectedBounds.Left, e.AffectedBounds.Bottom - 1), new Point (e.AffectedBounds.Right - 1, e.AffectedBounds.Bottom - 1), new Point (e.AffectedBounds.Right - 1, e.AffectedBounds.Top), new Point (e.AffectedBounds.Left + e.ConnectedArea.Right, e.AffectedBounds.Top) });
+				return;
+			}
 
-			//if (e.ToolStrip is MenuStrip)
-			//	return;
+			if (e.ToolStrip is MenuStrip)
+				return;
 				
 			using (Pen p = new Pen (this.ColorTable.ToolStripBorder)) {
 				if (this.RoundedEdges == true) {

+ 6 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripRenderEventArgs.cs

@@ -75,6 +75,12 @@ namespace System.Windows.Forms
 			get { return this.tool_strip; }
 		}
 		#endregion
+
+		#region Internal Properties
+		internal Rectangle InternalConnectedArea {
+			set { this.connected_area = value; }
+		}
+		#endregion
 	}
 }
 #endif

+ 1 - 1
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitStackLayout.cs

@@ -41,7 +41,7 @@ namespace System.Windows.Forms
 
 			if (ts.Orientation == Orientation.Horizontal) {
 				int x = ts.DisplayRectangle.Left;
-				//if (!(ts is MenuStrip))
+				if (!(ts is MenuStrip))
 					x += 2;
 				int y = ts.DisplayRectangle.Top;
 

+ 3 - 3
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripTextBox.cs

@@ -39,7 +39,7 @@ namespace System.Windows.Forms
 		public ToolStripTextBox () : base (new ToolStripTextBoxControl ())
 		{
 			base.Control.border_style = BorderStyle.None;
-			this.border_style = BorderStyle.FixedSingle;
+			this.border_style = BorderStyle.Fixed3D;
 		}
 
 		public ToolStripTextBox (Control c) : base (c)
@@ -65,7 +65,7 @@ namespace System.Windows.Forms
 			set { this.TextBox.AcceptsTab = value; }
 		}
 
-		[DefaultValue (BorderStyle.FixedSingle)]
+		[DefaultValue (BorderStyle.Fixed3D)]
 		public BorderStyle BorderStyle {
 			get { return this.border_style; }
 			set { this.border_style = value; }
@@ -160,7 +160,7 @@ namespace System.Windows.Forms
 		[Localizable (true)]
 		[Browsable (false)]
 		[EditorBrowsable (EditorBrowsableState.Never)]
-		[DefaultValue (false)]
+		[DefaultValue (true)]
 		public bool WordWrap {
 			get { return this.TextBox.WordWrap; }
 			set { this.TextBox.WordWrap = value; }