Revert "Replace wstring used in public methods by Platform::String in CalcViewModel (#758)" (#767)

This reverts commit 93f1f784bb.
This commit is contained in:
Rudy Huyn
2019-11-04 17:54:12 -08:00
committed by Matt Cooley
parent 93f1f784bb
commit 049d3f4c6c
35 changed files with 533 additions and 509 deletions

View File

@@ -35,11 +35,11 @@ AboutFlyout::AboutFlyout()
this->SetVersionString();
Header->Text = resourceLoader->GetResourceString("AboutButton/Content");
Header->Text = resourceLoader.GetResourceString("AboutButton/Content");
auto copyrightText =
LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("AboutControlCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
AboutControlCopyrightRun->Text = copyrightText;
LocalizationStringUtil::GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright")->Data(), to_wstring(BUILD_YEAR).c_str());
AboutControlCopyrightRun->Text = ref new String(copyrightText.c_str());
}
void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
@@ -53,7 +53,7 @@ void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArg
void AboutFlyout::SetVersionString()
{
PackageVersion version = Package::Current->Id->Version;
String ^ appName = AppResourceProvider::GetInstance()->GetResourceString(L"AppName");
String ^ appName = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
AboutFlyoutVersion->Text = appName + L" " + version.Major + L"." + version.Minor + L"." + version.Build + L"." + version.Revision;
}

View File

@@ -63,7 +63,11 @@ CalculationResult::CalculationResult()
Platform::String ^ CalculationResult::GetRawDisplayValue()
{
return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue);
std::wstring rawValue;
LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue);
return ref new Platform::String(rawValue.c_str());
}
void CalculationResult::OnApplyTemplate()

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.
#include "pch.h"
@@ -18,6 +18,8 @@ using namespace Windows::UI::Xaml::Data;
String ^ RadixButton::GetRawDisplayValue()
{
wstring rawValue;
String ^ radixContent = Content->ToString();
return LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent);
LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent->Data(), radixContent->Length(), &rawValue);
return ref new String(rawValue.c_str());
}

View File

