forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb30eea
commit 325ee6d
Showing
1 changed file
with
169 additions
and
95 deletions.
There are no files selected for viewing
264 changes: 169 additions & 95 deletions
264
src/Uno.UI/UI/Xaml/Automation/Peers/ComboBoxAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,205 @@ | ||
using Uno; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// MUX reference ComboBoxAutomationPeer_Partial.cpp, tag winui3/release/1.4.2 | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.UI.Xaml.Automation.Peers | ||
namespace Microsoft.UI.Xaml.Automation.Peers; | ||
|
||
/// <summary> | ||
/// Exposes ComboBox types to Microsoft UI Automation. | ||
/// </summary> | ||
public partial class ComboBoxAutomationPeer : SelectorAutomationPeer, Provider.IExpandCollapseProvider, Provider.IValueProvider, Provider.IWindowProvider | ||
{ | ||
public partial class ComboBoxAutomationPeer : SelectorAutomationPeer, Provider.IExpandCollapseProvider, Provider.IValueProvider, Provider.IWindowProvider | ||
public ComboBoxAutomationPeer(ComboBox owner) : base(owner) | ||
{ | ||
[NotImplemented] | ||
public ExpandCollapseState ExpandCollapseState | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member ExpandCollapseState ComboBoxAutomationPeer.ExpandCollapseState is not implemented in Uno."); | ||
} | ||
} | ||
|
||
[NotImplemented] | ||
public bool IsReadOnly | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member bool ComboBoxAutomationPeer.IsReadOnly is not implemented in Uno."); | ||
} | ||
} | ||
} | ||
|
||
[NotImplemented] | ||
public string Value | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member string ComboBoxAutomationPeer.Value is not implemented in Uno."); | ||
} | ||
} | ||
public ExpandCollapseState ExpandCollapseState | ||
=> (Owner as ComboBox).IsDropDownOpen ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed; | ||
|
||
[NotImplemented] | ||
public global::Microsoft.UI.Xaml.Automation.WindowInteractionState InteractionState | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member WindowInteractionState ComboBoxAutomationPeer.InteractionState is not implemented in Uno."); | ||
} | ||
} | ||
public bool IsReadOnly => (Owner as ComboBox).IsEnabled || (Owner as ComboBox).IsEditable; | ||
|
||
public string Value => (Owner as ComboBox).SelectionBoxItem?.ToString(); | ||
|
||
public WindowInteractionState InteractionState => WindowInteractionState.Running; | ||
|
||
public bool IsModal => true; | ||
|
||
[NotImplemented] | ||
public bool IsModal | ||
public bool IsTopmost => true; | ||
|
||
public bool Maximizable => false; | ||
|
||
public bool Minimizable => false; | ||
|
||
public WindowVisualState VisualState => WindowVisualState.Normal; | ||
|
||
public void Collapse() | ||
{ | ||
if (!IsEnabled()) | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member bool ComboBoxAutomationPeer.IsModal is not implemented in Uno."); | ||
} | ||
// UIA_E_ELEMENTNOTENABLED | ||
throw new ElementNotEnabledException(); | ||
} | ||
|
||
[NotImplemented] | ||
public bool IsTopmost | ||
var pOwner = Owner as ComboBox; | ||
pOwner.IsDropDownOpen = false; | ||
} | ||
|
||
public void Expand() | ||
{ | ||
if (!IsEnabled()) | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member bool ComboBoxAutomationPeer.IsTopmost is not implemented in Uno."); | ||
} | ||
// UIA_E_ELEMENTNOTENABLED; | ||
throw new ElementNotEnabledException(); | ||
} | ||
|
||
[NotImplemented] | ||
public bool Maximizable | ||
var pOwner = Owner as ComboBox; | ||
pOwner.IsDropDownOpen = true; | ||
} | ||
|
||
public void SetValue(string value) | ||
{ | ||
// UIA_E_INVALIDOPERATION | ||
throw new System.InvalidOperationException(); | ||
} | ||
|
||
public void Close() | ||
{ | ||
|
||
} | ||
|
||
public void SetVisualState(WindowVisualState state) | ||
{ | ||
|
||
} | ||
public bool WaitForInputIdle(int milliseconds) => false; | ||
|
||
protected override string GetClassNameCore() => nameof(ComboBox); | ||
|
||
protected override string GetNameCore() | ||
{ | ||
var returnValue = base.GetNameCore(); | ||
|
||
// If the Name property wasn't explicitly set on this AP, then we will | ||
// return the combo header. | ||
if (string.IsNullOrEmpty(returnValue)) | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member bool ComboBoxAutomationPeer.Maximizable is not implemented in Uno."); | ||
} | ||
return (Owner as ComboBox).Header.ToString(); | ||
} | ||
|
||
[NotImplemented] | ||
public bool Minimizable | ||
return returnValue; | ||
} | ||
|
||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
=> AutomationControlType.ComboBox; | ||
|
||
protected override IList<AutomationPeer> GetChildrenCore() | ||
{ | ||
UIElement spOwner = Owner as UIElement; | ||
ComboBox spComboBox = spOwner as ComboBox; | ||
|
||
if (spComboBox == null || !spComboBox.IsDropDownOpen) | ||
{ | ||
get | ||
{ | ||
throw new global::System.NotImplementedException("The member bool ComboBoxAutomationPeer.Minimizable is not implemented in Uno."); | ||
} | ||
return base.GetChildrenCore(); | ||
} | ||
|
||
[NotImplemented] | ||
public global::Microsoft.UI.Xaml.Automation.WindowVisualState VisualState | ||
IList<AutomationPeer> apChildren = new DirectUI.TrackerCollection<AutomationPeer>(); | ||
|
||
//UNO TODO: Implement GetLightDismissElement on ComboBox | ||
|
||
//var spLightDismissElement; | ||
//spComboBox.GetLightDismissElement(out spLightDismissElement); | ||
|
||
//if (spLightDismissElement != null) | ||
//{ | ||
// var ap = spLightDismissElement.GetOrCreateAutomationPeer(); | ||
// apChildren.Add(ap); | ||
//} | ||
|
||
//UNO TODO: Implement GetEditableTextPart and IsEditable on ComboBox | ||
|
||
//bool isEditable = spComboBox.IsEditable; | ||
//UIElement spEditableTextElement; | ||
|
||
//if (isEditable && spComboBox.GetEditableTextPart(out spEditableTextElement)) | ||
//{ | ||
// IAutomationPeer ap = spEditableTextElement.GetOrCreateAutomationPeer(); | ||
// apChildren.Insert(0, ap); | ||
//} | ||
|
||
return apChildren; | ||
} | ||
|
||
protected override string GetHelpTextCore() | ||
{ | ||
var returnValue = base.GetHelpTextCore(); | ||
|
||
// If the HelpText property wasn't explicitly set on this AP and no item is selected, | ||
// then we'll return the placeholder text. | ||
if (string.IsNullOrEmpty(returnValue)) | ||
{ | ||
get | ||
var selectedIndex = (Owner as ComboBox).SelectedIndex; | ||
if (selectedIndex < 0) | ||
{ | ||
throw new global::System.NotImplementedException("The member WindowVisualState ComboBoxAutomationPeer.VisualState is not implemented in Uno."); | ||
return (Owner as ComboBox).PlaceholderText; | ||
} | ||
} | ||
|
||
[NotImplemented] | ||
public ComboBoxAutomationPeer(global::Microsoft.UI.Xaml.Controls.ComboBox owner) : base(owner) | ||
{ | ||
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Microsoft.UI.Xaml.Automation.Peers.ComboBoxAutomationPeer", "ComboBoxAutomationPeer.ComboBoxAutomationPeer(ComboBox owner)"); | ||
} | ||
return returnValue; | ||
} | ||
|
||
[NotImplemented] | ||
public void Collapse() | ||
{ | ||
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Microsoft.UI.Xaml.Automation.Peers.ComboBoxAutomationPeer", "void ComboBoxAutomationPeer.Collapse()"); | ||
} | ||
protected override object GetPatternCore(PatternInterface patternInterface) | ||
{ | ||
var pOwner = Owner as ComboBox; | ||
|
||
switch (patternInterface) | ||
{ | ||
case PatternInterface.Value: | ||
if (pOwner.IsEditable) | ||
{ | ||
return this; | ||
} | ||
break; | ||
|
||
case PatternInterface.ExpandCollapse: | ||
return this; | ||
|
||
case PatternInterface.Window: | ||
if (pOwner.IsDropDownOpen) | ||
{ | ||
return this; | ||
} | ||
break; | ||
default: | ||
return base.GetPatternCore(patternInterface); | ||
} | ||
return null; | ||
} | ||
|
||
[NotImplemented] | ||
public void Expand() | ||
{ | ||
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Microsoft.UI.Xaml.Automation.Peers.ComboBoxAutomationPeer", "void ComboBoxAutomationPeer.Expand()"); | ||
} | ||
public new bool IsSelectionRequired => true; | ||
|
||
[NotImplemented] | ||
public void SetValue(string value) | ||
{ | ||
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Microsoft.UI.Xaml.Automation.Peers.ComboBoxAutomationPeer", "void ComboBoxAutomationPeer.SetValue(string value)"); | ||
} | ||
// Raise events for ExpandCollapseState changes to UIAutomation Clients. | ||
public void RaiseExpandCollapseAutomationEvent(bool isOpen) | ||
{ | ||
ExpandCollapseState oldValue; | ||
ExpandCollapseState newValue; | ||
|
||
[NotImplemented] | ||
public void Close() | ||
// Converting isOpen to appropriate enumerations | ||
if (isOpen) | ||
{ | ||
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Microsoft.UI.Xaml.Automation.Peers.ComboBoxAutomationPeer", "void ComboBoxAutomationPeer.Close()"); | ||
oldValue = ExpandCollapseState.Collapsed; | ||
newValue = ExpandCollapseState.Expanded; | ||
} | ||
|
||
[NotImplemented] | ||
public void SetVisualState(global::Microsoft.UI.Xaml.Automation.WindowVisualState state) | ||
else | ||
{ | ||
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Microsoft.UI.Xaml.Automation.Peers.ComboBoxAutomationPeer", "void ComboBoxAutomationPeer.SetVisualState(WindowVisualState state)"); | ||
oldValue = ExpandCollapseState.Expanded; | ||
newValue = ExpandCollapseState.Collapsed; | ||
} | ||
|
||
[NotImplemented] | ||
public bool WaitForInputIdle(int milliseconds) | ||
{ | ||
throw new global::System.NotImplementedException("The member bool ComboBoxAutomationPeer.WaitForInputIdle(int milliseconds) is not implemented in Uno."); | ||
} | ||
RaisePropertyChangedEvent(ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue, newValue); | ||
} | ||
} |