From 1b1eb4c7e79c3e075e49008d1e8583095e64b0c8 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Fri, 6 Mar 2020 16:25:50 -0800 Subject: [PATCH] Add automation name to graph control (#1032) * fix bugs * Update src/Calculator/Resources/en-US/Resources.resw Co-Authored-By: Rudy Huyn Co-authored-by: Rudy Huyn --- .../Automation/NarratorAnnouncement.cpp | 10 +++++ .../Common/Automation/NarratorAnnouncement.h | 1 + .../Common/LocalizationStringUtil.h | 12 +++++ src/Calculator/Resources/en-US/Resources.resw | 4 ++ .../GraphingCalculator.xaml | 3 ++ .../GraphingCalculator.xaml.cpp | 45 +++++++++++++++++++ .../GraphingCalculator.xaml.h | 5 +++ src/GraphControl/Control/Grapher.cpp | 7 +++ src/GraphControl/Control/Grapher.h | 2 + 9 files changed, 89 insertions(+) diff --git a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp index 15fca2c6..90e6feef 100644 --- a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp +++ b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp @@ -24,6 +24,7 @@ namespace CalculatorApp::Common::Automation StringReference OpenParenthesisCountChanged(L"OpenParenthesisCountChanged"); StringReference NoParenthesisAdded(L"NoParenthesisAdded"); StringReference GraphModeChanged(L"GraphModeChanged"); + StringReference GraphViewChanged(L"GraphViewChanged"); } } @@ -150,3 +151,12 @@ NarratorAnnouncement ^ CalculatorAnnouncement::GetGraphModeChangedAnnouncement(P AutomationNotificationKind::ActionCompleted, AutomationNotificationProcessing::ImportantMostRecent); } + +NarratorAnnouncement ^ CalculatorAnnouncement::GetGraphViewChangedAnnouncement(Platform::String ^ announcement) +{ + return ref new NarratorAnnouncement( + announcement, + CalculatorActivityIds::GraphViewChanged, + AutomationNotificationKind::ActionCompleted, + AutomationNotificationProcessing::MostRecent); +} diff --git a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h index 81c3856b..a1ba97ea 100644 --- a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h +++ b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h @@ -68,6 +68,7 @@ public static NarratorAnnouncement ^ GetNoRightParenthesisAddedAnnouncement(Platform::String ^ announcement); static NarratorAnnouncement ^ GetGraphModeChangedAnnouncement(Platform::String ^ announcement); + static NarratorAnnouncement ^ GetGraphViewChangedAnnouncement(Platform::String ^ announcement); }; } diff --git a/src/CalcViewModel/Common/LocalizationStringUtil.h b/src/CalcViewModel/Common/LocalizationStringUtil.h index 0e3d9dff..73da6d0d 100644 --- a/src/CalcViewModel/Common/LocalizationStringUtil.h +++ b/src/CalcViewModel/Common/LocalizationStringUtil.h @@ -81,6 +81,18 @@ namespace CalculatorApp { return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data(), param3->Data(), param4->Data()); } + + static Platform::String + ^ GetLocalizedString( + Platform::String ^ pMessage, + Platform::String ^ param1, + Platform::String ^ param2, + Platform::String ^ param3, + Platform::String ^ param4, + Platform::String ^ param5) + { + return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data(), param3->Data(), param4->Data(), param5->Data()); + } }; } } diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index abeb7b74..edb1da9d 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -4174,6 +4174,10 @@ Start tracing This is the tooltip/automation name for the graphing calculator start tracing button + + Graph viewing window, x-axis bounded by %1 and %2, y-axis bounded by %3 and %4, displaying %5 equations + {Locked="%1","%2", "%3", "%4", "%5"}. + Configure slider This is the tooltip text for the slider options button in Graphing Calculator diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml index 612324da..432b6bcb 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml @@ -471,7 +471,10 @@ VariableUpdated += ref new EventHandler(this, &CalculatorApp::GraphingCalculator::OnVariableChanged); + + UpdateGraphAutomationName(); } void GraphingCalculator::OnEquationsVectorChanged(IObservableVector ^ sender, IVectorChangedEventArgs ^ event) @@ -620,6 +623,48 @@ void GraphingCalculator::SetDefaultFocus() } } +void GraphingCalculator::GraphingControl_GraphViewChangedEvent(Object ^ sender, RoutedEventArgs ^ e) +{ + UpdateGraphAutomationName(); + + auto announcement = CalculatorAnnouncement::GetGraphViewChangedAnnouncement(GraphControlAutomationName); + auto peer = FrameworkElementAutomationPeer::FromElement(GraphingControl); + if (peer != nullptr) + { + peer->RaiseNotificationEvent(announcement->Kind, announcement->Processing, announcement->Announcement, announcement->ActivityId); + } +} + +void GraphingCalculator::GraphingControl_GraphPlottedEvent(Object ^ sender, RoutedEventArgs ^ e) +{ + UpdateGraphAutomationName(); +} + +void GraphingCalculator::UpdateGraphAutomationName() +{ + int numEquations = 0; + double xAxisMin, xAxisMax, yAxisMin, yAxisMax; + + // Only count equations that are graphed + for (auto equation : ViewModel->Equations) + { + if (equation->GraphEquation->IsValidated) + { + numEquations++; + } + } + + GraphingControl->GetDisplayRanges(&xAxisMin, &xAxisMax, &yAxisMin, &yAxisMax); + + GraphControlAutomationName = LocalizationStringUtil::GetLocalizedString( + AppResourceProvider::GetInstance()->GetResourceString(L"graphAutomationName"), + xAxisMin.ToString(), + xAxisMax.ToString(), + yAxisMin.ToString(), + yAxisMax.ToString(), + numEquations.ToString()); +} + void GraphingCalculator::GraphMenuFlyoutItem_Click(Object ^ sender, RoutedEventArgs ^ e) { auto dataPackage = ref new DataPackage(); diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h index 66b79eee..e1662cc5 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h @@ -27,6 +27,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo COMMAND_FOR_METHOD(ZoomResetButtonPressed, GraphingCalculator::OnZoomResetCommand); OBSERVABLE_PROPERTY_R(bool, IsKeyGraphFeaturesVisible); DEPENDENCY_PROPERTY(bool, IsSmallState); + DEPENDENCY_PROPERTY(Platform::String ^, GraphControlAutomationName); property CalculatorApp::ViewModel::GraphingCalculatorViewModel^ ViewModel { @@ -65,6 +66,8 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo void GraphingControl_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void GraphingControl_LosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args); void GraphingControl_VariablesUpdated(Platform::Object ^ sender, Object ^ args); + void GraphingControl_GraphViewChangedEvent(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void GraphingControl_GraphPlottedEvent(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void OnEquationKeyGraphFeaturesRequested(Platform::Object ^ sender, CalculatorApp::ViewModel::EquationViewModel ^ e); void OnKeyGraphFeaturesClosed(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void TraceValuePopup_SizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e); @@ -78,6 +81,8 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo void DisplayGraphSettings(); void AddTracePointerShadow(); + void UpdateGraphAutomationName(); + private: Windows::Foundation::EventRegistrationToken m_dataRequestedToken; Windows::Foundation::EventRegistrationToken m_vectorChangedToken; diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index 4ed9ed35..bb7c5a86 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -84,6 +84,7 @@ namespace GraphControl void Grapher::ZoomFromCenter(double scale) { ScaleRange(0, 0, scale); + GraphViewChangedEvent(this, ref new RoutedEventArgs()); } void Grapher::ScaleRange(double centerX, double centerY, double scale) @@ -95,6 +96,7 @@ namespace GraphControl if (SUCCEEDED(renderer->ScaleRange(centerX, centerY, scale))) { m_renderMain->RunRenderPass(); + GraphViewChangedEvent(this, ref new RoutedEventArgs()); } } } @@ -109,6 +111,7 @@ namespace GraphControl if (SUCCEEDED(renderer->ResetRange())) { m_renderMain->RunRenderPass(); + GraphViewChangedEvent(this, ref new RoutedEventArgs()); } } } @@ -249,6 +252,8 @@ namespace GraphControl co_await TryUpdateGraph(keepCurrentView); } } + + GraphPlottedEvent(this, ref new RoutedEventArgs()); } task Grapher::TryUpdateGraph(bool keepCurrentView) @@ -603,6 +608,7 @@ namespace GraphControl const auto [centerX, centerY] = PointerPositionToGraphPosition(pos.X, pos.Y, ActualWidth, ActualHeight); ScaleRange(centerX, centerY, scale); + GraphViewChangedEvent(this, ref new RoutedEventArgs()); e->Handled = true; } @@ -676,6 +682,7 @@ namespace GraphControl if (needsRenderPass) { m_renderMain->RunRenderPass(); + GraphViewChangedEvent(this, ref new RoutedEventArgs()); } } } diff --git a/src/GraphControl/Control/Grapher.h b/src/GraphControl/Control/Grapher.h index cddec89f..e6cdedf0 100644 --- a/src/GraphControl/Control/Grapher.h +++ b/src/GraphControl/Control/Grapher.h @@ -31,6 +31,8 @@ public event TracingValueChangedEventHandler ^ TracingValueChangedEvent; event PointerValueChangedEventHandler ^ PointerValueChangedEvent; event TracingChangedEventHandler ^ TracingChangedEvent; + event Windows::UI::Xaml::RoutedEventHandler ^ GraphViewChangedEvent; + event Windows::UI::Xaml::RoutedEventHandler ^ GraphPlottedEvent; virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler ^ PropertyChanged; public: