2007-08-20 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Mon, 20 Aug 2007 14:17:39 +0000 (14:17 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Mon, 20 Aug 2007 14:17:39 +0000 (14:17 -0000)
* ToolStrip.cs: Add some logic to un-focus controls in ToolStripControlHosts
when other buttons are clicked or navigated to.

svn path=/trunk/mcs/; revision=84467

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs

index 492f10ddc432e159d5d5208866f27e3061188982..2a7453db51129c227a8ba800b9774df02cdd2516 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-20  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolStrip.cs: Add some logic to un-focus controls in ToolStripControlHosts
+       when other buttons are clicked or navigated to.
+
 2007-08-20  Rolf Bjarne Kvinge <RKvinge@novell.com> 
 
        * XplatUIX11.cs: Treat toolwindows as if they had no window manager, since
index fce31b57827c519f9639732dcaa6bcd02a6b0ff9..f1878f4b4ddfcd291a07989baf38d3164260ca22 100644 (file)
@@ -853,6 +853,11 @@ namespace System.Windows.Forms
                {
                        if (mouse_currently_over != null)
                        {
+                               ToolStripItem focused = GetCurrentlyFocusedItem ();
+
+                               if (focused != null && focused != mouse_currently_over)
+                                       this.FocusInternal (true);
+
                                if (this is MenuStrip && !(mouse_currently_over as ToolStripMenuItem).HasDropDownItems) {
                                        if (!menu_selected)
                                                (this as MenuStrip).FireMenuActivate ();
@@ -1324,7 +1329,15 @@ namespace System.Windows.Forms
                        foreach (ToolStripItem tsi in this.Items)
                                if (tsi != nextItem)
                                        tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
-                                       
+
+                       ToolStripItem current = GetCurrentlySelectedItem ();
+                       
+                       if (!(current is ToolStripControlHost))
+                               this.FocusInternal (true);
+
+                       if (nextItem is ToolStripControlHost)
+                               (nextItem as ToolStripControlHost).Focus ();
+
                        nextItem.Select ();
                        
                        if (nextItem.Parent is MenuStrip && (nextItem.Parent as MenuStrip).MenuDroppedDown)
@@ -1372,6 +1385,15 @@ namespace System.Windows.Forms
                        return null;
                }
                
+               internal ToolStripItem GetCurrentlyFocusedItem ()
+               {
+                       foreach (ToolStripItem tsi in this.DisplayedItems)
+                               if ((tsi is ToolStripControlHost) && (tsi as ToolStripControlHost).Control.Focused)
+                                       return tsi;
+
+                       return null;
+               }
+               
                internal virtual Size GetToolStripPreferredSize (Size proposedSize)
                {
                        Size new_size = new Size (0, this.Height);