@@ -28,22 +28,22 @@ namespace CalculatorApp
{
case RADIX_TYPE::BIN_RADIX:
{
convertedValue = resourceLoader->GetResourceString("Bin");
convertedValue = resourceLoader.GetResourceString("Bin");
break;
}
case RADIX_TYPE::OCT_RADIX:
{
convertedValue = resourceLoader->GetResourceString("Oct");
convertedValue = resourceLoader.GetResourceString("Oct");
break;
}
case RADIX_TYPE::DEC_RADIX:
{
convertedValue = resourceLoader->GetResourceString("Dec");
convertedValue = resourceLoader.GetResourceString("Dec");
break;
}
case RADIX_TYPE::HEX_RADIX:
{
convertedValue = resourceLoader->GetResourceString("Hex");
convertedValue = resourceLoader.GetResourceString("Hex");
break;
}
default:

View File

@@ -59,8 +59,8 @@ Calculator::Calculator()
m_displayFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"DisplayContextMenu"));
auto resLoader = AppResourceProvider::GetInstance();
CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem");
PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem");
CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem");
PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem");
this->SizeChanged += ref new SizeChangedEventHandler(this, &Calculator::Calculator_SizeChanged);
}
@@ -68,10 +68,10 @@ Calculator::Calculator()
void Calculator::LoadResourceStrings()
{
auto resProvider = AppResourceProvider::GetInstance();
m_openMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Open");
m_closeMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Close");
m_openHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Open");
m_closeHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Close");
m_openMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Open");
m_closeMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Close");
m_openHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Open");
m_closeHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Close");
AutomationProperties::SetName(MemoryButton, m_openMemoryFlyoutAutomationName);
AutomationProperties::SetName(HistoryButton, m_openHistoryFlyoutAutomationName);
}
@@ -123,9 +123,9 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
Model->HideMemoryClicked += ref new HideMemoryClickedHandler(this, &Calculator::OnHideMemoryClicked);
InitializeHistoryView(Model->HistoryVM);
String ^ historyPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"HistoryPane");
String ^ historyPaneName = AppResourceProvider::GetInstance().GetResourceString(L"HistoryPane");
HistoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, historyPaneName));
String ^ memoryPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"MemoryPane");
String ^ memoryPaneName = AppResourceProvider::GetInstance().GetResourceString(L"MemoryPane");
MemoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, memoryPaneName));
if (Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Controls.Primitives.FlyoutBase", L"Closing"))
@@ -149,21 +149,24 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
}));
}
Platform::String ^ Calculator::GetCurrentLayoutState()
std::wstring Calculator::GetCurrentLayoutState()
{
std::wstring state;
if (IsProgrammer)
{
return L"Programmer";
state = L"Programmer";
}
else if (IsScientific)
{
return L"Scientific";
state = L"Scientific";
}
else
{
return L"Standard";
state = L"Standard";
}
return state;
}
void Calculator::UpdateViewState()
@@ -476,7 +479,7 @@ void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel ^ e)
assert(e->GetTokens() != nullptr);
Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands());
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
Model->SetPrimaryDisplay(e->Result, false);
Model->SetPrimaryDisplay(e->Result->Data(), false);
Model->IsFToEEnabled = false;
CloseHistoryFlyout();
@@ -613,7 +616,7 @@ Memory ^ Calculator::GetMemory()
if (m_memory == nullptr)
{
m_memory = ref new Memory();
VisualStateManager::GoToState(m_memory, GetCurrentLayoutState(), true /*useTransitions*/);
VisualStateManager::GoToState(m_memory, ref new String(GetCurrentLayoutState().c_str()), true /*useTransitions*/);
}
return m_memory;
@@ -669,6 +672,28 @@ void Calculator::OnHistoryFlyOutTapped(_In_ Object ^ sender, _In_ TappedRoutedEv
}
}
bool Calculator::IsValidRegularExpression(std::wstring str)
{
bool result = false;
std::wregex regexPatterns[3];
regexPatterns[0] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}";
regexPatterns[1] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[+]{1}[0-9]{1,}";
regexPatterns[2] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[-]{1}[0-9]{1,}";
const auto& localizer = LocalizationSettings::GetInstance();
String ^ englishString = localizer.GetEnglishValueFromLocalizedDigits(str);
for (int i = 0; i < 3; ++i)
{
if (regex_match(englishString->Data(), regexPatterns[i]))
{
result = true;
break;
}
}
return result;
}
void Calculator::DockPanelTapped(_In_ TappedRoutedEventArgs ^ e)
{
int index = DockPivot->SelectedIndex;

View File

@@ -94,7 +94,7 @@ public
void EnsureScientific();
void EnsureProgrammer();
void SetFontSizeResources();
Platform::String ^ GetCurrentLayoutState();
std::wstring GetCurrentLayoutState();
void Calculator_SizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
private:
@@ -140,6 +140,7 @@ public
void EnableMemoryControls(bool enable);
void OnMemoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
void OnHistoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
bool IsValidRegularExpression(std::wstring str);
void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
void OnHistoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args);
void OnMemoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args);

View File

@@ -247,11 +247,11 @@ int CalculatorProgrammerBitFlipPanel::GetIndexOfLastBit(BitLength length) const
String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value)
{
auto resourceLoader = AppResourceProvider::GetInstance();
String ^ automationNameTemplate = resourceLoader->GetResourceString(L"BitFlipItemAutomationName");
String ^ bitPosition;
String ^ automationNameTemplate = resourceLoader.GetResourceString(L"BitFlipItemAutomationName");
wstring bitPosition;
if (position == 0)
{
bitPosition = resourceLoader->GetResourceString(L"LeastSignificantBit");
bitPosition = wstring(resourceLoader.GetResourceString(L"LeastSignificantBit")->Data());
}
else
{
@@ -263,14 +263,14 @@ String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int
if (position == lastPosition)
{
bitPosition = resourceLoader->GetResourceString(L"MostSignificantBit");
bitPosition = wstring(resourceLoader.GetResourceString(L"MostSignificantBit")->Data());
}
else
{
String ^ indexName = resourceLoader->GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
String ^ bitPositionTemplate = resourceLoader->GetResourceString(L"BitPosition");
bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate, indexName);
String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition");
bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data());
}
}
return LocalizationStringUtil::GetLocalizedString(automationNameTemplate, bitPosition, value ? L"1" : L"0");
return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str());
}

View File

@@ -33,7 +33,7 @@ CalculatorProgrammerOperators::CalculatorProgrammerOperators()
{
InitializeComponent();
CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem");
CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem");
}
void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)

View File

@@ -92,7 +92,7 @@ DateCalculator::DateCalculator()
DateDiff_FromDate->PlaceholderText = placeholderText;
DateDiff_ToDate->PlaceholderText = placeholderText;
CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem");
CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem");
m_dateCalcOptionChangedEventToken = DateCalculationOption->SelectionChanged +=
ref new SelectionChangedEventHandler(this, &DateCalculator::DateCalcOption_Changed);
}

View File

@@ -10,7 +10,6 @@
#include "CalcViewModel/Common/AppResourceProvider.h"
#include "Views/Memory.xaml.h"
#include "Converters/BooleanToVisibilityConverter.h"
#include "CalcViewModel/Common/LocalizationStringUtil.h"
#include "Common/AppLifecycleLogger.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
@@ -511,20 +510,25 @@ void MainPage::SetHeaderAutomationName()
String ^ name;
if (NavCategory::IsDateCalculatorViewMode(mode))
{
name = resProvider->GetResourceString(L"HeaderAutomationName_Date");
name = resProvider.GetResourceString(L"HeaderAutomationName_Date");
}
else
{
String ^ full;
wstring full;
if (NavCategory::IsCalculatorViewMode(mode))
{
full = resProvider->GetResourceString(L"HeaderAutomationName_Calculator");
full = resProvider.GetResourceString(L"HeaderAutomationName_Calculator")->Data();
}
else if (NavCategory::IsConverterViewMode(mode))
{
full = resProvider->GetResourceString(L"HeaderAutomationName_Converter");
full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data();
}
name = LocalizationStringUtil::GetLocalizedString(full, m_model->CategoryName);
string::size_type found = full.find(L"%1");
wstring strMode = m_model->CategoryName->Data();
full = full.replace(found, 2, strMode);
name = ref new String(full.c_str());
}
AutomationProperties::SetName(Header, name);

View File

@@ -37,9 +37,9 @@ namespace CalculatorApp
Loaded += ref new RoutedEventHandler(this, &TitleBar::OnLoaded);
Unloaded += ref new RoutedEventHandler(this, &TitleBar::OnUnloaded);
#ifdef IS_STORE_BUILD
AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"AppName");
AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
#else
AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"DevAppName");
AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"DevAppName");
#endif // IS_STORE_BUILD
}

View File

@@ -40,6 +40,8 @@ using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::ViewManagement;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
// Calculate number of 100-nanosecond intervals in 500 milliseconds.
// There are 10,000 intervals in 1 ms.
static const long long DURATION_500_MS = 10000 * 500;
@@ -64,14 +66,14 @@ UnitConverter::UnitConverter()
m_isAnimationEnabled = userSettings->AnimationsEnabled;
auto resLoader = AppResourceProvider::GetInstance();
m_chargesMayApplyText = resLoader->GetResourceString(L"DataChargesMayApply");
m_failedToRefreshText = resLoader->GetResourceString(L"FailedToRefresh");
m_chargesMayApplyText = resLoader.GetResourceString(L"DataChargesMayApply");
m_failedToRefreshText = resLoader.GetResourceString(L"FailedToRefresh");
InitializeOfflineStatusTextBlock();
m_resultsFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"CalculationResultContextMenu"));
CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem");
PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem");
CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem");
PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem");
}
void UnitConverter::OnPropertyChanged(_In_ Object ^ sender, _In_ PropertyChangedEventArgs ^ e)
@@ -163,7 +165,7 @@ void UnitConverter::SetFailedToRefreshStatus()
void UnitConverter::InitializeOfflineStatusTextBlock()
{
auto resProvider = AppResourceProvider::GetInstance();
std::wstring offlineStatusHyperlinkText = resProvider->GetResourceString(L"OfflineStatusHyperlinkText")->Data();
std::wstring offlineStatusHyperlinkText = static_cast<String ^>(resProvider.GetResourceString(L"OfflineStatusHyperlinkText"))->Data();
// The resource string has the 'NetworkSettings' hyperlink wrapped with '%HL%'.
// Break the string and assign pieces appropriately.
@@ -243,9 +245,9 @@ void UnitConverter::OnCopyMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEvent
void UnitConverter::OnPasteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
{
auto that(this);
create_task(CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown))
.then([that](String ^ pastedString) { that->Model->OnPaste(pastedString); });
CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter).then([this](String ^ pastedString) {
Model->OnPaste(pastedString);
});
}
void UnitConverter::AnimateConverter()