// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // This class provides the concrete implementation for the ICalcDisplay interface // that is declared in the Calculation Manager Library. #include "pch.h" #include "CalculatorDisplay.h" #include "StandardCalculatorViewModel.h" using namespace CalculatorApp; using namespace CalculationManager; using namespace Platform; using namespace std; CalculatorDisplay::CalculatorDisplay() { } void CalculatorDisplay::SetCallback(Platform::WeakReference callbackReference) { m_callbackReference = callbackReference; } void CalculatorDisplay::SetHistoryCallback(Platform::WeakReference callbackReference) { m_historyCallbackReference = callbackReference; } void CalculatorDisplay::SetPrimaryDisplay(_In_ const wstring& displayStringValue, _In_ bool isError) { if (m_callbackReference) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->SetPrimaryDisplay(StringReference(displayStringValue.c_str()), isError); } } } void CalculatorDisplay::SetParenthesisNumber(_In_ unsigned int parenthesisCount) { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->SetParenthesisCount(parenthesisCount); } } } void CalculatorDisplay::OnNoRightParenAdded() { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->OnNoRightParenAdded(); } } } void CalculatorDisplay::SetIsInError(bool isError) { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->IsInError = isError; } } } void CalculatorDisplay::SetExpressionDisplay( _Inout_ std::shared_ptr>> const& tokens, _Inout_ std::shared_ptr>> const& commands) { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->SetExpressionDisplay(tokens, commands); } } } void CalculatorDisplay::SetMemorizedNumbers(_In_ const vector& newMemorizedNumbers) { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->SetMemorizedNumbers(newMemorizedNumbers); } } } void CalculatorDisplay::OnHistoryItemAdded(_In_ unsigned int addedItemIndex) { if (m_historyCallbackReference != nullptr) { if (auto historyVM = m_historyCallbackReference.Resolve()) { historyVM->OnHistoryItemAdded(addedItemIndex); } } } void CalculatorDisplay::MaxDigitsReached() { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->OnMaxDigitsReached(); } } } void CalculatorDisplay::BinaryOperatorReceived() { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->OnBinaryOperatorReceived(); } } } void CalculatorDisplay::MemoryItemChanged(unsigned int indexOfMemory) { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->OnMemoryItemChanged(indexOfMemory); } } } void CalculatorDisplay::InputChanged() { if (m_callbackReference != nullptr) { if (auto calcVM = m_callbackReference.Resolve()) { calcVM->OnInputChanged(); } } }