2007-05-01 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Tue, 1 May 2007 15:06:36 +0000 (15:06 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Tue, 1 May 2007 15:06:36 +0000 (15:06 -0000)
* Application.cs: Give toolstrips a chance to process mnemonics.
* ToolStrip.cs, ToolStripDropDownButton.cs, ToolStripItem.cs,
ToolStripItemTextRenderEventArgs.cs, ToolStripLabel.cs,
ToolStripMenuItem.cs, ToolStripSplitButton.cs: Implement keyboard mnemonics.

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDownButton.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/ToolStripLabel.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitButton.cs

index 45bafbaa82a953711c08a7f82288826ba492b5fb..88abb1267bcdf16c6ab863f2c78ade0c1705d64d 100644 (file)
@@ -678,7 +678,7 @@ namespace System.Windows.Forms {
 
                                                m.HWnd = keyboard_capture.Handle;
                                                
-                                               if (!keyboard_capture.PreProcessMessage (ref m)) {
+                                               if (!keyboard_capture.PreProcessMessage (ref m) && (m.Msg == (int)Msg.WM_KEYDOWN && !keyboard_capture.ProcessControlMnemonic ((char)m.WParam))) {
                                                        if (c == null || c.Parent == null || !(c.Parent is ToolStrip))
                                                                continue;
                                                        else
index 50900b8530dbdb948f6c4db77a0229cf180c5765..e66512681c17fba4d1e824e5ebc58c84d1c6017a 100644 (file)
@@ -1,3 +1,10 @@
+2007-05-01  Jonathan Pobst  <monkey@jpobst.com>
+
+       * Application.cs: Give toolstrips a chance to process mnemonics.
+       * ToolStrip.cs, ToolStripDropDownButton.cs, ToolStripItem.cs,
+       ToolStripItemTextRenderEventArgs.cs, ToolStripLabel.cs,
+       ToolStripMenuItem.cs, ToolStripSplitButton.cs: Implement keyboard mnemonics.
+
 2007-05-01  Jackson Harper  <jackson@ximian.com>
 
        * TextBoxBase.cs: Better preferred height, FixedSingle gets the
index 7a349ee4a2706acec6f166c171309698c12de56f..17f9a6ea561a73628860d689f96c7d44d6d43320 100644 (file)
@@ -1041,6 +1041,18 @@ namespace System.Windows.Forms
 
                protected override bool ProcessMnemonic (char charCode)
                {
+                       // If any item has an explicit mnemonic, it gets the message
+                       foreach (ToolStripItem tsi in this.Items)
+                               if (tsi.Enabled && tsi.Visible && Control.IsMnemonic (charCode, tsi.Text))
+                                       return tsi.ProcessMnemonic (charCode);
+
+                       string code = Char.ToUpper (charCode).ToString ();
+                       
+                       // If any item's text starts with our letter, it gets the message
+                       foreach (ToolStripItem tsi in this.Items)
+                               if (tsi.Enabled && tsi.Visible && tsi.Text.Length > 0 && tsi.Text.ToUpper ().StartsWith (code))
+                                       return tsi.ProcessMnemonic (charCode);
+
                        return base.ProcessMnemonic (charCode);
                }
                
@@ -1194,6 +1206,9 @@ namespace System.Windows.Forms
                                                Application.KeyboardCapture = this;
                                        else if (Application.KeyboardCapture == this)
                                                Application.KeyboardCapture = null;
+                                       
+                                       // Redraw for mnemonic underlines
+                                       this.Refresh ();
                                }
                        }
                }
@@ -1384,7 +1399,10 @@ namespace System.Windows.Forms
                        ToolStripItem next_item = this.GetNextItem (start, forward ? ArrowDirection.Right : ArrowDirection.Left);
                        
                        this.ChangeSelection (next_item);
-                       
+
+                       if (next_item is ToolStripControlHost)
+                               (next_item as ToolStripControlHost).Focus ();
+               
                        return next_item;
                }
 
index af0ecf48f825cc6029a091b3865385954be7f013..377933e80cc24924f50137481844eb5f99429eaf 100644 (file)
@@ -135,6 +135,19 @@ namespace System.Windows.Forms
                                return;
                        }
                }
+
+               protected internal override bool ProcessMnemonic (char charCode)
+               {
+                       if (!this.Selected)
+                               this.Parent.ChangeSelection (this);
+
+                       if (this.HasDropDownItems)
+                               this.ShowDropDown ();
+                       else
+                               this.PerformClick ();
+
+                       return true;
+               }
                #endregion
        }
 }
index 2e1bfe8b842fc3c9c531e5ca5e0948669c856ac6..6c5c7de76fed2355e384c322d32df95cd5099e9d 100644 (file)
@@ -1119,9 +1119,12 @@ namespace System.Windows.Forms
                        return false;
                }
                
+               // ProcessMnemonic will only be called if we are supposed to handle
+               // it.  None of that fancy "thinking" needed!
                protected internal virtual bool ProcessMnemonic (char charCode)
                {
-                       return false;
+                       this.PerformClick ();
+                       return true;
                }
                
                protected internal virtual void SetBounds (Rectangle bounds)
index 8308c426e52c175f98f764d61aa263cc7e2a53a2..e2e4c77676419c6a37cab9dc55f10e724d4a161f 100644 (file)
@@ -81,7 +81,8 @@ namespace System.Windows.Forms
                                        break;
                        }
 
-                       this.text_format |= TextFormatFlags.HidePrefix;
+                       if (Application.KeyboardCapture == null)
+                               this.text_format |= TextFormatFlags.HidePrefix;
                }
 
                public ToolStripItemTextRenderEventArgs (Graphics g, ToolStripItem item, string text, Rectangle textRectangle, Color textColor, Font textFont, TextFormatFlags format)
index 44b509a7737d020dc4af346a420e7f38e26b0c5d..eb31a200d6126f970d35b61b0704167515059ac5 100644 (file)
@@ -248,6 +248,12 @@ namespace System.Windows.Forms
                                                this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
                        }
                }
+
+               protected internal override bool ProcessMnemonic (char charCode)
+               {
+                       this.Parent.SelectNextToolStripItem (this, true);
+                       return true;
+               }
                #endregion
        }
 }
index 56738ec8820d02cdaa75b1b35cb768cba443c61f..b61e460609ce9c69af5a43bf4750d68e51111788 100644 (file)
@@ -358,6 +358,20 @@ namespace System.Windows.Forms
                                
                        return base.ProcessCmdKey (ref m, keyData);
                }
+
+               protected internal override bool ProcessMnemonic (char charCode)
+               {
+                       if (!this.Selected)
+                               this.Parent.ChangeSelection (this);
+                               
+                       if (this.HasDropDownItems) {
+                               this.ShowDropDown ();
+                               this.DropDown.SelectNextToolStripItem (null, true);
+                       } else
+                               this.PerformClick ();
+                       
+                       return true;
+               }
                
                protected internal override void SetBounds (Rectangle bounds)
                {
index a3f7674fe20b75cc0e70d1f60387409832e5c939..69fa87575b39a1a36c0e85e0bc01cbc03b5aad69 100644 (file)
@@ -288,6 +288,19 @@ namespace System.Windows.Forms
 
                        return base.ProcessDialogKey (keyData);
                }
+
+               protected internal override bool ProcessMnemonic (char charCode)
+               {
+                       if (!this.Selected)
+                               this.Parent.ChangeSelection (this);
+
+                       if (this.HasDropDownItems)
+                               this.ShowDropDown ();
+                       else
+                               this.PerformClick ();
+
+                       return true;
+               }
                #endregion
                
                #region Public Events