Skip to content

Commit

Permalink
feat: Implement ToggleMenuFlyoutItemAutomationPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
morning4coffe-dev authored and MartinZikmund committed Jun 17, 2024
1 parent 3f72be5 commit b515ef6
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Microsoft.UI.Xaml.Automation.Peers
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class ToggleMenuFlyoutItemAutomationPeer : global::Microsoft.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer, global::Microsoft.UI.Xaml.Automation.Provider.IToggleProvider
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Microsoft.UI.Xaml.Automation.ToggleState ToggleState
{
Expand All @@ -18,7 +18,7 @@ public partial class ToggleMenuFlyoutItemAutomationPeer : global::Microsoft.UI.X
}
}
#endif
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public ToggleMenuFlyoutItemAutomationPeer(global::Microsoft.UI.Xaml.Controls.ToggleMenuFlyoutItem owner) : base(owner)
{
Expand All @@ -27,7 +27,7 @@ public ToggleMenuFlyoutItemAutomationPeer(global::Microsoft.UI.Xaml.Controls.Tog
#endif
// Forced skipping of method Microsoft.UI.Xaml.Automation.Peers.ToggleMenuFlyoutItemAutomationPeer.ToggleMenuFlyoutItemAutomationPeer(Microsoft.UI.Xaml.Controls.ToggleMenuFlyoutItem)
// Forced skipping of method Microsoft.UI.Xaml.Automation.Peers.ToggleMenuFlyoutItemAutomationPeer.ToggleState.get
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public void Toggle()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX Reference ToggleMenuFlyoutItemAutomationPeer_Partial.cpp, tag winui3/release/1.4.2
namespace Microsoft.UI.Xaml.Automation.Peers;

public partial class ToggleMenuFlyoutItemAutomationPeer : FrameworkElementAutomationPeer, Provider.IToggleProvider
{
public ToggleMenuFlyoutItemAutomationPeer(Controls.ToggleMenuFlyoutItem owner) : base(owner)
{

}

protected override object GetPatternCore(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Toggle)
{
return this;
}
else
{
return base.GetPatternCore(patternInterface);
}
}

protected override string GetClassNameCore() => nameof(Controls.ToggleMenuFlyoutItem);

protected override AutomationControlType GetAutomationControlTypeCore()
=> AutomationControlType.MenuItem;

protected override string GetAcceleratorKeyCore()
{
var acceleratorKey = base.GetAcceleratorKeyCore();

if (string.IsNullOrEmpty(acceleratorKey))
{
return (Owner as Controls.ToggleMenuFlyoutItem).KeyboardAcceleratorTextOverride;
}

return acceleratorKey;
}

protected override int GetPositionInSetCore()
{
var returnValue = base.GetPositionInSetCore();

if (returnValue == -1)
{
returnValue = GetPositionInSet();
}

return returnValue;
}

protected override int GetSizeOfSetCore()
{
var returnValue = base.GetSizeOfSetCore();

if (returnValue == -1)
{
returnValue = GetPositionInSet();
}

return returnValue;
}

public void Toggle()
{
if (!IsEnabled())
{
throw new ElementNotEnabledException();
}

(Owner as Controls.ToggleMenuFlyoutItem).Invoke();
}

public ToggleState ToggleState
{
get
{
var isChecked = (Owner as Controls.ToggleMenuFlyoutItem).IsChecked;

if (isChecked)
{
return ToggleState.On;
}
else
{
return ToggleState.Off;
}
}
}

internal void RaisePropertyChangedEvent(object oldValue, object newValue)
{
var oldToggleState = ConvertToToggleState(oldValue);
var newToggleState = ConvertToToggleState(newValue);

if (oldToggleState != newToggleState)
{
//base.RaisePropertyChangedEvent(AutomationProperties.ToggleStateProperty, oldToggleState, newToggleState);
}
}

// Convert the Boolean in Inspectable to the ToggleState Enum, if the Inspectable is NULL that corresponds to Indeterminate state.
private ToggleState ConvertToToggleState(object value)
{
if (value is bool v)
{
return v ? ToggleState.On : ToggleState.Off;
}
return ToggleState.Indeterminate;
}
}

0 comments on commit b515ef6

Please sign in to comment.