Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3934,7 +3934,7 @@ internal override void ReleaseUiaProvider(HWND handle)
/// <param name="items">contains ToolStrip or ToolStripDropDown items to disconnect</param>
internal virtual void ReleaseToolStripItemsProviders(ToolStripItemCollection items)
{
ToolStripItem[] itemsArray = [..items.Cast<ToolStripItem>()];
ToolStripItem[] itemsArray = [.. items.Cast<ToolStripItem>()];
foreach (ToolStripItem toolStripItem in itemsArray)
{
if (toolStripItem is ToolStripDropDownItem dropDownItem && dropDownItem.DropDownItems.Count > 0)
Expand Down Expand Up @@ -4579,31 +4579,46 @@ protected override void WndProc(ref Message m)
{
SnapFocus((HWND)(nint)m.WParamInternal);

if (IsDropDown)
{
// Designer SmartTag panels are hosted in ToolStripDropDown. Keep these
// participating in modal menu tracking regardless of previous focus.
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
}

// Only activate ModalMenuFilter when focus transfers
// between ToolStrips (to fix #12916).
// Do NOT activate on generic Tab focus (#14489).
HWND previousFocus = (HWND)(nint)m.WParamInternal;
Control? previousControl = FromChildHandle(previousFocus);
if (previousControl is ToolStrip || previousControl?.Parent is ToolStrip)
else
{
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
HWND previousFocus = (HWND)(nint)m.WParamInternal;
Control? previousControl = FromChildHandle(previousFocus);
if (previousControl is ToolStrip || previousControl?.Parent is ToolStrip)
{
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
}
}
}

if (m.MsgInternal == PInvokeCore.WM_KILLFOCUS)
{
// Clear modal menu tracking when focus leaves ToolStrip context so
// keyboard input is not incorrectly routed after tabbing away.
HWND nextFocus = (HWND)(nint)m.WParamInternal;
Control? nextControl = FromChildHandle(nextFocus);
if (ToolStripManager.ModalMenuFilter.GetActiveToolStrip() == this
&& nextControl is not ToolStrip
&& nextControl?.Parent is not ToolStrip)
{
ToolStripManager.ModalMenuFilter.RemoveActiveToolStrip(this);
if (ToolStripManager.ModalMenuFilter.GetActiveToolStrip() is null)
// Keep ToolStripDropDowns in menu tracking while they remain visible (for
// example, designer SmartTag panels that may temporarily transfer focus).
if (!IsDropDown)
{
HWND nextFocus = (HWND)(nint)m.WParamInternal;
Control? nextControl = FromChildHandle(nextFocus);
if (ToolStripManager.ModalMenuFilter.GetActiveToolStrip() == this
&& nextControl is not ToolStrip
&& nextControl?.Parent is not ToolStrip)
{
ToolStripManager.ModalMenuFilter.ExitMenuMode();
ToolStripManager.ModalMenuFilter.RemoveActiveToolStrip(this);
if (ToolStripManager.ModalMenuFilter.GetActiveToolStrip() is null)
{
ToolStripManager.ModalMenuFilter.ExitMenuMode();
}
}
}
}
Expand Down
Loading