2007-08-08 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Wed, 8 Aug 2007 21:45:28 +0000 (21:45 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Wed, 8 Aug 2007 21:45:28 +0000 (21:45 -0000)
* ToolStrip.cs: Record if we were activated by mouse or keyboard.  Redraw
when we are dismissed to clear keyboard mnemonics.
* MenuStrip.cs, ToolStripDropDown.cs, ToolStripItem.cs,
ToolStripMenuItem.cs: Record if we were activated by mouse or keyboard.
* ToolStripItemTextRenderEventArgs.cs: Draw mnemonic underlines if menu
was activated by keyboard or the OS tells us to always draw them.
* ToolStripManager.cs: Setup storage for activated by mouse or keyboard.
[Fixes bugs #82376, #82377]

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItemTextRenderEventArgs.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripManager.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs

index 57e63b622d4fd926a10878e3d4ff2fcd160ad0ac..f7e4dfa92beee090891836e0838da9e3773d70fe 100644 (file)
@@ -1,3 +1,14 @@
+2007-08-08  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolStrip.cs: Record if we were activated by mouse or keyboard.  Redraw
+       when we are dismissed to clear keyboard mnemonics.
+       * MenuStrip.cs, ToolStripDropDown.cs, ToolStripItem.cs, 
+       ToolStripMenuItem.cs: Record if we were activated by mouse or keyboard.
+       * ToolStripItemTextRenderEventArgs.cs: Draw mnemonic underlines if menu
+       was activated by keyboard or the OS tells us to always draw them.
+       * ToolStripManager.cs: Setup storage for activated by mouse or keyboard.
+       [Fixes bugs #82376, #82377]
+
 2007-08-08  Jonathan Pobst  <monkey@jpobst.com>
 
        * Control.cs: If no one accepts a mnemonic, let the MenuStrip have a 
index 68a3c9fc2dfe484a771fa92824b75ad0f56b1705..d068e0f4801cb84159786cf1faba1661a7d32195 100644 (file)
@@ -197,7 +197,7 @@ namespace System.Windows.Forms
                internal override bool OnMenuKey ()
                {
                        // Set ourselves active and select our first item
-                       ToolStripManager.SetActiveToolStrip (this);
+                       ToolStripManager.SetActiveToolStrip (this, true);
                        ToolStripItem tsi = this.SelectNextToolStripItem (null, true);
                        
                        if (tsi is MdiControlStrip.SystemMenuItem)
index 91792b94c5268ca09cf97f34a0eb496ac761b241..1277b557c6db146e243c198ca04a23b37c45869f 100644 (file)
@@ -796,7 +796,7 @@ namespace System.Windows.Forms
                protected virtual void OnItemClicked (ToolStripItemClickedEventArgs e)
                {
                        if (this.KeyboardActive)
-                               ToolStripManager.SetActiveToolStrip (null);
+                               ToolStripManager.SetActiveToolStrip (null, false);
                        
                        ToolStripItemClickedEventHandler eh = (ToolStripItemClickedEventHandler)(Events [ItemClickedEvent]);
                        if (eh != null)
@@ -1075,7 +1075,7 @@ namespace System.Windows.Forms
                                                foreach (ToolStripItem tsi in this.Items)
                                                        tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
 
-                                               ToolStripManager.SetActiveToolStrip (ts);
+                                               ToolStripManager.SetActiveToolStrip (ts, true);
                                                ts.SelectNextToolStripItem (null, true);
                                        }
                                        
@@ -1087,7 +1087,7 @@ namespace System.Windows.Forms
                                                foreach (ToolStripItem tsi in this.Items)
                                                        tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
 
-                                               ToolStripManager.SetActiveToolStrip (ts);
+                                               ToolStripManager.SetActiveToolStrip (ts, true);
                                                ts.SelectNextToolStripItem (null, true);
                                        }
                                        
@@ -1298,8 +1298,10 @@ namespace System.Windows.Forms
                                        
                                        if (value)
                                                Application.KeyboardCapture = this;
-                                       else if (Application.KeyboardCapture == this)
+                                       else if (Application.KeyboardCapture == this) {
                                                Application.KeyboardCapture = null;
+                                               ToolStripManager.ActivatedByKeyboard = false;
+                                       }
                                        
                                        // Redraw for mnemonic underlines
                                        this.Invalidate ();
@@ -1317,7 +1319,7 @@ namespace System.Windows.Forms
                internal void ChangeSelection (ToolStripItem nextItem)
                {
                        if (Application.KeyboardCapture != this)
-                               ToolStripManager.SetActiveToolStrip (this);
+                               ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard);
                                
                        foreach (ToolStripItem tsi in this.Items)
                                if (tsi != nextItem)
@@ -1345,6 +1347,9 @@ namespace System.Windows.Forms
                        // Make sure all of our items are deselected and repainted
                        foreach (ToolStripItem tsi in this.Items)
                                tsi.Dismiss (reason);
+                               
+                       // We probably need to redraw for mnemonic underlines
+                       this.Invalidate ();
                }
                
                private void DoAutoSize ()
index 5361b3b93e535eab6fd67a0ba4d6a05249186a1e..5dfea707e9f9d9258c4ac13957e3fd9503a4a630 100644 (file)
@@ -499,7 +499,7 @@ namespace System.Windows.Forms
 
                        base.Show ();
 
-                       ToolStripManager.SetActiveToolStrip (this);
+                       ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard);
 
                        this.OnOpened (EventArgs.Empty);
                }
