Skip to content

Commit

Permalink
Make API changes and switch from preview. (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
teaP authored Nov 25, 2019
1 parent c5b73db commit 9870ee1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 75 deletions.
41 changes: 9 additions & 32 deletions dev/Generated/NumberBox.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

CppWinRTActivatableClassWithDPFactory(NumberBox)

GlobalDependencyProperty NumberBoxProperties::s_AcceptsCalculationProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_AcceptsExpressionProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_DescriptionProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HeaderProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HeaderTemplateProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_IsHyperScrollEnabledProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_IsWrapEnabledProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_MaximumProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_MinimumProperty{ nullptr };
Expand All @@ -36,11 +35,11 @@ NumberBoxProperties::NumberBoxProperties()

void NumberBoxProperties::EnsureProperties()
{
if (!s_AcceptsCalculationProperty)
if (!s_AcceptsExpressionProperty)
{
s_AcceptsCalculationProperty =
s_AcceptsExpressionProperty =
InitializeDependencyProperty(
L"AcceptsCalculation",
L"AcceptsExpression",
winrt::name_of<bool>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
Expand Down Expand Up @@ -80,17 +79,6 @@ void NumberBoxProperties::EnsureProperties()
ValueHelper<winrt::DataTemplate>::BoxedDefaultValue(),
nullptr);
}
if (!s_IsHyperScrollEnabledProperty)
{
s_IsHyperScrollEnabledProperty =
InitializeDependencyProperty(
L"IsHyperScrollEnabled",
winrt::name_of<bool>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<bool>::BoxValueIfNecessary(false),
nullptr);
}
if (!s_IsWrapEnabledProperty)
{
s_IsWrapEnabledProperty =
Expand Down Expand Up @@ -249,11 +237,10 @@ void NumberBoxProperties::EnsureProperties()

void NumberBoxProperties::ClearProperties()
{
s_AcceptsCalculationProperty = nullptr;
s_AcceptsExpressionProperty = nullptr;
s_DescriptionProperty = nullptr;
s_HeaderProperty = nullptr;
s_HeaderTemplateProperty = nullptr;
s_IsHyperScrollEnabledProperty = nullptr;
s_IsWrapEnabledProperty = nullptr;
s_MaximumProperty = nullptr;
s_MinimumProperty = nullptr;
Expand Down Expand Up @@ -352,14 +339,14 @@ void NumberBoxProperties::OnValuePropertyChanged(
winrt::get_self<NumberBox>(owner)->OnValuePropertyChanged(args);
}

void NumberBoxProperties::AcceptsCalculation(bool value)
void NumberBoxProperties::AcceptsExpression(bool value)
{
static_cast<NumberBox*>(this)->SetValue(s_AcceptsCalculationProperty, ValueHelper<bool>::BoxValueIfNecessary(value));
static_cast<NumberBox*>(this)->SetValue(s_AcceptsExpressionProperty, ValueHelper<bool>::BoxValueIfNecessary(value));
}

bool NumberBoxProperties::AcceptsCalculation()
bool NumberBoxProperties::AcceptsExpression()
{
return ValueHelper<bool>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_AcceptsCalculationProperty));
return ValueHelper<bool>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_AcceptsExpressionProperty));
}

void NumberBoxProperties::Description(winrt::IInspectable const& value)
Expand Down Expand Up @@ -392,16 +379,6 @@ winrt::DataTemplate NumberBoxProperties::HeaderTemplate()
return ValueHelper<winrt::DataTemplate>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_HeaderTemplateProperty));
}

void NumberBoxProperties::IsHyperScrollEnabled(bool value)
{
static_cast<NumberBox*>(this)->SetValue(s_IsHyperScrollEnabledProperty, ValueHelper<bool>::BoxValueIfNecessary(value));
}

bool NumberBoxProperties::IsHyperScrollEnabled()
{
return ValueHelper<bool>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_IsHyperScrollEnabledProperty));
}

