Modify how we manage Narrator with parenthesis and refactor right parenthesis

This commit is contained in:
Rudy Huyn 2019-03-24 00:02:53 -07:00
commit 0a7a3fa6fe
16 changed files with 77 additions and 103 deletions

View file

@ -83,7 +83,7 @@ void CCalcEngine::ClearTemporaryValues()
m_bError = false; m_bError = false;
} }
void CCalcEngine::ProcessCommand(WPARAM wParam) void CCalcEngine::ProcessCommand(WPARAM wParam, bool useNarrator)
{ {
if (wParam == IDC_SET_RESULT) if (wParam == IDC_SET_RESULT)
{ {
@ -91,10 +91,10 @@ void CCalcEngine::ProcessCommand(WPARAM wParam)
m_bSetCalcState = true; m_bSetCalcState = true;
} }
ProcessCommandWorker(wParam); ProcessCommandWorker(wParam, useNarrator);
} }
void CCalcEngine::ProcessCommandWorker(WPARAM wParam) void CCalcEngine::ProcessCommandWorker(WPARAM wParam, bool useNarrator)
{ {
INT nx, ni; INT nx, ni;
@ -397,7 +397,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
cleared for CENTR */ cleared for CENTR */
if (nullptr != m_pCalcDisplay) if (nullptr != m_pCalcDisplay)
{ {
m_pCalcDisplay->SetParenDisplayText(L""); m_pCalcDisplay->SetParenDisplayText(0, false);
m_pCalcDisplay->SetExpressionDisplay(make_shared<CalculatorVector<pair<wstring, int>>>(), make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>()); m_pCalcDisplay->SetExpressionDisplay(make_shared<CalculatorVector<pair<wstring, int>>>(), make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>());
} }
@ -440,7 +440,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
} }
// automatic closing of all the parenthesis to get a meaningful result as well as ensure data integrity // automatic closing of all the parenthesis to get a meaningful result as well as ensure data integrity
m_nTempCom = m_nLastCom; // Put back this last saved command to the prev state so ) can be handled properly m_nTempCom = m_nLastCom; // Put back this last saved command to the prev state so ) can be handled properly
ProcessCommand(IDC_CLOSEP); ProcessCommand(IDC_CLOSEP, useNarrator);
m_nLastCom = m_nTempCom; // Actually this is IDC_CLOSEP m_nLastCom = m_nTempCom; // Actually this is IDC_CLOSEP
m_nTempCom = (INT)wParam; // put back in the state where last op seen was IDC_CLOSEP, and current op is IDC_EQU m_nTempCom = (INT)wParam; // put back in the state where last op seen was IDC_CLOSEP, and current op is IDC_EQU
} }
@ -632,7 +632,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
// Set the "(=xx" indicator. // Set the "(=xx" indicator.
if (nullptr != m_pCalcDisplay) if (nullptr != m_pCalcDisplay)
{ {
m_pCalcDisplay->SetParenDisplayText(m_openParenCount ? to_wstring(m_openParenCount) : L""); m_pCalcDisplay->SetParenDisplayText(m_openParenCount >= 0 ? (unsigned int)m_openParenCount : 0, useNarrator);
} }
if (!m_bError) if (!m_bError)

View file

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#include "pch.h" #include "pch.h"
@ -111,9 +111,9 @@ namespace CalculationManager
/// Callback from the engine /// Callback from the engine
/// </summary> /// </summary>
/// <param name="parenthesisCount">string containing the parenthesis count</param> /// <param name="parenthesisCount">string containing the parenthesis count</param>
void CalculatorManager::SetParenDisplayText(const wstring& parenthesisCount) void CalculatorManager::SetParenDisplayText(_In_ unsigned int parenthesisCount, bool useNarrator)
{ {
m_displayCallback->SetParenDisplayText(parenthesisCount); m_displayCallback->SetParenDisplayText(parenthesisCount, useNarrator);
} }
/// <summary> /// <summary>
@ -216,7 +216,7 @@ namespace CalculationManager
/// Handle special commands such as mode change and combination of two commands. /// Handle special commands such as mode change and combination of two commands.
/// </summary> /// </summary>
/// <param name="command">Enum Command</command> /// <param name="command">Enum Command</command>
void CalculatorManager::SendCommand(_In_ Command command) void CalculatorManager::SendCommand(_In_ Command command, bool useNarrator)
{ {
// When the expression line is cleared, we save the current state, which includes, // When the expression line is cleared, we save the current state, which includes,
// primary display, memory, and degree mode // primary display, memory, and degree mode
@ -235,7 +235,7 @@ namespace CalculationManager
this->SetProgrammerMode(); this->SetProgrammerMode();
break; break;
default: default:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command), useNarrator);
} }
m_savedCommands.clear(); // Clear the previous command history m_savedCommands.clear(); // Clear the previous command history
@ -263,38 +263,38 @@ namespace CalculationManager
switch (command) switch (command)
{ {
case Command::CommandASIN: case Command::CommandASIN:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandSIN)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandSIN), useNarrator);
break; break;
case Command::CommandACOS: case Command::CommandACOS:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandCOS)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandCOS), useNarrator);
break; break;
case Command::CommandATAN: case Command::CommandATAN:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandTAN)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandTAN), useNarrator);
break; break;
case Command::CommandPOWE: case Command::CommandPOWE:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandLN)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandLN), useNarrator);
break; break;
case Command::CommandASINH: case Command::CommandASINH:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandSINH)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandSINH), useNarrator);
break; break;
case Command::CommandACOSH: case Command::CommandACOSH:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandCOSH)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandCOSH), useNarrator);
break; break;
case Command::CommandATANH: case Command::CommandATANH:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV), useNarrator);
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandTANH)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandTANH), useNarrator);
break; break;
case Command::CommandFE: case Command::CommandFE:
m_isExponentialFormat = !m_isExponentialFormat; m_isExponentialFormat = !m_isExponentialFormat;
[[fallthrough]]; [[fallthrough]];
default: default:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command), useNarrator);
break; break;
} }
} }

View file

@ -94,7 +94,7 @@ namespace CalculationManager
void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) override; void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) override;
void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override; void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override;
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override; void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
void SetParenDisplayText(const std::wstring& parenthesisCount) override; void SetParenDisplayText(_In_ unsigned int parenthesisCount, bool useNarrator=true) override;
void OnNoRightParenAdded() override; void OnNoRightParenAdded() override;
void DisplayPasteError(); void DisplayPasteError();
void MaxDigitsReached() override; void MaxDigitsReached() override;
@ -109,7 +109,7 @@ namespace CalculationManager
void SetStandardMode(); void SetStandardMode();
void SetScientificMode(); void SetScientificMode();
void SetProgrammerMode(); void SetProgrammerMode();
void SendCommand(_In_ Command command); void SendCommand(_In_ Command command, bool useNarrator=true);
std::vector<unsigned char> SerializeCommands(); std::vector<unsigned char> SerializeCommands();
void DeSerializeCommands(_In_ const std::vector<unsigned char>& serializedData); void DeSerializeCommands(_In_ const std::vector<unsigned char>& serializedData);
void SerializeMemory(); void SerializeMemory();

View file

@ -52,7 +52,7 @@ namespace CalculatorUnitTests
class CCalcEngine { class CCalcEngine {
public: public:
CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay *pCalcDisplay, __in_opt std::shared_ptr<IHistoryDisplay> pHistoryDisplay); CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay *pCalcDisplay, __in_opt std::shared_ptr<IHistoryDisplay> pHistoryDisplay);
void ProcessCommand(WPARAM wID); void ProcessCommand(WPARAM wID, bool useNarrator=true);
void DisplayError (DWORD nError); void DisplayError (DWORD nError);
std::unique_ptr<CalcEngine::Rational> PersistedMemObject(); std::unique_ptr<CalcEngine::Rational> PersistedMemObject();
void PersistedMemObject(CalcEngine::Rational const& memObject); void PersistedMemObject(CalcEngine::Rational const& memObject);
@ -127,7 +127,7 @@ private:
wchar_t m_groupSeparator; wchar_t m_groupSeparator;
private: private:
void ProcessCommandWorker(WPARAM wParam); void ProcessCommandWorker(WPARAM wParam, bool useNarrator = true);
void HandleErrorCommand(WPARAM idc); void HandleErrorCommand(WPARAM idc);
void HandleMaxDigitsReached(); void HandleMaxDigitsReached();
void DisplayNum(void); void DisplayNum(void);

