-
-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a few automation peers for #647
- Loading branch information
Showing
9 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
Fluent.Ribbon/Automation/Peers/DropDownButtonAutomationPeer.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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
namespace Fluent.Automation.Peers | ||
{ | ||
using System.Runtime.CompilerServices; | ||
using System.Windows.Automation; | ||
using System.Windows.Automation.Peers; | ||
using System.Windows.Automation.Provider; | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// Automation peer for <see cref="DropDownButton"/>. | ||
/// </summary> | ||
public class DropDownButtonAutomationPeer : HeaderedControlAutomationPeer, IToggleProvider | ||
{ | ||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
public DropDownButtonAutomationPeer([NotNull] DropDownButton owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetClassNameCore() | ||
{ | ||
return "DropDownButton"; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override object GetPattern(PatternInterface patternInterface) | ||
{ | ||
if (patternInterface == PatternInterface.Toggle) | ||
{ | ||
return this; | ||
} | ||
|
||
return base.GetPattern(patternInterface); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Toggle() | ||
{ | ||
((DropDownButton)this.Owner).IsDropDownOpen = !((DropDownButton)this.Owner).IsDropDownOpen; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ToggleState ToggleState => ConvertToToggleState(((DropDownButton)this.Owner).IsDropDownOpen); | ||
|
||
private static ToggleState ConvertToToggleState(bool value) | ||
{ | ||
return value | ||
? ToggleState.On | ||
: ToggleState.Off; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
internal virtual void RaiseToggleStatePropertyChangedEvent(bool oldValue, bool newValue) | ||
{ | ||
this.RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty, ConvertToToggleState(oldValue), ConvertToToggleState(newValue)); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Fluent.Ribbon/Automation/Peers/HeaderedControlAutomationPeer.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Fluent.Automation.Peers | ||
{ | ||
using System.Windows; | ||
using System.Windows.Automation.Peers; | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// Base automation peer for <see cref="IHeaderedControl"/>. | ||
/// </summary> | ||
public abstract class HeaderedControlAutomationPeer : FrameworkElementAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
protected HeaderedControlAutomationPeer([NotNull] FrameworkElement owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetNameCore() | ||
{ | ||
var text = base.GetNameCore(); | ||
var owner = (IHeaderedControl)this.Owner; | ||
|
||
if (string.IsNullOrEmpty(text)) | ||
{ | ||
if (owner.Header is string headerString) | ||
{ | ||
return headerString; | ||
} | ||
} | ||
|
||
return text; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Fluent.Ribbon/Automation/Peers/InRibbonGalleryAutomationPeer.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Fluent.Automation.Peers | ||
{ | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// Automation peer for <see cref="InRibbonGallery" /> | ||
/// </summary> | ||
// todo: add full automation for expansion, listing items (?) etc. | ||
public class InRibbonGalleryAutomationPeer : HeaderedControlAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
public InRibbonGalleryAutomationPeer([NotNull] InRibbonGallery owner) | ||
: base(owner) | ||
{ | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Fluent.Automation.Peers | ||
{ | ||
using System.Windows; | ||
using System.Windows.Automation; | ||
using System.Windows.Automation.Peers; | ||
using System.Windows.Automation.Provider; | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// Automation peer for <see cref="ScreenTip" />. | ||
/// </summary> | ||
public class ScreenTipAutomationPeer : ToolTipAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
public ScreenTipAutomationPeer([NotNull] ScreenTip owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override bool IsContentElementCore() | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Fluent.Ribbon/Automation/Peers/SplitButtonAutomationPeer.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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace Fluent.Automation.Peers | ||
{ | ||
using System.Windows.Automation; | ||
using System.Windows.Automation.Peers; | ||
using System.Windows.Automation.Provider; | ||
using System.Windows.Threading; | ||
using Fluent.Extensions; | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// Automation peer for <see cref="SplitButton"/>. | ||
/// </summary> | ||
public class SplitButtonAutomationPeer : DropDownButtonAutomationPeer, IInvokeProvider | ||
{ | ||
/// <summary> | ||
/// Creates a new instance. | ||
/// </summary> | ||
public SplitButtonAutomationPeer([NotNull] SplitButton owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetClassNameCore() | ||
{ | ||
return "SplitButton"; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.SplitButton; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override object GetPattern(PatternInterface patternInterface) | ||
{ | ||
if (patternInterface == PatternInterface.Invoke) | ||
{ | ||
//return ((SplitButton)this.Owner).button; | ||
return this; | ||
} | ||
|
||
return base.GetPattern(patternInterface); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Invoke() | ||
{ | ||
if (this.IsEnabled() == false) | ||
{ | ||
throw new ElementNotEnabledException(); | ||
} | ||
|
||
this.RunInDispatcherAsync(() => ((SplitButton)this.Owner).AutomationButtonClick(), DispatcherPriority.Input); | ||
} | ||
} | ||
} |
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
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
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
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