Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,40 @@
using Avalonia;
using Avalonia.Automation;
using Avalonia.Automation.Provider;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;

namespace Avalonia.Automation.Peers;

public class ColorSpectrumAutomationPeer : ControlAutomationPeer, IValueProvider
{
public ColorSpectrumAutomationPeer(ColorSpectrum owner)
: base(owner)
{
owner.ColorChanged += OwnerOnColorChanged;
}

public bool IsReadOnly => false;
public new ColorSpectrum Owner => (ColorSpectrum)base.Owner;
public string? Value => Owner.Color.ToString();

public void SetValue(string? value)
{
if (!Color.TryParse(value, out var color))
{
throw new System.FormatException($"Invalid color string: '{value}'.");
}

Owner.Color = color;
}

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

protected override string GetClassNameCore() => nameof(ColorSpectrum);

private void OwnerOnColorChanged(object? sender, ColorChangedEventArgs e)
{
RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, e.OldColor.ToString(), e.NewColor.ToString());
}
}
11 changes: 9 additions & 2 deletions src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Collections.Pooled;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
Expand Down Expand Up @@ -197,6 +198,11 @@ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e
base.OnDetachedFromVisualTree(e);
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new ColorSpectrumAutomationPeer(this);
}

/// <summary>
/// Explicitly unregisters all events connected in OnApplyTemplate().
/// </summary>
Expand Down Expand Up @@ -397,6 +403,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
{
if (change.Property == ColorProperty)
{
_oldColor = change.GetOldValue<Color>();

// If we're in the process of internally updating the color,
// then we don't want to respond to the Color property changing.
if (!_updatingColor)
Expand All @@ -410,9 +418,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

UpdateEllipse();
UpdateBitmapSources();
RaiseColorChanged();
}

_oldColor = change.GetOldValue<Color>();
}
else if (change.Property == HsvColorProperty)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Threading.Tasks;
using Avalonia.Collections;
using Avalonia.Controls.Metadata;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Controls.Utils;
Expand Down Expand Up @@ -774,6 +775,8 @@ protected override void OnLostFocus(FocusChangedEventArgs e)
FocusChanged(HasFocus());
}

protected override AutomationPeer OnCreateAutomationPeer() => new AutoCompleteBoxAutomationPeer(this);

/// <summary>
/// Determines whether the text box or drop-down portion of the
/// <see cref="T:Avalonia.Controls.AutoCompleteBox" /> control has
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using Avalonia.Automation;
using Avalonia.Automation.Provider;
using Avalonia.Controls;

namespace Avalonia.Automation.Peers
{
public class AutoCompleteBoxAutomationPeer : ControlAutomationPeer, IExpandCollapseProvider, IValueProvider
{
public AutoCompleteBoxAutomationPeer(AutoCompleteBox owner)
: base(owner)
{
owner.PropertyChanged += OwnerPropertyChanged;
}

public new AutoCompleteBox Owner => (AutoCompleteBox)base.Owner;

public ExpandCollapseState ExpandCollapseState => ToState(Owner.IsDropDownOpen);
public bool ShowsMenu => true;
public void Collapse() => Owner.IsDropDownOpen = false;
public void Expand() => Owner.IsDropDownOpen = true;
public bool IsReadOnly => false;

public string? Value
{
get => Owner.Text;
set
{
if (value == Owner.Text)
return;

Owner.Text = value;
}
}

void IValueProvider.SetValue(string? value) => Owner.Text = value;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Group;
}

protected override string GetClassNameCore() => nameof(AutoCompleteBox);

private void OwnerPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == AutoCompleteBox.IsDropDownOpenProperty)
{
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ToState(e.GetOldValue<bool>()),
ToState(e.GetNewValue<bool>()));
}
else if (e.Property == AutoCompleteBox.TextProperty)
{
RaisePropertyChangedEvent(
ValuePatternIdentifiers.ValueProperty,
e.OldValue,
e.NewValue);
}
}

private static ExpandCollapseState ToState(bool value)
{
return value ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
}
}
}
57 changes: 57 additions & 0 deletions src/Avalonia.Controls/Automation/Peers/CalendarAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Automation;
using Avalonia.Automation.Provider;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;

