Skip to content

Commit

Permalink
Adding automation peer for RibbonGroupBox #647
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Sep 18, 2019
1 parent b632883 commit 17740b0
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 2 deletions.
52 changes: 52 additions & 0 deletions Fluent.Ribbon/Automation/Peers/RibbonControlDataAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Fluent.Automation.Peers
{
using System.Windows.Automation.Peers;
using Fluent.Extensions;

/// <summary>
/// Automation peer for ribbon control items.
/// </summary>
public class RibbonControlDataAutomationPeer : ItemAutomationPeer
{
/// <summary>
/// Creates a new instance.
/// </summary>
public RibbonControlDataAutomationPeer(object item, ItemsControlAutomationPeer itemsControlPeer)
: base(item, itemsControlPeer)
{
}

/// <inheritdoc />
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.ListItem;
}

/// <inheritdoc />
protected override string GetClassNameCore()
{
var wrapperPeer = this.GetWrapperPeer();

if (wrapperPeer != null)
{
return wrapperPeer.GetClassName();
}

return string.Empty;
}

/// <inheritdoc />
public override object GetPattern(PatternInterface patternInterface)
{
object result = null;
var wrapperPeer = this.GetWrapperPeer();

if (wrapperPeer != null)
{
result = wrapperPeer.GetPattern(patternInterface);
}

return result;
}
}
}
102 changes: 102 additions & 0 deletions Fluent.Ribbon/Automation/Peers/RibbonGroupBoxAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
namespace Fluent.Automation.Peers
{
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using JetBrains.Annotations;

/// <summary>
/// Automation peer for <see cref="RibbonGroupBox"/>.
/// </summary>
public class RibbonGroupBoxAutomationPeer : ItemsControlAutomationPeer
{
private RibbonGroupHeaderAutomationPeer headerPeer;

private RibbonGroupBox OwningGroup => (RibbonGroupBox)this.Owner;

private RibbonGroupHeaderAutomationPeer HeaderPeer
{
get
{
if (this.headerPeer == null
|| !this.headerPeer.Owner.IsDescendantOf(this.OwningGroup))
{
if (this.OwningGroup.State == RibbonGroupBoxState.Collapsed)
{
if (this.OwningGroup.DropDownPopup != null)
{
this.headerPeer = new RibbonGroupHeaderAutomationPeer(this.OwningGroup.DropDownPopup);
}
}
else if (this.OwningGroup.Header != null)
{
this.headerPeer = new RibbonGroupHeaderAutomationPeer(this.OwningGroup);
}
}

return this.headerPeer;
}
}

/// <summary>
/// Creates a new instance.
/// </summary>
public RibbonGroupBoxAutomationPeer([NotNull] RibbonGroupBox owner)
: base(owner)
{
}

/// <inheritdoc />
protected override List<AutomationPeer> GetChildrenCore()
{
var list = base.GetChildrenCore();

if (this.HeaderPeer != null)
{
if (list == null)
{
list = new List<AutomationPeer>(1);
}

list.Add(this.HeaderPeer);
}

return list;
}

/// <inheritdoc />
protected override string GetClassNameCore()
{
return this.Owner.GetType().Name;
}

/// <inheritdoc />
public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Scroll)
{
return null;
}

return base.GetPattern(patternInterface);
}

/// <inheritdoc />
protected override void SetFocusCore()
{
}

/// <inheritdoc />
protected override ItemAutomationPeer CreateItemAutomationPeer(object item)
{
return new RibbonControlDataAutomationPeer(item, this);
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue)
{
this.EventsSource?.RaisePropertyChangedEvent(ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed, newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
}
}
10 changes: 8 additions & 2 deletions Fluent.Ribbon/Controls/RibbonGroupBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Fluent
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
Expand Down Expand Up @@ -971,9 +972,11 @@ private void OnDialogLauncherButtonClick(object sender, RoutedEventArgs e)
/// <param name="e">The event data</param>
private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ribbon = (RibbonGroupBox)d;
var groupBox = (RibbonGroupBox)d;

ribbon.OnIsDropDownOpenChanged();
groupBox.OnIsDropDownOpenChanged();

(UIElementAutomationPeer.FromElement(groupBox) as Fluent.Automation.Peers.RibbonGroupBoxAutomationPeer)?.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue);
}

private void OnIsDropDownOpenChanged()
Expand Down Expand Up @@ -1154,5 +1157,8 @@ void ILogicalChildSupport.RemoveLogicalChild(object child)
{
this.RemoveLogicalChild(child);
}

/// <inheritdoc />
protected override AutomationPeer OnCreateAutomationPeer() => new Fluent.Automation.Peers.RibbonGroupBoxAutomationPeer(this);
}
}

0 comments on commit 17740b0

Please sign in to comment.