+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
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)
protected virtual void OnItemClicked (ToolStripItemClickedEventArgs e)
{
if (this.KeyboardActive)
- ToolStripManager.SetActiveToolStrip (null);
+ ToolStripManager.SetActiveToolStrip (null, false);
ToolStripItemClickedEventHandler eh = (ToolStripItemClickedEventHandler)(Events [ItemClickedEvent]);
if (eh != null)
foreach (ToolStripItem tsi in this.Items)
tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
- ToolStripManager.SetActiveToolStrip (ts);
+ ToolStripManager.SetActiveToolStrip (ts, true);
ts.SelectNextToolStripItem (null, true);
}
foreach (ToolStripItem tsi in this.Items)
tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard);
- ToolStripManager.SetActiveToolStrip (ts);
+ ToolStripManager.SetActiveToolStrip (ts, true);
ts.SelectNextToolStripItem (null, true);
}
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 ();
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)
// 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 ()
base.Show ();
- ToolStripManager.SetActiveToolStrip (this);
+ ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard);
this.OnOpened (EventArgs.Empty);
}
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);
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) {
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) {
// it. None of that fancy "thinking" needed!
protected internal virtual bool ProcessMnemonic (char charCode)
{
+ ToolStripManager.SetActiveToolStrip (this.Parent, true);
this.PerformClick ();
return true;
}
break;
}
- if (Application.KeyboardCapture == null)
+ if ((Application.KeyboardCapture == null || !ToolStripManager.ActivatedByKeyboard) && !SystemInformation.MenuAccessKeysUnderlined)
this.text_format |= TextFormatFlags.HidePrefix;
}
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 ()
#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)
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;
}
this.Parent.ChangeSelection (this);
if (this.HasDropDownItems) {
+ ToolStripManager.SetActiveToolStrip (this.Parent, true);
this.ShowDropDown ();
this.DropDown.SelectNextToolStripItem (null, true);
} else