mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-14 17:22:50 -07:00
Hello GitHub
This commit is contained in:
parent
456fe5e355
commit
c13b8a099e
822 changed files with 276650 additions and 75 deletions
65
src/CalcViewModel/HistoryItemViewModel.cpp
Normal file
65
src/CalcViewModel/HistoryItemViewModel.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "HistoryItemViewModel.h"
|
||||
#include "Common\LocalizationService.h"
|
||||
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace std;
|
||||
using namespace Platform;
|
||||
|
||||
|
||||
HistoryItemViewModel::HistoryItemViewModel(String^ expression, String^ result,
|
||||
_In_ const shared_ptr<CalculatorVector <pair<wstring, int>>> &spTokens,
|
||||
_In_ const shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> &spCommands) :m_expression(expression), m_result(result), m_spTokens(spTokens), m_spCommands(spCommands)
|
||||
{
|
||||
// updating accessibility names for expression and result
|
||||
m_accExpression = HistoryItemViewModel::GetAccessibleExpressionFromTokens(spTokens, m_expression);
|
||||
m_accResult = LocalizationService::GetNarratorReadableString(m_result);
|
||||
}
|
||||
|
||||
String^ HistoryItemViewModel::GetAccessibleExpressionFromTokens(_In_ shared_ptr< CalculatorVector< pair< wstring, int > > > const &spTokens, _In_ String^ fallbackExpression)
|
||||
{
|
||||
// updating accessibility names for expression and result
|
||||
wstringstream accExpression{};
|
||||
accExpression << L"";
|
||||
|
||||
unsigned int nTokens;
|
||||
HRESULT hr = spTokens->GetSize(&nTokens);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
pair<wstring, int> tokenItem;
|
||||
for (unsigned int i = 0; i < nTokens; i++)
|
||||
{
|
||||
hr = spTokens->GetAt(i, &tokenItem);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wstring token = tokenItem.first;
|
||||
accExpression << LocalizationService::GetNarratorReadableToken(StringReference(token.c_str()))->Data();
|
||||
}
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
wstring expressionSuffix{};
|
||||
hr = spTokens->GetExpressionSuffix(&expressionSuffix);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
accExpression << expressionSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return LocalizationService::GetNarratorReadableString(fallbackExpression);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ref new String(accExpression.str().c_str());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue