Skip to content

Commit

Permalink
ProgressRing Automation Peer (#2065)
Browse files Browse the repository at this point in the history
* automationPeer scaffolding

* fix build errors

* remove IRangeValueProvider\

* implemement indeterminate behaviour for narrator

* create localized resource

* progressBar resources for all states

* changes from comments

* changes from comments

* re add IRangeValueProvider

* fix: stuck in updating state with indeterminate as default

* move Resources.resw in Strings\en-us folder

* Update ProgressBar.vcxitems

Fix Resources.resw path

* Update ProgressRing.vcxitems

Co-authored-by: Ranjesh <[email protected]>
  • Loading branch information
karkarl and ranjeshj authored Mar 11, 2020
1 parent b9c3c53 commit 929ce1f
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 9 deletions.
16 changes: 16 additions & 0 deletions dev/Generated/ProgressRingAutomationPeer.properties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// DO NOT EDIT! This file was generated by CustomTasks.DependencyPropertyCodeGen
#include "pch.h"
#include "common.h"
#include "ProgressRingAutomationPeer.h"

namespace winrt::Microsoft::UI::Xaml::Automation::Peers
{
CppWinRTActivatableClassWithBasicFactory(ProgressRingAutomationPeer)
}

#include "ProgressRingAutomationPeer.g.cpp"


2 changes: 0 additions & 2 deletions dev/ProgressBar/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ void ProgressBar::SetProgressBarIndicatorWidth()
{
indeterminateProgressBarIndicator2.Width(progressBarWidth * 0.6); // 60% of ProgressBar Width
}

return;
}
else if (std::abs(maximum - minimum) > DBL_EPSILON)
{
Expand Down
5 changes: 4 additions & 1 deletion dev/ProgressBar/ProgressBar.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@
<ItemGroup>
<Midl Include="$(MSBuildThisFileDirectory)ProgressBar.idl" />
</ItemGroup>
</Project>
<ItemGroup>
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\en-us\Resources.resw" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions dev/ProgressBar/ProgressBarAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ winrt::IInspectable ProgressBarAutomationPeer::GetPatternCore(winrt::PatternInte
{
if (patternInterface == winrt::PatternInterface::RangeValue)
{
if (auto progressBar = Owner().try_as<winrt::ProgressBar>())
{
if (progressBar.IsIndeterminate())
{
return nullptr;
}
}

return *this;
}

Expand All @@ -31,6 +39,29 @@ hstring ProgressBarAutomationPeer::GetClassNameCore()
return winrt::hstring_name_of<winrt::ProgressBar>();
}

winrt::hstring ProgressBarAutomationPeer::GetNameCore()
{
//Check to see if the item has a defined AutomationProperties.Name
winrt::hstring name = __super::GetNameCore();

if (auto progressBar = Owner().try_as<winrt::ProgressBar>())
{
if (progressBar.ShowError())
{
return winrt::hstring{ ResourceAccessor::GetLocalizedStringResource(SR_ProgressBarErrorStatus) + name };
}
else if (progressBar.ShowPaused())
{
return winrt::hstring{ ResourceAccessor::GetLocalizedStringResource(SR_ProgressBarPausedStatus) + name };
}
else if (progressBar.IsIndeterminate())
{
return winrt::hstring{ ResourceAccessor::GetLocalizedStringResource(SR_ProgressBarIndeterminateStatus) + name };
}
}
return name;
}

winrt::AutomationControlType ProgressBarAutomationPeer::GetAutomationControlTypeCore()
{
return winrt::AutomationControlType::ProgressBar;
Expand Down
5 changes: 4 additions & 1 deletion dev/ProgressBar/ProgressBarAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class ProgressBarAutomationPeer :

// IAutomationPeerOverrides
winrt::IInspectable GetPatternCore(winrt::PatternInterface const& patternInterface);
hstring GetClassNameCore();
winrt::hstring GetClassNameCore();
winrt::hstring GetNameCore();
winrt::AutomationControlType GetAutomationControlTypeCore();

// IRangeValueProvider is necessary here to override IsReadOnly() to true.
bool IsReadOnly() { return true; }
double Value();
double SmallChange();
Expand All @@ -26,6 +28,7 @@ class ProgressBarAutomationPeer :
double Maximum();
void SetValue(double value);


private:
com_ptr<ProgressBar> GetImpl();
};
Expand Down
132 changes: 132 additions & 0 deletions dev/ProgressBar/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ProgressBarErrorStatus" xml:space="preserve">
<value>Error</value>
<comment>This is used to announce Error state.</comment>
</data>
<data name="ProgressBarIndeterminateStatus" xml:space="preserve">
<value>Busy</value>
<comment>This is used to announce Indeterminate state.</comment>
</data>
<data name="ProgressBarPausedStatus" xml:space="preserve">
<value>Paused</value>
<comment>This is used to announce Paused state.</comment>
</data>
</root>
6 changes: 6 additions & 0 deletions dev/ProgressRing/ProgressRing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pch.h"
#include "common.h"
#include "ProgressRing.h"
#include "ProgressRingAutomationPeer.h"
#include "RuntimeProfiler.h"
#include "ResourceAccessor.h"
#include "math.h"
Expand Down Expand Up @@ -39,6 +40,11 @@ ProgressRing::ProgressRing()
SizeChanged({ this, &ProgressRing::OnSizeChanged });
}

