From 9870ee125e9ac4eb655b80ad0128b8ffe9fba35f Mon Sep 17 00:00:00 2001 From: T Paine <30241445+teaP@users.noreply.github.com> Date: Mon, 25 Nov 2019 13:02:12 -0800 Subject: [PATCH] Make API changes and switch from preview. (#1673) --- dev/Generated/NumberBox.properties.cpp | 41 ++++--------------- dev/Generated/NumberBox.properties.h | 13 ++---- .../InteractionTests/NumberBoxTests.cs | 10 ++--- dev/NumberBox/NumberBox.cpp | 36 ++++++++++------ dev/NumberBox/NumberBox.h | 2 + dev/NumberBox/NumberBox.idl | 18 ++++---- dev/NumberBox/TestUI/NumberBoxPage.xaml | 7 +--- 7 files changed, 52 insertions(+), 75 deletions(-) diff --git a/dev/Generated/NumberBox.properties.cpp b/dev/Generated/NumberBox.properties.cpp index b07accec12..7aaa1bf8e2 100644 --- a/dev/Generated/NumberBox.properties.cpp +++ b/dev/Generated/NumberBox.properties.cpp @@ -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 }; @@ -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(), winrt::name_of(), false /* isAttached */, @@ -80,17 +79,6 @@ void NumberBoxProperties::EnsureProperties() ValueHelper::BoxedDefaultValue(), nullptr); } - if (!s_IsHyperScrollEnabledProperty) - { - s_IsHyperScrollEnabledProperty = - InitializeDependencyProperty( - L"IsHyperScrollEnabled", - winrt::name_of(), - winrt::name_of(), - false /* isAttached */, - ValueHelper::BoxValueIfNecessary(false), - nullptr); - } if (!s_IsWrapEnabledProperty) { s_IsWrapEnabledProperty = @@ -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; @@ -352,14 +339,14 @@ void NumberBoxProperties::OnValuePropertyChanged( winrt::get_self(owner)->OnValuePropertyChanged(args); } -void NumberBoxProperties::AcceptsCalculation(bool value) +void NumberBoxProperties::AcceptsExpression(bool value) { - static_cast(this)->SetValue(s_AcceptsCalculationProperty, ValueHelper::BoxValueIfNecessary(value)); + static_cast(this)->SetValue(s_AcceptsExpressionProperty, ValueHelper::BoxValueIfNecessary(value)); } -bool NumberBoxProperties::AcceptsCalculation() +bool NumberBoxProperties::AcceptsExpression() { - return ValueHelper::CastOrUnbox(static_cast(this)->GetValue(s_AcceptsCalculationProperty)); + return ValueHelper::CastOrUnbox(static_cast(this)->GetValue(s_AcceptsExpressionProperty)); } void NumberBoxProperties::Description(winrt::IInspectable const& value) @@ -392,16 +379,6 @@ winrt::DataTemplate NumberBoxProperties::HeaderTemplate() return ValueHelper::CastOrUnbox(static_cast(this)->GetValue(s_HeaderTemplateProperty)); } -void NumberBoxProperties::IsHyperScrollEnabled(bool value) -{ - static_cast(this)->SetValue(s_IsHyperScrollEnabledProperty, ValueHelper::BoxValueIfNecessary(value)); -} - -bool NumberBoxProperties::IsHyperScrollEnabled() -{ - return ValueHelper::CastOrUnbox(static_cast(this)->GetValue(s_IsHyperScrollEnabledProperty)); -} - void NumberBoxProperties::IsWrapEnabled(bool value) { static_cast(this)->SetValue(s_IsWrapEnabledProperty, ValueHelper::BoxValueIfNecessary(value)); diff --git a/dev/Generated/NumberBox.properties.h b/dev/Generated/NumberBox.properties.h index bfb7b97568..d74e011c37 100644 --- a/dev/Generated/NumberBox.properties.h +++ b/dev/Generated/NumberBox.properties.h @@ -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(); @@ -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(); @@ -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; } @@ -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; diff --git a/dev/NumberBox/InteractionTests/NumberBoxTests.cs b/dev/NumberBox/InteractionTests/NumberBoxTests.cs index ef75bfea47..e1011a308a 100644 --- a/dev/NumberBox/InteractionTests/NumberBoxTests.cs +++ b/dev/NumberBox/InteractionTests/NumberBoxTests.cs @@ -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")) @@ -298,8 +298,6 @@ public void ScrollTest() { RangeValueSpinner numBox = FindElement.ByName("TestNumberBox"); - Check("HyperScrollCheckBox"); - Log.Comment("Verify that scroll doesn't work when the control doesn't have focus."); InputHelper.RotateWheel(numBox, 1); Wait.ForIdle(); @@ -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("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; diff --git a/dev/NumberBox/NumberBox.cpp b/dev/NumberBox/NumberBox.cpp index d32ef9ef77..9975822241 100644 --- a/dev/NumberBox/NumberBox.cpp +++ b/dev/NumberBox/NumberBox.cpp @@ -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; }()); @@ -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(); - const winrt::IReference value = AcceptsCalculation() + const winrt::IReference value = AcceptsExpression() ? NumberBoxParser::Compute(text, numberParser) : numberParser.ParseDouble(text); @@ -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) diff --git a/dev/NumberBox/NumberBox.h b/dev/NumberBox/NumberBox.h index 3f5c625061..290b123ca3 100644 --- a/dev/NumberBox/NumberBox.h +++ b/dev/NumberBox/NumberBox.h @@ -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); @@ -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{}; }; diff --git a/dev/NumberBox/NumberBox.idl b/dev/NumberBox/NumberBox.idl index 1d972824b8..7caaf5d41d 100644 --- a/dev/NumberBox/NumberBox.idl +++ b/dev/NumberBox/NumberBox.idl @@ -1,7 +1,7 @@ namespace MU_XC_NAMESPACE { -[WUXC_VERSION_PREVIEW] +[WUXC_VERSION_MUXONLY] [webhosthidden] enum NumberBoxSpinButtonPlacementMode { @@ -10,7 +10,7 @@ enum NumberBoxSpinButtonPlacementMode Inline }; -[WUXC_VERSION_PREVIEW] +[WUXC_VERSION_MUXONLY] [webhosthidden] enum NumberBoxValidationMode { @@ -18,7 +18,7 @@ enum NumberBoxValidationMode Disabled }; -[WUXC_VERSION_PREVIEW] +[WUXC_VERSION_MUXONLY] [webhosthidden] runtimeclass NumberBoxValueChangedEventArgs { @@ -26,7 +26,7 @@ runtimeclass NumberBoxValueChangedEventArgs Double NewValue{ get; }; }; -[WUXC_VERSION_PREVIEW] +[WUXC_VERSION_MUXONLY] [webhosthidden] unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control { @@ -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")] @@ -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; }; } @@ -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 { diff --git a/dev/NumberBox/TestUI/NumberBoxPage.xaml b/dev/NumberBox/TestUI/NumberBoxPage.xaml index e5d50b3ee8..711771fb3e 100644 --- a/dev/NumberBox/TestUI/NumberBoxPage.xaml +++ b/dev/NumberBox/TestUI/NumberBoxPage.xaml @@ -32,10 +32,8 @@ - - - + @@ -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}"/>