namespace Avalonia.Automation.Peers
{
public class CalendarAutomationPeer : ControlAutomationPeer, ISelectionProvider, IValueProvider
{
public CalendarAutomationPeer(Calendar owner)
: base(owner)
{
owner.SelectedDatesChanged += OwnerSelectedDatesChanged;
}

public new Calendar Owner => (Calendar)base.Owner;

public bool CanSelectMultiple =>
Owner.SelectionMode == CalendarSelectionMode.SingleRange ||
Owner.SelectionMode == CalendarSelectionMode.MultipleRange;

public bool IsSelectionRequired => false;

public IReadOnlyList<AutomationPeer> GetSelection()
{
return Owner.SelectedDates.Select(date => Owner.FindDayButtonFromDay(date))
.OfType<CalendarDayButton>().Select(GetOrCreate).ToList();
}

public bool IsReadOnly => true;

public string? Value => string.Join(
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator,
Owner.SelectedDates.Select(x => x.ToString(System.Globalization.CultureInfo.CurrentCulture)));

public void SetValue(string? value)
{
throw new NotSupportedException();
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Calendar;
}

protected override string GetClassNameCore() => nameof(Calendar);

private void OwnerSelectedDatesChanged(object? sender, SelectionChangedEventArgs e)
{
RaisePropertyChangedEvent(SelectionPatternIdentifiers.SelectionProperty, null, null);
RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, null, null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using Avalonia.Automation;
using Avalonia.Automation.Provider;
using Avalonia.Controls;

namespace Avalonia.Automation.Peers
{
public class CalendarDatePickerAutomationPeer : ControlAutomationPeer,
IInvokeProvider,
IExpandCollapseProvider,
IValueProvider
{
public CalendarDatePickerAutomationPeer(CalendarDatePicker owner)
: base(owner)
{
Owner.PropertyChanged += OwnerPropertyChanged;
}

public new CalendarDatePicker Owner => (CalendarDatePicker)base.Owner;

public ExpandCollapseState ExpandCollapseState => ToState(Owner.IsDropDownOpen);

public bool ShowsMenu => true;

public bool IsReadOnly => false;

public string? Value => Owner.Text;

public void Invoke()
{
EnsureEnabled();
Owner.IsDropDownOpen = true;
}

public void Expand() => Owner.IsDropDownOpen = true;

public void Collapse() => Owner.IsDropDownOpen = false;

public void SetValue(string? value) => Owner.Text = value;

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

protected override string GetClassNameCore() => "CalendarDatePicker";

protected override bool IsContentElementCore() => true;

protected override bool IsControlElementCore() => true;

private void OwnerPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == CalendarDatePicker.TextProperty)
{
RaisePropertyChangedEvent(
ValuePatternIdentifiers.ValueProperty,
e.OldValue,
e.NewValue);
}
else if (e.Property == CalendarDatePicker.IsDropDownOpenProperty)
{
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ToState(e.GetOldValue<bool>()),
ToState(e.GetNewValue<bool>()));
}
}

private static ExpandCollapseState ToState(bool isExpanded)
{
return isExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Avalonia.Controls;

namespace Avalonia.Automation.Peers
{
public class NativeMenuBarAutomationPeer(NativeMenuBar owner) : ControlAutomationPeer(owner)
{
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.MenuBar;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using Avalonia.Automation;
using Avalonia.Automation.Provider;
using Avalonia.Controls;

namespace Avalonia.Automation.Peers
{
public class NumericUpDownAutomationPeer : ControlAutomationPeer, IRangeValueProvider
{
public NumericUpDownAutomationPeer(NumericUpDown owner)
: base(owner)
{
Owner.PropertyChanged += OwnerPropertyChanged;
}

public new NumericUpDown Owner => (NumericUpDown)base.Owner;

public bool IsReadOnly => Owner.IsReadOnly;

public double Maximum => (double)Owner.Maximum;

public double Minimum => (double)Owner.Minimum;

public double Value => Owner.Value.HasValue
? (double)Owner.Value.Value
: (double)Math.Clamp(0m, Owner.Minimum, Owner.Maximum);

public double SmallChange => (double)Owner.Increment;

public double LargeChange => (double)Owner.Increment;

public void SetValue(double value)
{
Owner.Value = (decimal)value;
}

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

protected override string GetClassNameCore() => "NumericUpDown";

private void OwnerPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == NumericUpDown.MinimumProperty)
{
RaisePropertyChangedEvent(
RangeValuePatternIdentifiers.MinimumProperty,
e.OldValue,
e.NewValue);
}
else if (e.Property == NumericUpDown.MaximumProperty)
{
RaisePropertyChangedEvent(
RangeValuePatternIdentifiers.MaximumProperty,
e.OldValue,
e.NewValue);
}
else if (e.Property == NumericUpDown.ValueProperty)
{
RaisePropertyChangedEvent(
RangeValuePatternIdentifiers.ValueProperty,
e.OldValue,
e.NewValue);
}
else if (e.Property == NumericUpDown.IsReadOnlyProperty)
{
RaisePropertyChangedEvent(
RangeValuePatternIdentifiers.IsReadOnlyProperty,
e.OldValue,
e.NewValue);
}
}
}
}
Loading