View file

@ -12,7 +12,7 @@ public:
virtual void SetPrimaryDisplay(const std::wstring& pszText, bool isError) = 0; virtual void SetPrimaryDisplay(const std::wstring& pszText, bool isError) = 0;
virtual void SetIsInError(bool isInError) = 0; virtual void SetIsInError(bool isInError) = 0;
virtual void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) = 0; virtual void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) = 0;
virtual void SetParenDisplayText(const std::wstring& pszText) = 0; virtual void SetParenDisplayText(_In_ unsigned int count, _In_ bool useNarrator) = 0;
virtual void OnNoRightParenAdded() = 0; virtual void OnNoRightParenAdded() = 0;
virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer. virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer.
virtual void BinaryOperatorReceived() = 0; virtual void BinaryOperatorReceived() = 0;

View file

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
// Implementation of the NarratorNotifier class. // Implementation of the NarratorNotifier class.
@ -6,7 +6,7 @@
#include "pch.h" #include "pch.h"
#include "NarratorNotifier.h" #include "NarratorNotifier.h"
#include "NarratorAnnouncementHostFactory.h" #include "NarratorAnnouncementHostFactory.h"
#include <iostream>
using namespace CalculatorApp::Common::Automation; using namespace CalculatorApp::Common::Automation;
using namespace Platform; using namespace Platform;
using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml;
@ -26,6 +26,7 @@ void NarratorNotifier::Announce(NarratorAnnouncement^ announcement)
&& m_announcementHost != nullptr) && m_announcementHost != nullptr)
{ {
m_announcementHost->Announce(announcement); m_announcementHost->Announce(announcement);
OutputDebugString(announcement->Announcement->Data());
} }
} }

View file

@ -36,13 +36,13 @@ void CalculatorDisplay::SetPrimaryDisplay(_In_ const wstring& displayStringValue
} }
} }
void CalculatorDisplay::SetParenDisplayText(_In_ const std::wstring& parenthesisCount) void CalculatorDisplay::SetParenDisplayText(_In_ unsigned int parenthesisCount, _In_ bool useNarrator)
{ {
if (m_callbackReference != nullptr) if (m_callbackReference != nullptr)
{ {
if (auto calcVM = m_callbackReference.Resolve<ViewModel::StandardCalculatorViewModel>()) if (auto calcVM = m_callbackReference.Resolve<ViewModel::StandardCalculatorViewModel>())
{ {
calcVM->SetParenthesisCount(parenthesisCount); calcVM->SetParenthesisCount(parenthesisCount, useNarrator);
} }
} }
} }

View file

@ -21,7 +21,7 @@ namespace CalculatorApp
void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) override; void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) override;
void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override; void SetMemorizedNumbers(_In_ const std::vector<std::wstring>& memorizedNumbers) override;
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override; void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
void SetParenDisplayText(_In_ const std::wstring& parenthesisCount) override; void SetParenDisplayText(_In_ unsigned int parenthesisCount, _In_ bool useNarrator=true) override;
void OnNoRightParenAdded() override; void OnNoRightParenAdded() override;
void MaxDigitsReached() override; void MaxDigitsReached() override;
void BinaryOperatorReceived() override; void BinaryOperatorReceived() override;

View file