@@ -935,7 +935,7 @@ namespace System.Windows.Forms
                                        this.Dismiss (ToolStripDropDownCloseReason.Keyboard);
                                        
                                        ToolStrip parent_strip = this.OwnerItem.Parent;
-                                       ToolStripManager.SetActiveToolStrip (parent_strip);
+                                       ToolStripManager.SetActiveToolStrip (parent_strip, true);
                                        
                                        if (parent_strip is MenuStrip && keyData == Keys.Left) {
                                                parent_strip.SelectNextToolStripItem (this.TopLevelOwnerItem, false);
index 6fe61e0f46ab149a04dbcdefc07ed6eb4236b45c..fd983f4d70335fd9a73622193c6d43c27f1f9c29 100644 (file)
@@ -414,7 +414,7 @@ namespace System.Windows.Forms
                public int Height {
                        get { return this.Size.Height; }
                        set { 
-                               this.bounds.Height = value
+                               this.Size = new Size (this.Size.Width, value)
                                this.explicit_size.Height = value;
                                
                                if (this.Visible) {
@@ -772,7 +772,7 @@ namespace System.Windows.Forms
                public int Width {
                        get { return this.Size.Width; }
                        set { 
-                               this.bounds.Width = value
+                               this.Size = new Size (value, this.Size.Height)
                                this.explicit_size.Width = value;
                                
                                if (this.Visible) {
@@ -1200,6 +1200,7 @@ namespace System.Windows.Forms
                // it.  None of that fancy "thinking" needed!
                protected internal virtual bool ProcessMnemonic (char charCode)
                {
+                       ToolStripManager.SetActiveToolStrip (this.Parent, true);
                        this.PerformClick ();
                        return true;
                }
index c2b166d43792a7ac6b44d8b07a2719805c7a8d72..185f95f348be925b6b49c59baf3fdd5567d1cf06 100644 (file)
@@ -81,7 +81,7 @@ namespace System.Windows.Forms
                                        break;
                        }
 
-                       if (Application.KeyboardCapture == null)
+                       if ((Application.KeyboardCapture == null || !ToolStripManager.ActivatedByKeyboard) && !SystemInformation.MenuAccessKeysUnderlined)
                                this.text_format |= TextFormatFlags.HidePrefix;
                }
 
index f08b3f444ac06b3fb73598b51ce5a927515870b8..9fd0776a4078f8c81652aca43de6b83723bed0fa 100644 (file)
@@ -41,6 +41,7 @@ namespace System.Windows.Forms
                private static bool visual_styles_enabled = Application.RenderWithVisualStyles;
                private static List<ToolStrip> toolstrips = new List<ToolStrip> ();
                private static List<ToolStripMenuItem> menu_items = new List<ToolStripMenuItem> ();
+               private static bool activated_by_keyboard;
                
                #region Private Constructor
                private ToolStripManager ()
@@ -421,6 +422,11 @@ namespace System.Windows.Forms
                #endregion
 
                #region Private/Internal Methods
+               internal static bool ActivatedByKeyboard {
+                       get { return activated_by_keyboard; }
+                       set { activated_by_keyboard = value; }
+               }
+               
                internal static void AddToolStrip (ToolStrip ts)
                {
                        lock (toolstrips)
@@ -494,13 +500,17 @@ namespace System.Windows.Forms
                        return false;
                }
                
-               internal static void SetActiveToolStrip (ToolStrip toolStrip)
+               internal static void SetActiveToolStrip (ToolStrip toolStrip, bool keyboard)
                {
                        if (Application.KeyboardCapture != null)
                                Application.KeyboardCapture.KeyboardActive = false;
                                
-                       if (toolStrip == null)
+                       if (toolStrip == null) {
+                               activated_by_keyboard = false;
                                return;
+                       }
+                       
+                       activated_by_keyboard = keyboard;
                                
                        toolStrip.KeyboardActive = true;
                }
index 4d3ce1644ee09d458bc86cf5723b6eeab25fd0c6..25f9eabd213255f60c9bd7c82299bd78217094b3 100644 (file)
@@ -395,6 +395,7 @@ namespace System.Windows.Forms
                                this.Parent.ChangeSelection (this);
                                
                        if (this.HasDropDownItems) {
+                               ToolStripManager.SetActiveToolStrip (this.Parent, true);
                                this.ShowDropDown ();
                                this.DropDown.SelectNextToolStripItem (null, true);
                        } else