winrt::AutomationPeer ProgressRing::OnCreateAutomationPeer()
{
return winrt::make<ProgressRingAutomationPeer>(*this);
}

void ProgressRing::OnApplyTemplate()
{
winrt::IControlProtected controlProtected{ *this };
Expand Down
2 changes: 1 addition & 1 deletion dev/ProgressRing/ProgressRing.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ProgressRing :
public:
ProgressRing();

winrt::AutomationPeer OnCreateAutomationPeer();
// IFrameworkElement
void OnApplyTemplate();

void OnStrokeThicknessPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnIsIndeterminatePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnForegroundPropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&);
void OnForegroundColorPropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&);
Expand Down
12 changes: 12 additions & 0 deletions dev/ProgressRing/ProgressRing.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ unsealed runtimeclass ProgressRing : Windows.UI.Xaml.Controls.Primitives.RangeBa
}

}

namespace MU_XAP_NAMESPACE
{

[WUXC_VERSION_PREVIEW]
[webhosthidden]
unsealed runtimeclass ProgressRingAutomationPeer : Windows.UI.Xaml.Automation.Peers.RangeBaseAutomationPeer
{
ProgressRingAutomationPeer(MU_XC_NAMESPACE.ProgressRing owner);
}

}
7 changes: 6 additions & 1 deletion dev/ProgressRing/ProgressRing.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)IThemedAnimatedVisualSource.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ProgressRingAutomationPeer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ProgressRingIndeterminate.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ProgressRing.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\ProgressRing.properties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProgressRingAutomationPeer.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProgressRingIndeterminate.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProgressRing.cpp" />
</ItemGroup>
Expand All @@ -37,4 +39,7 @@
<ItemGroup>
<Midl Include="$(MSBuildThisFileDirectory)ProgressRing.idl" />
</ItemGroup>
</Project>
<ItemGroup>
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\en-us\Resources.resw" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions dev/ProgressRing/ProgressRing.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\ProgressRing.properties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProgressRing.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProgressRingAutomationPeer.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProgressRingIndeterminate.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)ProgressRing.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)IThemedAnimatedVisualSource.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ProgressRingAutomationPeer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ProgressRingIndeterminate.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -18,8 +20,6 @@
<Page Include="$(MSBuildThisFileDirectory)ProgressRing_themeresources.xaml" />
</ItemGroup>
<ItemGroup>
<Filter Include="AnimatedVisuals">
<UniqueIdentifier>{76115a89-641e-4eaa-ac72-f01887e6cb2d}</UniqueIdentifier>
</Filter>
<PRIResource Include="$(MSBuildThisFileDirectory)Resources.resw" />
</ItemGroup>
</Project>
Loading

0 comments on commit 929ce1f

Please sign in to comment.