Skip to content

Commit

Permalink
Revert dotnet#11520 to fix a MenuItem issue. (dotnet#11920)
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausLoeffelmann committed Aug 20, 2024
1 parent 701b3b1 commit a9a7631
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,6 @@ protected override void OnItemClicked(ToolStripItemClickedEventArgs e)
|| !(dismissingItem.HasDropDownItems))
{ // clicking on a item w/dropdown does not dismiss window
Close(ToolStripDropDownCloseReason.ItemClicked);
SelectPreviousToolStrip();
}
}
}
Expand Down Expand Up @@ -1360,7 +1359,7 @@ internal void SelectPreviousToolStrip()
{
// snap the owner item before calling hide as non-auto created dropdowns will
// exit menu mode if there's no OwnerItem.
ToolStripItem? itemOnPreviousMenuToSelect = GetToplevelOwnerItem();
ToolStripItem? itemOnPreviousMenuToSelect = OwnerItem;
Hide();

if (itemOnPreviousMenuToSelect is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,6 @@ internal override void Toggle()
_ => ToggleState.ToggleState_Indeterminate
};

internal void OnCheckStateChanged(CheckState oldValue, CheckState newValue)
{
RaiseAutomationPropertyChangedEvent(
UIA_PROPERTY_ID.UIA_ToggleToggleStatePropertyId,
(VARIANT)(int)CheckStateToToggleState(oldValue),
(VARIANT)(int)CheckStateToToggleState(newValue));
}

private static ToggleState CheckStateToToggleState(CheckState checkState)
=> checkState switch
{
CheckState.Checked => ToggleState.ToggleState_On,
CheckState.Unchecked => ToggleState.ToggleState_Off,
_ => ToggleState.ToggleState_Indeterminate
};

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace System.Windows.Forms;
$"System.ComponentModel.Design.Serialization.CodeDomSerializer, {AssemblyRef.SystemDesign}")]
public partial class ToolStripMenuItem : ToolStripDropDownItem
{
private CheckState _prevCheckState = CheckState.Unchecked;
private static readonly MenuTimer s_menuTimer = new();

private static readonly int s_propShortcutKeys = PropertyStore.CreateKey();
Expand Down Expand Up @@ -312,7 +311,6 @@ public CheckState CheckState

if (value != CheckState)
{
_prevCheckState = CheckState;
Properties.SetInteger(s_propCheckState, (int)value);
OnCheckedChanged(EventArgs.Empty);
OnCheckStateChanged(EventArgs.Empty);
Expand Down Expand Up @@ -822,13 +820,6 @@ protected virtual void OnCheckedChanged(EventArgs e)
protected virtual void OnCheckStateChanged(EventArgs e)
{
AccessibilityNotifyClients(AccessibleEvents.StateChange);

if (IsAccessibilityObjectCreated &&
AccessibilityObject is ToolStripMenuItemAccessibleObject accessibilityObject)
{
accessibilityObject.OnCheckStateChanged(_prevCheckState, CheckState);
}

((EventHandler?)Events[s_eventCheckStateChanged])?.Invoke(this, e);
}

Expand Down Expand Up @@ -1056,14 +1047,8 @@ protected override void OnPaint(PaintEventArgs e)

protected internal override bool ProcessCmdKey(ref Message m, Keys keyData)
{
if (Enabled && !HasDropDownItems && (ShortcutKeys == keyData || keyData == Keys.Space))
if (Enabled && ShortcutKeys == keyData && !HasDropDownItems)
{
if (keyData is Keys.Space)
{
Checked = CheckOnClick ? !Checked : Checked;
return true;
}

FireEvent(ToolStripItemEventType.Click);
return true;
}
Expand Down

0 comments on commit a9a7631

Please sign in to comment.