@ -91,7 +91,8 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() :
m_localizedMemoryItemClearedAutomationFormat(nullptr), m_localizedMemoryItemClearedAutomationFormat(nullptr),
m_localizedMemoryCleared(nullptr), m_localizedMemoryCleared(nullptr),
m_localizedOpenParenthesisCountChangedAutomationFormat(nullptr), m_localizedOpenParenthesisCountChangedAutomationFormat(nullptr),
m_localizedNoRightParenthesisAddedFormat(nullptr) m_localizedNoRightParenthesisAddedFormat(nullptr),
m_parenthesisCount(0)
{ {
WeakReference calculatorViewModel(this); WeakReference calculatorViewModel(this);
m_calculatorDisplay.SetCallback(calculatorViewModel); m_calculatorDisplay.SetCallback(calculatorViewModel);
@ -216,13 +217,19 @@ void StandardCalculatorViewModel::DisplayPasteError()
m_standardCalculatorManager.DisplayPasteError(); m_standardCalculatorManager.DisplayPasteError();
} }
void StandardCalculatorViewModel::SetParenthesisCount(_In_ const wstring& parenthesisCount) void StandardCalculatorViewModel::SetParenthesisCount(_In_ unsigned int parenthesisCount, _In_ bool useNarrator)
{ {
if (IsProgrammer || IsScientific) if (IsProgrammer || IsScientific)
{ {
OpenParenthesisCount = ref new String(parenthesisCount.c_str()); OpenParenthesisCount = ref new String(parenthesisCount == 0 ? L"" : to_wstring(parenthesisCount).c_str());
RaisePropertyChanged("LeftParenthesisAutomationName"); RaisePropertyChanged("LeftParenthesisAutomationName");
if (useNarrator && m_parenthesisCount > parenthesisCount)
{
//only narrate the number of parenthesis when the counter decreases.
SetOpenParenthesisCountNarratorAnnouncement();
}
} }
m_parenthesisCount = parenthesisCount;
} }
void StandardCalculatorViewModel::SetOpenParenthesisCountNarratorAnnouncement() void StandardCalculatorViewModel::SetOpenParenthesisCountNarratorAnnouncement()
@ -859,7 +866,7 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
{ {
sentEquals = (mappedNumOp == NumbersAndOperatorsEnum::Equals); sentEquals = (mappedNumOp == NumbersAndOperatorsEnum::Equals);
Command cmdenum = ConvertToOperatorsEnum(mappedNumOp); Command cmdenum = ConvertToOperatorsEnum(mappedNumOp);
m_standardCalculatorManager.SendCommand(cmdenum); m_standardCalculatorManager.SendCommand(cmdenum, false);
// The CalcEngine state machine won't allow the negate command to be sent before any // The CalcEngine state machine won't allow the negate command to be sent before any
// other digits, so instead a flag is set and the command is sent after the first appropriate // other digits, so instead a flag is set and the command is sent after the first appropriate
@ -869,7 +876,7 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
if (canSendNegate) if (canSendNegate)
{ {
Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate); Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate);
m_standardCalculatorManager.SendCommand(cmdNegate); m_standardCalculatorManager.SendCommand(cmdNegate, false);
} }
// Can't send negate on a leading zero, so wait until the appropriate time to send it. // Can't send negate on a leading zero, so wait until the appropriate time to send it.
@ -888,7 +895,7 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
if (!(MapCharacterToButtonId(*it, canSendNegate) == NumbersAndOperatorsEnum::Add)) if (!(MapCharacterToButtonId(*it, canSendNegate) == NumbersAndOperatorsEnum::Add))
{ {
Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate); Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate);
m_standardCalculatorManager.SendCommand(cmdNegate); m_standardCalculatorManager.SendCommand(cmdNegate, false);
} }
} }
@ -1422,29 +1429,29 @@ void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosit
switch (nOpCode) switch (nOpCode)
{ {
case static_cast<int>(Command::CommandASIN) : case static_cast<int>(Command::CommandASIN) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandSIN), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandSIN), true, angleType);
break; break;
case static_cast<int>(Command::CommandACOS) : case static_cast<int>(Command::CommandACOS) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandCOS), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandCOS), true, angleType);
break; break;
case static_cast<int>(Command::CommandATAN) : case static_cast<int>(Command::CommandATAN) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandTAN), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandTAN), true, angleType);
break; break;
case static_cast<int>(Command::CommandASINH) : case static_cast<int>(Command::CommandASINH) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandSINH), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandSINH), true, angleType);
break; break;
case static_cast<int>(Command::CommandACOSH) : case static_cast<int>(Command::CommandACOSH) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandCOSH), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandCOSH), true, angleType);
break; break;
case static_cast<int>(Command::CommandATANH) : case static_cast<int>(Command::CommandATANH) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandTANH), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandTANH), true, angleType);
break; break;
case static_cast<int>(Command::CommandPOWE) : case static_cast<int>(Command::CommandPOWE) :
updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandLN), true, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(static_cast<int>(Command::CommandLN), true, angleType);
break; break;
default: default:
updatedToken = CCalcEngine::OpCodeToUnaryString(nOpCode, false, angleType); updatedToken = CCalcEngine::OpCodeToUnaryString(nOpCode, false, angleType);
} }
if ((token.first.length() > 0) && (token.first[token.first.length() - 1] == L'(')) if ((token.first.length() > 0) && (token.first[token.first.length() - 1] == L'('))
{ {

View file

@ -283,7 +283,7 @@ namespace CalculatorApp
void SetTokens(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens); void SetTokens(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens);
void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands); void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands);
void SetHistoryExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector <std::shared_ptr<IExpressionCommand>>> const &commands); void SetHistoryExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector <std::shared_ptr<IExpressionCommand>>> const &commands);
void SetParenthesisCount(_In_ const std::wstring& parenthesisCount); void SetParenthesisCount(_In_ unsigned int parenthesisCount, _In_ bool useNarrator=true);
void SetOpenParenthesisCountNarratorAnnouncement(); void SetOpenParenthesisCountNarratorAnnouncement();
void OnNoRightParenAdded(); void OnNoRightParenAdded();
void SetNoParenAddedNarratorAnnouncement(); void SetNoParenAddedNarratorAnnouncement();
@ -352,6 +352,7 @@ namespace CalculatorApp
bool m_operandUpdated; bool m_operandUpdated;
bool m_completeTextSelection; bool m_completeTextSelection;
bool m_isLastOperationHistoryLoad; bool m_isLastOperationHistoryLoad;
unsigned int m_parenthesisCount;
Platform::String^ m_selectedExpressionLastData; Platform::String^ m_selectedExpressionLastData;
Common::DisplayExpressionToken^ m_selectedExpressionToken; Common::DisplayExpressionToken^ m_selectedExpressionToken;
Platform::String^ m_leftParenthesisAutomationFormat; Platform::String^ m_leftParenthesisAutomationFormat;

View file

@ -35,12 +35,10 @@ CalculatorProgrammerRadixOperators::CalculatorProgrammerRadixOperators() :
void CalculatorProgrammerRadixOperators::OnLoaded(Object^, RoutedEventArgs^) void CalculatorProgrammerRadixOperators::OnLoaded(Object^, RoutedEventArgs^)
{ {
m_progModeRadixChangeToken = Model->ProgModeRadixChange += ref new ProgModeRadixChangeHandler(this, &CalculatorProgrammerRadixOperators::ProgModeRadixChange); m_progModeRadixChangeToken = Model->ProgModeRadixChange += ref new ProgModeRadixChangeHandler(this, &CalculatorProgrammerRadixOperators::ProgModeRadixChange);
m_propertyChangedToken = Model->PropertyChanged += ref new PropertyChangedEventHandler(this, &CalculatorProgrammerRadixOperators::OnViewModelPropertyChanged);
} }
void CalculatorProgrammerRadixOperators::OnUnloaded(Object^, RoutedEventArgs^) void CalculatorProgrammerRadixOperators::OnUnloaded(Object^, RoutedEventArgs^)
{ {
Model->ProgModeRadixChange -= m_progModeRadixChangeToken; Model->ProgModeRadixChange -= m_progModeRadixChangeToken;
Model->PropertyChanged -= m_propertyChangedToken;
} }
void CalculatorProgrammerRadixOperators::Shift_Clicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) void CalculatorProgrammerRadixOperators::Shift_Clicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
@ -99,11 +97,3 @@ void CalculatorProgrammerRadixOperators::IsErrorVisualState::set(bool value)
NumberPad->IsErrorVisualState = m_isErrorVisualState; NumberPad->IsErrorVisualState = m_isErrorVisualState;
} }
} }
void CalculatorProgrammerRadixOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e)
{
if (e->PropertyName == StandardCalculatorViewModel::OpenParenthesisCountPropertyName && closeParenthesisButton->FocusState != ::FocusState::Unfocused)
{
Model->SetOpenParenthesisCountNarratorAnnouncement();
}
}

View file

@ -35,10 +35,8 @@ namespace CalculatorApp
void OnLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void OnLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnUnloaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void OnUnloaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ProgModeRadixChange(); void ProgModeRadixChange();
void OnViewModelPropertyChanged(Platform::Object^ sender, Windows::UI::Xaml::Data::PropertyChangedEventArgs ^ e);
bool m_isErrorVisualState; bool m_isErrorVisualState;
Windows::Foundation::EventRegistrationToken m_progModeRadixChangeToken; Windows::Foundation::EventRegistrationToken m_progModeRadixChangeToken;
Windows::Foundation::EventRegistrationToken m_propertyChangedToken;
}; };
} }

View file

@ -11,8 +11,6 @@
x:Name="ControlRoot" x:Name="ControlRoot"
d:DesignHeight="400" d:DesignHeight="400"
d:DesignWidth="315" d:DesignWidth="315"
Loaded="OnLoaded"
Unloaded="OnUnloaded"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<converters:BooleanNegationConverter x:Key="BooleanNegationConverter"/> <converters:BooleanNegationConverter x:Key="BooleanNegationConverter"/>

View file

@ -38,15 +38,6 @@ CalculatorScientificOperators::CalculatorScientificOperators()
Common::KeyboardShortcutManager::ShiftButtonChecked(false); Common::KeyboardShortcutManager::ShiftButtonChecked(false);
} }
void CalculatorScientificOperators::OnLoaded(Object^, RoutedEventArgs^)
{
m_propertyChangedToken = Model->PropertyChanged += ref new PropertyChangedEventHandler(this, &CalculatorScientificOperators::OnViewModelPropertyChanged);
}
void CalculatorScientificOperators::OnUnloaded(Object^, RoutedEventArgs^)
{
Model->PropertyChanged -= m_propertyChangedToken;
}
void CalculatorScientificOperators::ShortLayout_Completed(_In_ Platform::Object^ /*sender*/, _In_ Platform::Object^ /*e*/) void CalculatorScientificOperators::ShortLayout_Completed(_In_ Platform::Object^ /*sender*/, _In_ Platform::Object^ /*e*/)
{ {
IsWideLayout = false; IsWideLayout = false;
@ -107,10 +98,3 @@ void CalculatorScientificOperators::SetOperatorRowVisibility()
InvRow2->Visibility = invRowVis; InvRow2->Visibility = invRowVis;
} }
void CalculatorScientificOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e)
{
if (e->PropertyName == StandardCalculatorViewModel::OpenParenthesisCountPropertyName && closeParenthesisButton->FocusState != ::FocusState::Unfocused)
{
Model->SetOpenParenthesisCountNarratorAnnouncement();
}
}

View file

@ -41,10 +41,5 @@ namespace CalculatorApp
void shiftButton_Check(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e); void shiftButton_Check(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void shiftButton_IsEnabledChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e); void shiftButton_IsEnabledChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e);
void SetOperatorRowVisibility(); void SetOperatorRowVisibility();
void OnViewModelPropertyChanged(Platform::Object^ sender, Windows::UI::Xaml::Data::PropertyChangedEventArgs ^ e);
void OnLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnUnloaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
Windows::Foundation::EventRegistrationToken m_propertyChangedToken;
}; };
} }

View file

@ -57,7 +57,7 @@ namespace CalculatorManagerTest
m_memorizedNumberStrings = numbers; m_memorizedNumberStrings = numbers;
} }
void SetParenDisplayText(const std::wstring& parenthesisCount) override void SetParenDisplayText(unsigned int parenthesisCount, bool /*useNarrator*/) override
{ {
m_parenDisplay = parenthesisCount; m_parenDisplay = parenthesisCount;
} }
@ -115,7 +115,7 @@ namespace CalculatorManagerTest
private: private:
wstring m_primaryDisplay; wstring m_primaryDisplay;
wstring m_expression; wstring m_expression;
wstring m_parenDisplay; unsigned int m_parenDisplay;
bool m_isError; bool m_isError;
vector<wstring> m_memorizedNumberStrings; vector<wstring> m_memorizedNumberStrings;
int m_maxDigitsCalledCount; int m_maxDigitsCalledCount;