void NumberBoxProperties::IsWrapEnabled(bool value)
{
static_cast<NumberBox*>(this)->SetValue(s_IsWrapEnabledProperty, ValueHelper<bool>::BoxValueIfNecessary(value));
Expand Down
13 changes: 4 additions & 9 deletions dev/Generated/NumberBox.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class NumberBoxProperties
public:
NumberBoxProperties();

void AcceptsCalculation(bool value);
bool AcceptsCalculation();
void AcceptsExpression(bool value);
bool AcceptsExpression();

void Description(winrt::IInspectable const& value);
winrt::IInspectable Description();
Expand All @@ -21,9 +21,6 @@ class NumberBoxProperties
void HeaderTemplate(winrt::DataTemplate const& value);
winrt::DataTemplate HeaderTemplate();

void IsHyperScrollEnabled(bool value);
bool IsHyperScrollEnabled();

void IsWrapEnabled(bool value);
bool IsWrapEnabled();

Expand Down Expand Up @@ -66,11 +63,10 @@ class NumberBoxProperties
void Value(double value);
double Value();

static winrt::DependencyProperty AcceptsCalculationProperty() { return s_AcceptsCalculationProperty; }
static winrt::DependencyProperty AcceptsExpressionProperty() { return s_AcceptsExpressionProperty; }
static winrt::DependencyProperty DescriptionProperty() { return s_DescriptionProperty; }
static winrt::DependencyProperty HeaderProperty() { return s_HeaderProperty; }
static winrt::DependencyProperty HeaderTemplateProperty() { return s_HeaderTemplateProperty; }
static winrt::DependencyProperty IsHyperScrollEnabledProperty() { return s_IsHyperScrollEnabledProperty; }
static winrt::DependencyProperty IsWrapEnabledProperty() { return s_IsWrapEnabledProperty; }
static winrt::DependencyProperty MaximumProperty() { return s_MaximumProperty; }
static winrt::DependencyProperty MinimumProperty() { return s_MinimumProperty; }
Expand All @@ -86,11 +82,10 @@ class NumberBoxProperties
static winrt::DependencyProperty ValidationModeProperty() { return s_ValidationModeProperty; }
static winrt::DependencyProperty ValueProperty() { return s_ValueProperty; }

static GlobalDependencyProperty s_AcceptsCalculationProperty;
static GlobalDependencyProperty s_AcceptsExpressionProperty;
static GlobalDependencyProperty s_DescriptionProperty;
static GlobalDependencyProperty s_HeaderProperty;
static GlobalDependencyProperty s_HeaderTemplateProperty;
static GlobalDependencyProperty s_IsHyperScrollEnabledProperty;
static GlobalDependencyProperty s_IsWrapEnabledProperty;
static GlobalDependencyProperty s_MaximumProperty;
static GlobalDependencyProperty s_MinimumProperty;
Expand Down
10 changes: 4 additions & 6 deletions dev/NumberBox/InteractionTests/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void BasicKeyboardTest()
}
}

// [TestMethod] Disabled because GamePad A gets eaten by the TextBox.
[TestMethod]
public void GamepadTest()
{
using (var setup = new TestSetupHelper("NumberBox Tests"))
Expand Down Expand Up @@ -298,8 +298,6 @@ public void ScrollTest()
{
RangeValueSpinner numBox = FindElement.ByName<RangeValueSpinner>("TestNumberBox");

Check("HyperScrollCheckBox");

Log.Comment("Verify that scroll doesn't work when the control doesn't have focus.");
InputHelper.RotateWheel(numBox, 1);
Wait.ForIdle();
Expand Down Expand Up @@ -421,17 +419,17 @@ public void ValueChangedTest()
}

[TestMethod]
public void BasicCalculationTest()
public void BasicExpressionTest()
{
using (var setup = new TestSetupHelper("NumberBox Tests"))
{
RangeValueSpinner numBox = FindElement.ByName<RangeValueSpinner>("TestNumberBox");

Log.Comment("Verify that calculations don't work if AcceptsCalculations is false");
Log.Comment("Verify that expressions don't work if AcceptsExpression is false");
EnterText(numBox, "5 + 3");
Verify.AreEqual(0, numBox.Value);

Check("CalculationCheckBox");
Check("ExpressionCheckBox");

int numErrors = 0;
const double resetValue = 1234;
Expand Down
36 changes: 24 additions & 12 deletions dev/NumberBox/NumberBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void NumberBox::OnApplyTemplate()
if (textBox)
{
m_textBoxKeyDownRevoker = textBox.KeyDown(winrt::auto_revoke, { this, &NumberBox::OnNumberBoxKeyDown });
m_textBoxKeyUpRevoker = textBox.KeyUp(winrt::auto_revoke, { this, &NumberBox::OnNumberBoxKeyUp });
}
return textBox;
}());
Expand Down Expand Up @@ -322,7 +323,7 @@ void NumberBox::ValidateInput()
// Setting NumberFormatter to something that isn't an INumberParser will throw an exception, so this should be safe
const auto numberParser = NumberFormatter().as<winrt::INumberParser>();

const winrt::IReference<double> value = AcceptsCalculation()
const winrt::IReference<double> value = AcceptsExpression()
? NumberBoxParser::Compute(text, numberParser)
: numberParser.ParseDouble(text);

Expand Down Expand Up @@ -362,33 +363,44 @@ void NumberBox::OnSpinUpClick(winrt::IInspectable const& sender, winrt::RoutedEv

void NumberBox::OnNumberBoxKeyDown(winrt::IInspectable const& sender, winrt::KeyRoutedEventArgs const& args)
{
// Handle these on key down so that we get repeat behavior.
switch (args.OriginalKey())
{
case winrt::VirtualKey::Enter:
case winrt::VirtualKey::GamepadA:
ValidateInput();
break;

case winrt::VirtualKey::Escape:
case winrt::VirtualKey::GamepadB:
UpdateTextToValue();
break;

case winrt::VirtualKey::Up:
StepValueUp();
args.Handled(true);
break;

case winrt::VirtualKey::Down:
StepValueDown();
args.Handled(true);
break;
}
}

void NumberBox::OnNumberBoxKeyUp(winrt::IInspectable const& sender, winrt::KeyRoutedEventArgs const& args)
{
switch (args.OriginalKey())
{
case winrt::VirtualKey::Enter:
case winrt::VirtualKey::GamepadA:
ValidateInput();
args.Handled(true);
break;

case winrt::VirtualKey::Escape:
case winrt::VirtualKey::GamepadB:
UpdateTextToValue();
args.Handled(true);
break;
}
}

void NumberBox::OnNumberBoxScroll(winrt::IInspectable const& sender, winrt::PointerRoutedEventArgs const& args)
{
if (auto && textBox = m_textBox.get())
{
if (IsHyperScrollEnabled() && textBox.FocusState() != winrt::FocusState::Unfocused)
if (textBox.FocusState() != winrt::FocusState::Unfocused)
{
const auto delta = args.GetCurrentPoint(*this).Properties().MouseWheelDelta();
if (delta > 0)
Expand Down
2 changes: 2 additions & 0 deletions dev/NumberBox/NumberBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class NumberBox :
void OnSpinDownClick(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
void OnSpinUpClick(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
void OnNumberBoxKeyDown(winrt::IInspectable const& sender, winrt::KeyRoutedEventArgs const& args);
void OnNumberBoxKeyUp(winrt::IInspectable const& sender, winrt::KeyRoutedEventArgs const& args);
void OnNumberBoxGotFocus(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
void OnNumberBoxLostFocus(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
void OnNumberBoxScroll(winrt::IInspectable const& sender, winrt::PointerRoutedEventArgs const& args);
Expand Down Expand Up @@ -88,6 +89,7 @@ class NumberBox :
winrt::RepeatButton::Click_revoker m_upButtonClickRevoker{};
winrt::RepeatButton::Click_revoker m_downButtonClickRevoker{};
winrt::TextBox::KeyDown_revoker m_textBoxKeyDownRevoker{};
winrt::TextBox::KeyUp_revoker m_textBoxKeyUpRevoker{};
winrt::RepeatButton::Click_revoker m_popupUpButtonClickRevoker{};
winrt::RepeatButton::Click_revoker m_popupDownButtonClickRevoker{};
};
18 changes: 7 additions & 11 deletions dev/NumberBox/NumberBox.idl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace MU_XC_NAMESPACE
{

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
enum NumberBoxSpinButtonPlacementMode
{
Expand All @@ -10,23 +10,23 @@ enum NumberBoxSpinButtonPlacementMode
Inline
};

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
enum NumberBoxValidationMode
{
InvalidInputOverwritten,
Disabled
};

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
runtimeclass NumberBoxValueChangedEventArgs
{
Double OldValue{ get; };
Double NewValue{ get; };
};

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control
{
Expand Down Expand Up @@ -68,15 +68,12 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control
[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
NumberBoxSpinButtonPlacementMode SpinButtonPlacementMode{ get; set; };

[MUX_DEFAULT_VALUE("false")]
Boolean IsHyperScrollEnabled;

[MUX_DEFAULT_VALUE("false")]
[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
Boolean IsWrapEnabled;

[MUX_DEFAULT_VALUE("false")]
Boolean AcceptsCalculation;
Boolean AcceptsExpression;

[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
[MUX_PROPERTY_VALIDATION_CALLBACK("ValidateNumberFormatter")]
Expand All @@ -101,9 +98,8 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control

static Windows.UI.Xaml.DependencyProperty ValidationModeProperty{ get; };
static Windows.UI.Xaml.DependencyProperty SpinButtonPlacementModeProperty{ get; };
static Windows.UI.Xaml.DependencyProperty IsHyperScrollEnabledProperty{ get; };
static Windows.UI.Xaml.DependencyProperty IsWrapEnabledProperty{ get; };
static Windows.UI.Xaml.DependencyProperty AcceptsCalculationProperty{ get; };
static Windows.UI.Xaml.DependencyProperty AcceptsExpressionProperty{ get; };

static Windows.UI.Xaml.DependencyProperty NumberFormatterProperty{ get; };
}
Expand All @@ -113,7 +109,7 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control
namespace MU_XAP_NAMESPACE
{

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
unsealed runtimeclass NumberBoxAutomationPeer : Windows.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer
{
Expand Down
7 changes: 2 additions & 5 deletions dev/NumberBox/TestUI/NumberBoxPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
</ComboBox>

<CheckBox x:Name="EnabledCheckBox" AutomationProperties.Name="EnabledCheckBox" IsChecked="True" Content="Enabled"/>

<CheckBox x:Name="CalculationCheckBox" AutomationProperties.Name="CalculationCheckBox" IsChecked="False" Content="Accepts Calculations"/>

<CheckBox x:Name="HyperScrollCheckBox" AutomationProperties.Name="HyperScrollCheckBox" IsChecked="False" Content="HyperScroll Enabled"/>
<CheckBox x:Name="ExpressionCheckBox" AutomationProperties.Name="ExpressionCheckBox" IsChecked="False" Content="Accepts Expression"/>

<CheckBox x:Name="WrapCheckBox" AutomationProperties.Name="WrapCheckBox" IsChecked="False" Content="Wrap Enabled"/>

Expand Down Expand Up @@ -72,8 +70,7 @@
PlaceholderText="Text"
ValueChanged="NumberBoxValueChanged"
StepFrequency="{x:Bind StepNumberBox.Value, Mode=OneWay}"
AcceptsCalculation="{x:Bind CalculationCheckBox.IsChecked.Value, Mode=OneWay}"
IsHyperScrollEnabled="{x:Bind HyperScrollCheckBox.IsChecked.Value, Mode=OneWay}"
AcceptsExpression="{x:Bind ExpressionCheckBox.IsChecked.Value, Mode=OneWay}"
IsWrapEnabled="{x:Bind WrapCheckBox.IsChecked.Value, Mode=OneWay}"
IsEnabled="{x:Bind EnabledCheckBox.IsChecked.Value, Mode=OneWay}"/>

Expand Down

0 comments on commit 9870ee1

Please sign in to comment.