Merge master into feature/GraphingCalculator branch (#660)

This commit is contained in:
Pepe Rivera
2019-09-05 15:01:12 -07:00
committed by GitHub
parent 1c9755d38a
commit 41fbcfe9c5
199 changed files with 5809 additions and 2925 deletions

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"
@@ -31,6 +31,8 @@ using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::Foundation;
using namespace Concurrency;
namespace
{
@@ -38,14 +40,14 @@ namespace
StringReference ClearMemoryVisibilityPropertyName(L"ClearMemoryVisibility");
}
ApplicationViewModel::ApplicationViewModel() :
m_CalculatorViewModel(nullptr),
m_DateCalcViewModel(nullptr),
m_GraphingCalcViewModel(nullptr),
m_ConverterViewModel(nullptr),
m_PreviousMode(ViewMode::None),
m_mode(ViewMode::None),
m_categories(nullptr)
ApplicationViewModel::ApplicationViewModel()
: m_CalculatorViewModel(nullptr)
, m_DateCalcViewModel(nullptr)
, m_GraphingCalcViewModel(nullptr)
, m_ConverterViewModel(nullptr)
, m_PreviousMode(ViewMode::None)
, m_mode(ViewMode::None)
, m_categories(nullptr)
{
SetMenuCategories();
}
@@ -56,6 +58,7 @@ void ApplicationViewModel::Mode::set(ViewMode value)
{
PreviousMode = m_mode;
m_mode = value;
SetDisplayNormalAlwaysOnTopOption();
OnModeChanged();
RaisePropertyChanged(ModePropertyName);
}
@@ -83,7 +86,7 @@ void ApplicationViewModel::Initialize(ViewMode mode)
}
catch (const std::exception& e)
{
TraceLogger::GetInstance().LogStandardException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogStandardException(mode, __FUNCTIONW__, e);
if (!TryRecoverFromNavigationModeFailure())
{
// Could not navigate to standard mode either.
@@ -93,7 +96,7 @@ void ApplicationViewModel::Initialize(ViewMode mode)
}
catch (Exception ^ e)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogPlatformException(mode, __FUNCTIONW__, e);
if (!TryRecoverFromNavigationModeFailure())
{
// Could not navigate to standard mode either.
@@ -122,10 +125,8 @@ bool ApplicationViewModel::TryRecoverFromNavigationModeFailure()
void ApplicationViewModel::OnModeChanged()
{
assert(NavCategory::IsValidViewMode(m_mode));
TraceLogger::GetInstance().LogModeChangeBegin(m_PreviousMode, m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (NavCategory::IsCalculatorViewMode(m_mode))
{
TraceLogger::GetInstance().LogCalculatorModeViewed(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (!m_CalculatorViewModel)
{
m_CalculatorViewModel = ref new StandardCalculatorViewModel();
@@ -141,7 +142,6 @@ void ApplicationViewModel::OnModeChanged()
}
else if (NavCategory::IsDateCalculatorViewMode(m_mode))
{
TraceLogger::GetInstance().LogDateCalculatorModeViewed(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (!m_DateCalcViewModel)
{
m_DateCalcViewModel = ref new DateCalculatorViewModel();
@@ -149,7 +149,6 @@ void ApplicationViewModel::OnModeChanged()
}
else if (NavCategory::IsConverterViewMode(m_mode))
{
TraceLogger::GetInstance().LogConverterModeViewed(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (!m_ConverterViewModel)
{
auto dataLoader = make_shared<UnitConverterDataLoader>(ref new GeographicRegion());
@@ -163,13 +162,21 @@ void ApplicationViewModel::OnModeChanged()
auto resProvider = AppResourceProvider::GetInstance();
CategoryName = resProvider.GetResourceString(NavCategory::GetNameResourceKey(m_mode));
// This is the only place where a ViewMode enum should be cast to an int.
//
// Cast mode to an int in order to save it to app data.
// Save the changed mode, so that the new window launches in this mode.
// Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load.
ApplicationData::Current->LocalSettings->Values->Insert(ModePropertyName, NavCategory::Serialize(m_mode));
TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
// Log ModeChange event when not first launch, log WindowCreated on first launch
if (NavCategory::IsValidViewMode(m_PreviousMode))
{
TraceLogger::GetInstance().LogModeChange(m_mode);
}
else
{
TraceLogger::GetInstance().LogWindowCreated(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
}
RaisePropertyChanged(ClearMemoryVisibilityPropertyName);
}
@@ -208,3 +215,62 @@ void ApplicationViewModel::SetMenuCategories()
// property setter logic.
Categories = NavCategoryGroup::CreateMenuOptions();
}
void ApplicationViewModel::ToggleAlwaysOnTop(float width, float height)
{
HandleToggleAlwaysOnTop(width, height);
}
#pragma optimize("", off)
task<void> ApplicationViewModel::HandleToggleAlwaysOnTop(float width, float height)
{
if (ApplicationView::GetForCurrentView()->ViewMode == ApplicationViewMode::CompactOverlay)
{
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
localSettings->Values->Insert(WidthLocalSettings, width);
localSettings->Values->Insert(HeightLocalSettings, height);
bool success = co_await ApplicationView::GetForCurrentView()->TryEnterViewModeAsync(ApplicationViewMode::Default);
CalculatorViewModel->AreHistoryShortcutsEnabled = success;
CalculatorViewModel->HistoryVM->AreHistoryShortcutsEnabled = success;
CalculatorViewModel->IsAlwaysOnTop = !success;
IsAlwaysOnTop = !success;
}
else
{
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
ViewModePreferences ^ compactOptions = ViewModePreferences::CreateDefault(ApplicationViewMode::CompactOverlay);
if (!localSettings->Values->GetView()->HasKey(LaunchedLocalSettings))
{
compactOptions->CustomSize = Size(320, 394);
localSettings->Values->Insert(LaunchedLocalSettings, true);
}
else
{
if (localSettings->Values->GetView()->HasKey(WidthLocalSettings) && localSettings->Values->GetView()->HasKey(HeightLocalSettings))
{
float oldWidth = safe_cast<IPropertyValue ^>(localSettings->Values->GetView()->Lookup(WidthLocalSettings))->GetSingle();
float oldHeight = safe_cast<IPropertyValue ^>(localSettings->Values->GetView()->Lookup(HeightLocalSettings))->GetSingle();
compactOptions->CustomSize = Size(oldWidth, oldHeight);
}
else
{
compactOptions->CustomSize = Size(320, 394);
}
}
bool success = co_await ApplicationView::GetForCurrentView()->TryEnterViewModeAsync(ApplicationViewMode::CompactOverlay, compactOptions);
CalculatorViewModel->AreHistoryShortcutsEnabled = !success;
CalculatorViewModel->HistoryVM->AreHistoryShortcutsEnabled = !success;
CalculatorViewModel->IsAlwaysOnTop = success;
IsAlwaysOnTop = success;
}
SetDisplayNormalAlwaysOnTopOption();
};
#pragma optimize("", on)
void ApplicationViewModel::SetDisplayNormalAlwaysOnTopOption()
{
DisplayNormalAlwaysOnTopOption =
m_mode == ViewMode::Standard && ApplicationView::GetForCurrentView()->IsViewModeSupported(ApplicationViewMode::CompactOverlay) && !IsAlwaysOnTop;
}

View File

@@ -20,13 +20,17 @@ namespace CalculatorApp
void Initialize(CalculatorApp::Common::ViewMode mode); // Use for first init, use deserialize for rehydration
OBSERVABLE_OBJECT();
OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel^, CalculatorViewModel);
OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel^, DateCalcViewModel);
OBSERVABLE_PROPERTY_RW(GraphingCalculatorViewModel^, GraphingCalcViewModel);
OBSERVABLE_PROPERTY_RW(UnitConverterViewModel^, ConverterViewModel);
OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel ^, CalculatorViewModel);
OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel ^, DateCalcViewModel);
OBSERVABLE_PROPERTY_RW(GraphingCalculatorViewModel ^, GraphingCalcViewModel);
OBSERVABLE_PROPERTY_RW(UnitConverterViewModel ^, ConverterViewModel);
OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, PreviousMode);
OBSERVABLE_PROPERTY_R(bool, IsAlwaysOnTop);
OBSERVABLE_NAMED_PROPERTY_RW(Platform::String ^, CategoryName);
// Indicates whether calculator is currently in standard mode _and_ supports CompactOverlay _and_ is not in Always-on-Top mode
OBSERVABLE_PROPERTY_R(bool, DisplayNormalAlwaysOnTopOption);
COMMAND_FOR_METHOD(CopyCommand, ApplicationViewModel::OnCopyCommand);
COMMAND_FOR_METHOD(PasteCommand, ApplicationViewModel::OnPasteCommand);
@@ -66,6 +70,32 @@ namespace CalculatorApp
}
}
static property Platform::String ^ LaunchedLocalSettings
{
Platform::String ^ get()
{
return Platform::StringReference(L"calculatorAlwaysOnTopLaunched");
}
}
static property Platform::String ^ WidthLocalSettings
{
Platform::String ^ get()
{
return Platform::StringReference(L"calculatorAlwaysOnTopLastWidth");
}
}
static property Platform::String ^ HeightLocalSettings
{
Platform::String ^ get()
{
return Platform::StringReference(L"calculatorAlwaysOnTopLastHeight");
}
}
void ToggleAlwaysOnTop(float width, float height);
private:
bool TryRecoverFromNavigationModeFailure();
@@ -78,6 +108,8 @@ namespace CalculatorApp
CalculatorApp::Common::ViewMode m_mode;
Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup ^> ^ m_categories;
Concurrency::task<void> HandleToggleAlwaysOnTop(float width, float height);
void SetDisplayNormalAlwaysOnTopOption();
};
}
}

View File

@@ -42,8 +42,8 @@
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.18362.0</WindowsTargetPlatformMinVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -308,7 +308,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(IsStoreBuild)' == 'True'">
<ClCompile>
<AdditionalOptions>/DSEND_TELEMETRY %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>/DSEND_DIAGNOSTICS %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
@@ -322,6 +322,7 @@
<ClInclude Include="Common\Automation\NarratorNotifier.h" />
<ClInclude Include="Common\Automation\NotificationHost.h" />
<ClInclude Include="Common\BindableBase.h" />
<ClInclude Include="Common\BitLength.h" />
<ClInclude Include="Common\CalculatorButtonPressedEventArgs.h" />
<ClInclude Include="Common\CalculatorButtonUser.h" />
<ClInclude Include="Common\CalculatorDisplay.h" />

View File

@@ -1,95 +1,247 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Common">
<UniqueIdentifier>{1daab7c4-63f6-4266-a259-f34acad66d09}</UniqueIdentifier>
</Filter>
<Filter Include="Common\Automation">
<UniqueIdentifier>{8d4edf06-c312-4312-978a-b6c2beb8295a}</UniqueIdentifier>
</Filter>
<Filter Include="DataLoaders">
<UniqueIdentifier>{0184f727-b8aa-4af8-a699-63f1b56e7853}</UniqueIdentifier>
</Filter>
<Filter Include="GraphingCalculator">
<UniqueIdentifier>{cf7dca32-9727-4f98-83c3-1c0ca7dd1e0c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
<ClCompile Include="ApplicationViewModel.cpp" />
<ClCompile Include="Common\AppResourceProvider.cpp" />
<ClCompile Include="Common\Automation\LiveRegionHost.cpp" />
<ClCompile Include="Common\Automation\NarratorAnnouncement.cpp" />
<ClCompile Include="Common\Automation\NarratorAnnouncementHostFactory.cpp" />
<ClCompile Include="Common\Automation\NarratorNotifier.cpp" />
<ClCompile Include="Common\Automation\NotificationHost.cpp" />
<ClCompile Include="Common\BindableBase.cpp" />
<ClCompile Include="Common\CalculatorButtonPressedEventArgs.cpp" />
<ClCompile Include="Common\CalculatorDisplay.cpp" />
<ClCompile Include="Common\ConversionResultTaskHelper.cpp" />
<ClCompile Include="Common\CopyPasteManager.cpp" />
<ClCompile Include="Common\DateCalculator.cpp" />
<ClCompile Include="Common\EngineResourceProvider.cpp" />
<ClCompile Include="Common\ExpressionCommandDeserializer.cpp" />
<ClCompile Include="Common\ExpressionCommandSerializer.cpp" />
<ClCompile Include="Common\KeyboardShortcutManager.cpp" />
<ClCompile Include="Common\LocalizationService.cpp" />
<ClCompile Include="Common\NavCategory.cpp" />
<ClCompile Include="Common\NetworkManager.cpp" />
<ClCompile Include="Common\TraceLogger.cpp" />
<ClCompile Include="Common\Utils.cpp" />
<ClCompile Include="DataLoaders\CurrencyDataLoader.cpp" />
<ClCompile Include="DataLoaders\CurrencyHttpClient.cpp" />
<ClCompile Include="DataLoaders\UnitConverterDataLoader.cpp" />
<ClCompile Include="DateCalculatorViewModel.cpp" />
<ClCompile Include="GraphingCalculator\EquationViewModel.cpp" />
<ClCompile Include="GraphingCalculator\GraphingCalculatorViewModel.cpp" />
<ClCompile Include="HistoryItemViewModel.cpp" />
<ClCompile Include="HistoryViewModel.cpp" />
<ClCompile Include="MemoryItemViewModel.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="StandardCalculatorViewModel.cpp" />
<ClCompile Include="UnitConverterViewModel.cpp" />
<ClCompile Include="ViewState.cpp" />
<ClCompile Include="Common\AppResourceProvider.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\BindableBase.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\CalculatorButtonPressedEventArgs.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\CalculatorDisplay.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\ConversionResultTaskHelper.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\CopyPasteManager.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\DateCalculator.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\EngineResourceProvider.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\ExpressionCommandDeserializer.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\ExpressionCommandSerializer.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\KeyboardShortcutManager.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\LocalizationService.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\NavCategory.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\NetworkManager.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\TraceLogger.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\Utils.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\Automation\LiveRegionHost.cpp">
<Filter>Common\Automation</Filter>
</ClCompile>
<ClCompile Include="Common\Automation\NarratorAnnouncement.cpp">
<Filter>Common\Automation</Filter>
</ClCompile>
<ClCompile Include="Common\Automation\NarratorAnnouncementHostFactory.cpp">
<Filter>Common\Automation</Filter>
</ClCompile>
<ClCompile Include="Common\Automation\NarratorNotifier.cpp">
<Filter>Common\Automation</Filter>
</ClCompile>
<ClCompile Include="Common\Automation\NotificationHost.cpp">
<Filter>Common\Automation</Filter>
</ClCompile>
<ClCompile Include="DataLoaders\CurrencyDataLoader.cpp">
<Filter>DataLoaders</Filter>
</ClCompile>
<ClCompile Include="DataLoaders\CurrencyHttpClient.cpp">
<Filter>DataLoaders</Filter>
</ClCompile>
<ClCompile Include="DataLoaders\UnitConverterDataLoader.cpp">
<Filter>DataLoaders</Filter>
</ClCompile>
<ClCompile Include="GraphingCalculator\EquationViewModel.cpp">
<Filter>GraphingCalculator</Filter>
</ClInclude>
<ClCompile Include="GraphingCalculator\GraphingCalculatorViewModel.cpp">
<Filter>GraphingCalculator</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="ApplicationViewModel.h" />
<ClInclude Include="Common\AlwaysSelectedCollectionView.h" />
<ClInclude Include="Common\AppResourceProvider.h" />
<ClInclude Include="Common\Automation\INarratorAnnouncementHost.h" />
<ClInclude Include="Common\Automation\LiveRegionHost.h" />
<ClInclude Include="Common\Automation\NarratorAnnouncement.h" />
<ClInclude Include="Common\Automation\NarratorAnnouncementHostFactory.h" />
<ClInclude Include="Common\Automation\NarratorNotifier.h" />
<ClInclude Include="Common\Automation\NotificationHost.h" />
<ClInclude Include="Common\BindableBase.h" />
<ClInclude Include="Common\CalculatorButtonPressedEventArgs.h" />
<ClInclude Include="Common\CalculatorButtonUser.h" />
<ClInclude Include="Common\CalculatorDisplay.h" />
<ClInclude Include="Common\ConversionResultTaskHelper.h" />
<ClInclude Include="Common\CopyPasteManager.h" />
<ClInclude Include="Common\DateCalculator.h" />
<ClInclude Include="Common\DelegateCommand.h" />
<ClInclude Include="Common\DisplayExpressionToken.h" />
<ClInclude Include="Common\EngineResourceProvider.h" />
<ClInclude Include="Common\ExpressionCommandDeserializer.h" />
<ClInclude Include="Common\ExpressionCommandSerializer.h" />
<ClInclude Include="Common\KeyboardShortcutManager.h" />
<ClInclude Include="Common\LocalizationService.h" />
<ClInclude Include="Common\LocalizationSettings.h" />
<ClInclude Include="Common\LocalizationStringUtil.h" />
<ClInclude Include="Common\MyVirtualKey.h" />
<ClInclude Include="Common\NavCategory.h" />
<ClInclude Include="Common\NetworkManager.h" />
<ClInclude Include="Common\TraceActivity.h" />
<ClInclude Include="Common\TraceLogger.h" />
<ClInclude Include="Common\Utils.h" />
<ClInclude Include="Common\ValidatingConverters.h" />
<ClInclude Include="DataLoaders\CurrencyDataLoader.h" />
<ClInclude Include="DataLoaders\CurrencyHttpClient.h" />
<ClInclude Include="DataLoaders\ICurrencyHttpClient.h" />
<ClInclude Include="DataLoaders\UnitConverterDataConstants.h" />
<ClInclude Include="DataLoaders\UnitConverterDataLoader.h" />
<ClInclude Include="DateCalculatorViewModel.h" />
<ClInclude Include="GraphingCalculator\EquationViewModel.h" />
<ClInclude Include="GraphingCalculator\GraphingCalculatorViewModel.h" />
<ClInclude Include="HistoryItemViewModel.h" />
<ClInclude Include="HistoryViewModel.h" />
<ClInclude Include="MemoryItemViewModel.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="StandardCalculatorViewModel.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="UnitConverterViewModel.h" />
<ClInclude Include="ViewState.h" />
<ClInclude Include="DataLoaders\DataLoaderMockConstants.h" />
<ClInclude Include="Common\AlwaysSelectedCollectionView.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\AppResourceProvider.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\BindableBase.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\CalculatorButtonPressedEventArgs.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\CalculatorButtonUser.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\CalculatorDisplay.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\ConversionResultTaskHelper.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\CopyPasteManager.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\DateCalculator.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\DelegateCommand.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\DisplayExpressionToken.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\EngineResourceProvider.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\ExpressionCommandDeserializer.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\ExpressionCommandSerializer.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\KeyboardShortcutManager.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\LocalizationService.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\LocalizationSettings.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\LocalizationStringUtil.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\MyVirtualKey.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\NavCategory.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\NetworkManager.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\TraceLogger.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\Utils.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\ValidatingConverters.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\Automation\INarratorAnnouncementHost.h">
<Filter>Common\Automation</Filter>
</ClInclude>
<ClInclude Include="Common\Automation\LiveRegionHost.h">
<Filter>Common\Automation</Filter>
</ClInclude>
<ClInclude Include="Common\Automation\NarratorAnnouncement.h">
<Filter>Common\Automation</Filter>
</ClInclude>
<ClInclude Include="Common\Automation\NarratorAnnouncementHostFactory.h">
<Filter>Common\Automation</Filter>
</ClInclude>
<ClInclude Include="Common\Automation\NarratorNotifier.h">
<Filter>Common\Automation</Filter>
</ClInclude>
<ClInclude Include="Common\Automation\NotificationHost.h">
<Filter>Common\Automation</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\CurrencyDataLoader.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\CurrencyHttpClient.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\ICurrencyHttpClient.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\UnitConverterDataConstants.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\UnitConverterDataLoader.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="Common\TraceActivity.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\DataLoaderMockConstants.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="DataLoaders\DataLoaderConstants.h">
<Filter>DataLoaders</Filter>
</ClInclude>
<ClInclude Include="Common\BitLength.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="GraphingCalculator\EquationViewModel.h">
<Filter>GraphingCalculator</Filter>
</ClInclude>
<ClInclude Include="GraphingCalculator\GraphingCalculatorViewModel.h">
<Filter>GraphingCalculator</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="DataLoaders\DefaultFromToCurrency.json" />
<None Include="DataLoaders\DefaultFromToCurrency.json">
<Filter>DataLoaders</Filter>
</None>
<None Include="packages.config" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,17 @@
#pragma once
namespace CalculatorApp
{
namespace Common
{
public
enum class BitLength : int
{
BitLengthUnknown = -1,
BitLengthByte = 8,
BitLengthWord = 16,
BitLengthDWord = 32,
BitLengthQWord = 64,
};
}
}

View File

@@ -12,171 +12,35 @@ namespace CalculatorApp
public
enum class NumbersAndOperatorsEnum
{
Zero = (int) CM::Command::Command0,
One = (int) CM::Command::Command1,
Two = (int) CM::Command::Command2,
Three = (int) CM::Command::Command3,
Four = (int) CM::Command::Command4,
Five = (int) CM::Command::Command5,
Six = (int) CM::Command::Command6,
Seven = (int) CM::Command::Command7,
Eight = (int) CM::Command::Command8,
Nine = (int) CM::Command::Command9,
Add = (int) CM::Command::CommandADD,
Subtract = (int) CM::Command::CommandSUB,
Multiply = (int) CM::Command::CommandMUL,
Divide = (int) CM::Command::CommandDIV,
Invert = (int) CM::Command::CommandREC,
Equals = (int) CM::Command::CommandEQU,
Decimal = (int) CM::Command::CommandPNT,
Sqrt = (int) CM::Command::CommandSQRT,
Percent = (int) CM::Command::CommandPERCENT,
Negate = (int) CM::Command::CommandSIGN,
Backspace = (int) CM::Command::CommandBACK,
ClearEntry = (int) CM::Command::CommandCENTR,
Clear = (int) CM::Command::CommandCLEAR,
Degree = (int) CM::Command::CommandDEG,
Radians = (int) CM::Command::CommandRAD,
Grads = (int) CM::Command::CommandGRAD,
Degrees = (int) CM::Command::CommandDegrees,
OpenParenthesis = (int) CM::Command::CommandOPENP,
CloseParenthesis = (int) CM::Command::CommandCLOSEP,
Pi = (int) CM::Command::CommandPI,
Sin = (int) CM::Command::CommandSIN,
Cos = (int) CM::Command::CommandCOS,
Tan = (int) CM::Command::CommandTAN,
Factorial = (int) CM::Command::CommandFAC,
XPower2 = (int) CM::Command::CommandSQR,
Mod = (int) CM::Command::CommandMOD,
FToE = (int) CM::Command::CommandFE,
LogBaseE = (int) CM::Command::CommandLN,
InvSin = (int) CM::Command::CommandASIN,
InvCos = (int) CM::Command::CommandACOS,
InvTan = (int) CM::Command::CommandATAN,
LogBase10 = (int) CM::Command::CommandLOG,
XPowerY = (int) CM::Command::CommandPWR,
YRootX = (int) CM::Command::CommandROOT,
TenPowerX = (int) CM::Command::CommandPOW10,
EPowerX = (int) CM::Command::CommandPOWE,
Exp = (int) CM::Command::CommandEXP,
IsScientificMode = (int) CM::Command::ModeScientific,
IsStandardMode = (int) CM::Command::ModeBasic,
None = (int) CM::Command::CommandNULL,
IsProgrammerMode = (int) CM::Command::ModeProgrammer,
And = (int) CM::Command::CommandAnd,
Ror = (int) CM::Command::CommandROR,
Rol = (int) CM::Command::CommandROL,
Or = (int) CM::Command::CommandOR,
Lsh = (int) CM::Command::CommandLSHF,
Rsh = (int) CM::Command::CommandRSHF,
Xor = (int) CM::Command::CommandXor,
Not = (int) CM::Command::CommandNot,
A = (int) CM::Command::CommandA,
B = (int) CM::Command::CommandB,
C = (int) CM::Command::CommandC,
D = (int) CM::Command::CommandD,
E = (int) CM::Command::CommandE,
F = (int) CM::Command::CommandF,
Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine.
Sinh = (int) CM::Command::CommandSINH,
Cosh = (int) CM::Command::CommandCOSH,
Tanh = (int) CM::Command::CommandTANH,
InvSinh = (int) CM::Command::CommandASINH,
InvCosh = (int) CM::Command::CommandACOSH,
InvTanh = (int) CM::Command::CommandATANH,
Cube = (int) CM::Command::CommandCUB,
DMS = (int) CM::Command::CommandDMS,
Hyp = (int)CM::Command::CommandHYP,
HexButton = (int)CM::Command::CommandHex,
DecButton = (int)CM::Command::CommandDec,
OctButton = (int)CM::Command::CommandOct,
BinButton = (int)CM::Command::CommandBin,
Qword = (int)CM::Command::CommandQword,
Dword = (int)CM::Command::CommandDword,
Word = (int)CM::Command::CommandWord,
Byte = (int)CM::Command::CommandByte,
Plot,
X,
Y,
BINSTART = (int) CM::Command::CommandBINEDITSTART,
BINPOS0 = (int) CM::Command::CommandBINPOS0,
BINPOS1 = (int) CM::Command::CommandBINPOS1,
BINPOS2 = (int) CM::Command::CommandBINPOS2,
BINPOS3 = (int) CM::Command::CommandBINPOS3,
BINPOS4 = (int) CM::Command::CommandBINPOS4,
BINPOS5 = (int) CM::Command::CommandBINPOS5,
BINPOS6 = (int) CM::Command::CommandBINPOS6,
BINPOS7 = (int) CM::Command::CommandBINPOS7,
BINPOS8 = (int) CM::Command::CommandBINPOS8,
BINPOS9 = (int) CM::Command::CommandBINPOS9,
BINPOS10 = (int) CM::Command::CommandBINPOS10,
BINPOS11 = (int) CM::Command::CommandBINPOS11,
BINPOS12 = (int) CM::Command::CommandBINPOS12,
BINPOS13 = (int) CM::Command::CommandBINPOS13,
BINPOS14 = (int) CM::Command::CommandBINPOS14,
BINPOS15 = (int) CM::Command::CommandBINPOS15,
BINPOS16 = (int) CM::Command::CommandBINPOS16,
BINPOS17 = (int) CM::Command::CommandBINPOS17,
BINPOS18 = (int) CM::Command::CommandBINPOS18,
BINPOS19 = (int) CM::Command::CommandBINPOS19,
BINPOS20 = (int) CM::Command::CommandBINPOS20,
BINPOS21 = (int) CM::Command::CommandBINPOS21,
BINPOS22 = (int) CM::Command::CommandBINPOS22,
BINPOS23 = (int) CM::Command::CommandBINPOS23,
BINPOS24 = (int) CM::Command::CommandBINPOS24,
BINPOS25 = (int) CM::Command::CommandBINPOS25,
BINPOS26 = (int) CM::Command::CommandBINPOS26,
BINPOS27 = (int) CM::Command::CommandBINPOS27,
BINPOS28 = (int) CM::Command::CommandBINPOS28,
BINPOS29 = (int) CM::Command::CommandBINPOS29,
BINPOS30 = (int) CM::Command::CommandBINPOS30,
BINPOS31 = (int) CM::Command::CommandBINPOS31,
BINPOS32 = (int) CM::Command::CommandBINPOS32,
BINPOS33 = (int) CM::Command::CommandBINPOS33,
BINPOS34 = (int) CM::Command::CommandBINPOS34,
BINPOS35 = (int) CM::Command::CommandBINPOS35,
BINPOS36 = (int) CM::Command::CommandBINPOS36,
BINPOS37 = (int) CM::Command::CommandBINPOS37,
BINPOS38 = (int) CM::Command::CommandBINPOS38,
BINPOS39 = (int) CM::Command::CommandBINPOS39,
BINPOS40 = (int) CM::Command::CommandBINPOS40,
BINPOS41 = (int) CM::Command::CommandBINPOS41,
BINPOS42 = (int) CM::Command::CommandBINPOS42,
BINPOS43 = (int) CM::Command::CommandBINPOS43,
BINPOS44 = (int) CM::Command::CommandBINPOS44,
BINPOS45 = (int) CM::Command::CommandBINPOS45,
BINPOS46 = (int) CM::Command::CommandBINPOS46,
BINPOS47 = (int) CM::Command::CommandBINPOS47,
BINPOS48 = (int) CM::Command::CommandBINPOS48,
BINPOS49 = (int) CM::Command::CommandBINPOS49,
BINPOS50 = (int) CM::Command::CommandBINPOS50,
BINPOS51 = (int) CM::Command::CommandBINPOS51,
BINPOS52 = (int) CM::Command::CommandBINPOS52,
BINPOS53 = (int) CM::Command::CommandBINPOS53,
BINPOS54 = (int) CM::Command::CommandBINPOS54,
BINPOS55 = (int) CM::Command::CommandBINPOS55,
BINPOS56 = (int) CM::Command::CommandBINPOS56,
BINPOS57 = (int) CM::Command::CommandBINPOS57,
BINPOS58 = (int) CM::Command::CommandBINPOS58,
BINPOS59 = (int) CM::Command::CommandBINPOS59,
BINPOS60 = (int) CM::Command::CommandBINPOS60,
BINPOS61 = (int) CM::Command::CommandBINPOS61,
BINPOS62 = (int) CM::Command::CommandBINPOS62,
BINPOS63 = (int) CM::Command::CommandBINPOS63,
BINEND = (int) CM::Command::CommandBINEDITEND
};
// This contains list of functions whose usage we are tracelogging
public
enum class FunctionLogEnum
{
Zero = (int)CM::Command::Command0,
One = (int)CM::Command::Command1,
Two = (int)CM::Command::Command2,
Three = (int)CM::Command::Command3,
Four = (int)CM::Command::Command4,
Five = (int)CM::Command::Command5,
Six = (int)CM::Command::Command6,
Seven = (int)CM::Command::Command7,
Eight = (int)CM::Command::Command8,
Nine = (int)CM::Command::Command9,
Add = (int)CM::Command::CommandADD,
Subtract = (int)CM::Command::CommandSUB,
Multiply = (int)CM::Command::CommandMUL,
Divide = (int)CM::Command::CommandDIV,
Invert = (int)CM::Command::CommandREC,
Equals = (int)CM::Command::CommandEQU,
Decimal = (int)CM::Command::CommandPNT,
Sqrt = (int)CM::Command::CommandSQRT,
Percent = (int)CM::Command::CommandPERCENT,
Negate = (int)CM::Command::CommandSIGN,
Backspace = (int)CM::Command::CommandBACK,
ClearEntry = (int)CM::Command::CommandCENTR,
Clear = (int)CM::Command::CommandCLEAR,
Degree = (int)CM::Command::CommandDEG,
Radians = (int)CM::Command::CommandRAD,
Grads = (int)CM::Command::CommandGRAD,
Degrees = (int)CM::Command::CommandDegrees,
OpenParenthesis = (int)CM::Command::CommandOPENP,
CloseParenthesis = (int)CM::Command::CommandCLOSEP,
Pi = (int)CM::Command::CommandPI,
Sin = (int)CM::Command::CommandSIN,
Cos = (int)CM::Command::CommandCOS,
@@ -195,10 +59,10 @@ public
TenPowerX = (int)CM::Command::CommandPOW10,
EPowerX = (int)CM::Command::CommandPOWE,
Exp = (int)CM::Command::CommandEXP,
DecButton = (int)CM::Command::CommandDec,
OctButton = (int)CM::Command::CommandOct,
HexButton = (int)CM::Command::CommandHex,
BinButton = (int)CM::Command::CommandBin,
IsScientificMode = (int)CM::Command::ModeScientific,
IsStandardMode = (int)CM::Command::ModeBasic,
None = (int)CM::Command::CommandNULL,
IsProgrammerMode = (int)CM::Command::ModeProgrammer,
And = (int)CM::Command::CommandAnd,
Ror = (int)CM::Command::CommandROR,
Rol = (int)CM::Command::CommandROL,
@@ -207,13 +71,108 @@ public
Rsh = (int)CM::Command::CommandRSHF,
Xor = (int)CM::Command::CommandXor,
Not = (int)CM::Command::CommandNot,
A = (int)CM::Command::CommandA,
B = (int)CM::Command::CommandB,
C = (int)CM::Command::CommandC,
D = (int)CM::Command::CommandD,
E = (int)CM::Command::CommandE,
F = (int)CM::Command::CommandF,
Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine.
Sinh = (int)CM::Command::CommandSINH,
Cosh = (int)CM::Command::CommandCOSH,
Tanh = (int)CM::Command::CommandTANH,
InvSinh = (int)CM::Command::CommandASINH,
InvCosh = (int)CM::Command::CommandACOSH,
InvTanh = (int)CM::Command::CommandATANH,
Cube = (int)CM::Command::CommandCUB,
DMS = (int)CM::Command::CommandDMS,
Cube = (int) CM::Command::CommandCUB,
DMS = (int) CM::Command::CommandDMS,
Hyp = (int)CM::Command::CommandHYP,
HexButton = (int)CM::Command::CommandHex,
DecButton = (int)CM::Command::CommandDec,
OctButton = (int)CM::Command::CommandOct,
BinButton = (int)CM::Command::CommandBin,
Qword = (int)CM::Command::CommandQword,
Dword = (int)CM::Command::CommandDword,
Word = (int)CM::Command::CommandWord,
Byte = (int)CM::Command::CommandByte,
Plot,
X,
Y,
BINSTART = (int)CM::Command::CommandBINEDITSTART,
BINPOS0 = (int)CM::Command::CommandBINPOS0,
BINPOS1 = (int)CM::Command::CommandBINPOS1,
BINPOS2 = (int)CM::Command::CommandBINPOS2,
BINPOS3 = (int)CM::Command::CommandBINPOS3,
BINPOS4 = (int)CM::Command::CommandBINPOS4,
BINPOS5 = (int)CM::Command::CommandBINPOS5,
BINPOS6 = (int)CM::Command::CommandBINPOS6,
BINPOS7 = (int)CM::Command::CommandBINPOS7,
BINPOS8 = (int)CM::Command::CommandBINPOS8,
BINPOS9 = (int)CM::Command::CommandBINPOS9,
BINPOS10 = (int)CM::Command::CommandBINPOS10,
BINPOS11 = (int)CM::Command::CommandBINPOS11,
BINPOS12 = (int)CM::Command::CommandBINPOS12,
BINPOS13 = (int)CM::Command::CommandBINPOS13,
BINPOS14 = (int)CM::Command::CommandBINPOS14,
BINPOS15 = (int)CM::Command::CommandBINPOS15,
BINPOS16 = (int)CM::Command::CommandBINPOS16,
BINPOS17 = (int)CM::Command::CommandBINPOS17,
BINPOS18 = (int)CM::Command::CommandBINPOS18,
BINPOS19 = (int)CM::Command::CommandBINPOS19,
BINPOS20 = (int)CM::Command::CommandBINPOS20,
BINPOS21 = (int)CM::Command::CommandBINPOS21,
BINPOS22 = (int)CM::Command::CommandBINPOS22,
BINPOS23 = (int)CM::Command::CommandBINPOS23,
BINPOS24 = (int)CM::Command::CommandBINPOS24,
BINPOS25 = (int)CM::Command::CommandBINPOS25,
BINPOS26 = (int)CM::Command::CommandBINPOS26,
BINPOS27 = (int)CM::Command::CommandBINPOS27,
BINPOS28 = (int)CM::Command::CommandBINPOS28,
BINPOS29 = (int)CM::Command::CommandBINPOS29,
BINPOS30 = (int)CM::Command::CommandBINPOS30,
BINPOS31 = (int)CM::Command::CommandBINPOS31,
BINPOS32 = (int)CM::Command::CommandBINPOS32,
BINPOS33 = (int)CM::Command::CommandBINPOS33,
BINPOS34 = (int)CM::Command::CommandBINPOS34,
BINPOS35 = (int)CM::Command::CommandBINPOS35,
BINPOS36 = (int)CM::Command::CommandBINPOS36,
BINPOS37 = (int)CM::Command::CommandBINPOS37,
BINPOS38 = (int)CM::Command::CommandBINPOS38,
BINPOS39 = (int)CM::Command::CommandBINPOS39,
BINPOS40 = (int)CM::Command::CommandBINPOS40,
BINPOS41 = (int)CM::Command::CommandBINPOS41,
BINPOS42 = (int)CM::Command::CommandBINPOS42,
BINPOS43 = (int)CM::Command::CommandBINPOS43,
BINPOS44 = (int)CM::Command::CommandBINPOS44,
BINPOS45 = (int)CM::Command::CommandBINPOS45,
BINPOS46 = (int)CM::Command::CommandBINPOS46,
BINPOS47 = (int)CM::Command::CommandBINPOS47,
BINPOS48 = (int)CM::Command::CommandBINPOS48,
BINPOS49 = (int)CM::Command::CommandBINPOS49,
BINPOS50 = (int)CM::Command::CommandBINPOS50,
BINPOS51 = (int)CM::Command::CommandBINPOS51,
BINPOS52 = (int)CM::Command::CommandBINPOS52,
BINPOS53 = (int)CM::Command::CommandBINPOS53,
BINPOS54 = (int)CM::Command::CommandBINPOS54,
BINPOS55 = (int)CM::Command::CommandBINPOS55,
BINPOS56 = (int)CM::Command::CommandBINPOS56,
BINPOS57 = (int)CM::Command::CommandBINPOS57,
BINPOS58 = (int)CM::Command::CommandBINPOS58,
BINPOS59 = (int)CM::Command::CommandBINPOS59,
BINPOS60 = (int)CM::Command::CommandBINPOS60,
BINPOS61 = (int)CM::Command::CommandBINPOS61,
BINPOS62 = (int)CM::Command::CommandBINPOS62,
BINPOS63 = (int)CM::Command::CommandBINPOS63,
BINEND = (int)CM::Command::CommandBINEDITEND,
// Enum values below are used for Tracelogging and do not map to the Calculator engine
MemoryAdd = (int)CM::Command::CommandMPLUS,
MemorySubtract = (int)CM::Command::CommandMMINUS,
MemoryRecall = (int)CM::Command::CommandRECALL,
MemoryClear = (int)CM::Command::CommandMCLEAR,
BitflipButton = 1000,
FullKeypadButton = 1001
};
}

View File

@@ -65,7 +65,7 @@ void CopyPasteManager::CopyToClipboard(String ^ stringToCopy)
Clipboard::SetContent(dataPackage);
}
task<String ^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
task<String ^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
// Retrieve the text in the clipboard
auto dataPackageView = Clipboard::GetContent();
@@ -97,19 +97,19 @@ int CopyPasteManager::ClipboardTextFormat()
return -1;
}
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, int bitLengthType)
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, BitLength bitLengthType)
{
return CopyPasteManager::ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType);
}
// return "NoOp" if pastedText is invalid else return pastedText
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
if (pastedText->Length() > MaxPasteableLength)
{
// return NoOp to indicate don't paste anything.
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"PastedExpressionSizeGreaterThanMaxAllowed", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed");
return StringReference(PasteErrorString);
}
@@ -129,7 +129,7 @@ String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode
// Extract operands from the expression to make regex comparison easy and quick. For whole expression it was taking too much of time.
// Operands vector will have the list of operands in the pasteExpression
vector<wstring> operands = ExtractOperands(pasteExpression, mode, programmerNumberBase, bitLengthType);
vector<wstring> operands = ExtractOperands(pasteExpression, mode);
if (operands.empty())
{
// return NoOp to indicate don't paste anything.
@@ -144,14 +144,14 @@ String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode
// validate each operand with patterns for different modes
if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType))
{
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"InvalidExpressionForPresentMode", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode");
return StringReference(PasteErrorString);
}
return ref new String(pastedText->Data());
}
vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode, int programmerNumberBase, int bitLengthType)
vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode)
{
vector<wstring> operands{};
size_t lastIndex = 0;
@@ -173,7 +173,7 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
if (operands.size() >= MaxOperandCount)
{
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"OperandCountGreaterThanMaxCount", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"OperandCountGreaterThanMaxCount");
operands.clear();
return operands;
}
@@ -187,7 +187,7 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
// to disallow pasting of 1e+12345 as 1e+1234, max exponent that can be pasted is 9999.
if (expLength > MaxExponentLength)
{
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"ExponentLengthGreaterThanMaxLength", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"ExponentLengthGreaterThanMaxLength");
operands.clear();
return operands;
}
@@ -241,7 +241,7 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
return operands;
}
bool CopyPasteManager::ExpressionRegExMatch(vector<wstring> operands, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
bool CopyPasteManager::ExpressionRegExMatch(vector<wstring> operands, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
if (operands.empty())
{
@@ -317,7 +317,7 @@ bool CopyPasteManager::ExpressionRegExMatch(vector<wstring> operands, ViewMode m
return expMatched;
}
pair<size_t, uint64_t> CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
pair<size_t, uint64_t> CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
constexpr size_t defaultMaxOperandLength = 0;
constexpr uint64_t defaultMaxValue = 0;
@@ -335,16 +335,16 @@ pair<size_t, uint64_t> CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mo
unsigned int bitLength = 0;
switch (bitLengthType)
{
case QwordType:
case BitLength::BitLengthQWord:
bitLength = 64;
break;
case DwordType:
case BitLength::BitLengthDWord:
bitLength = 32;
break;
case WordType:
case BitLength::BitLengthWord:
bitLength = 16;
break;
case ByteType:
case BitLength::BitLengthByte:
bitLength = 8;
break;
}

View File

@@ -5,6 +5,7 @@
#include "AppResourceProvider.h"
#include "NavCategory.h"
#include "BitLength.h"
namespace CalculatorUnitTests
{
@@ -13,10 +14,6 @@ namespace CalculatorUnitTests
namespace CalculatorApp
{
inline constexpr auto QwordType = 1;
inline constexpr auto DwordType = 2;
inline constexpr auto WordType = 3;
inline constexpr auto ByteType = 4;
inline constexpr auto HexBase = 5;
inline constexpr auto DecBase = 6;
inline constexpr auto OctBase = 7;
@@ -30,7 +27,7 @@ namespace CalculatorApp
CalculatorApp::Common::ViewMode mode,
CalculatorApp::Common::CategoryGroupType modeType,
int programmerNumberBase = -1,
int bitLengthType = -1);
CalculatorApp::Common::BitLength bitLengthType = CalculatorApp::Common::BitLength::BitLengthUnknown);
static bool HasStringToPaste()
{
return ClipboardTextFormat() >= 0;
@@ -41,29 +38,33 @@ namespace CalculatorApp
private:
static int ClipboardTextFormat();
static Platform::String
^ ValidatePasteExpression(Platform::String ^ pastedText, CalculatorApp::Common::ViewMode mode, int programmerNumberBase, int bitLengthType);
^ ValidatePasteExpression(
Platform::String ^ pastedText,
CalculatorApp::Common::ViewMode mode,
int programmerNumberBase,
CalculatorApp::Common::BitLength bitLengthType);
static Platform::String
^ ValidatePasteExpression(
Platform::String ^ pastedText,
CalculatorApp::Common::ViewMode mode,
CalculatorApp::Common::CategoryGroupType modeType,
int programmerNumberBase,
int bitLengthType);
CalculatorApp::Common::BitLength bitLengthType);
static std::vector<std::wstring>
ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode, int programmerNumberBase = -1, int bitLengthType = -1);
ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode);
static bool ExpressionRegExMatch(
std::vector<std::wstring> operands,
CalculatorApp::Common::ViewMode mode,
CalculatorApp::Common::CategoryGroupType modeType,
int programmerNumberBase = -1,
int bitLengthType = -1);
CalculatorApp::Common::BitLength bitLengthType = CalculatorApp::Common::BitLength::BitLengthUnknown);
static std::pair<size_t, uint64_t> GetMaxOperandLengthAndValue(
CalculatorApp::Common::ViewMode mode,
CalculatorApp::Common::CategoryGroupType modeType,
int programmerNumberBase = -1,
int bitLengthType = -1);
CalculatorApp::Common::BitLength bitLengthType = CalculatorApp::Common::BitLength::BitLengthUnknown);
static std::wstring SanitizeOperand(const std::wstring& operand);
static bool TryOperandToULL(const std::wstring& operand, int numberBase, unsigned long long int& result);
static size_t OperandLength(

View File

@@ -670,10 +670,11 @@ void KeyboardShortcutManager::OnAcceleratorKeyActivated(CoreDispatcher ^, Accele
if (nullptr != vm)
{
ViewMode toMode = NavCategory::GetViewModeForVirtualKey(static_cast<MyVirtualKey>(key));
if (NavCategory::IsValidViewMode(toMode))
auto nvi = dynamic_cast<MUXC::NavigationViewItem ^>(menuItems->GetAt(NavCategory::GetFlatIndex(toMode)));
if (nvi && nvi->IsEnabled && NavCategory::IsValidViewMode(toMode))
{
vm->Mode = toMode;
navView->SelectedItem = menuItems->GetAt(NavCategory::GetFlatIndex(toMode));
navView->SelectedItem = nvi;
}
}
}

View File

@@ -75,9 +75,24 @@ LocalizationService::LocalizationService(_In_ const wchar_t * const overridedLan
{
m_isLanguageOverrided = overridedLanguage != nullptr;
m_language = m_isLanguageOverrided ? ref new Platform::String(overridedLanguage) : ApplicationLanguages::Languages->GetAt(0);
m_flowDirection = ResourceContext::GetForCurrentView()->QualifierValues->Lookup(L"LayoutDirection")
m_flowDirection = ResourceContext::GetForViewIndependentUse()->QualifierValues->Lookup(L"LayoutDirection")
!= L"LTR" ? FlowDirection::RightToLeft : FlowDirection::LeftToRight;
wstring localeName = wstring(m_language->Data());
localeName += L".UTF8";
try
{
// Convert wstring to string for locale
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &localeName[0], (int)localeName.size(), NULL, 0, NULL, NULL);
string localeNameStr(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &localeName[0], (int)localeName.size(), &localeNameStr[0], size_needed, NULL, NULL);
m_locale = locale(localeNameStr.data());
}
catch (...)
{
m_locale = locale("");
}
auto resourceLoader = AppResourceProvider::GetInstance();
m_fontFamilyOverride = resourceLoader.GetResourceString(L"LocalizedFontFamilyOverride");
@@ -371,7 +386,7 @@ DecimalFormatter ^ LocalizationService::GetRegionalSettingsAwareDecimalFormatter
// as configured by running intl.cpl.
//
// This helper function creates a DateTimeFormatter with a TwentyFour hour clock
DateTimeFormatter ^ LocalizationService::GetRegionalSettingsAwareDateTimeFormatter(_In_ String^ format) const
DateTimeFormatter ^ LocalizationService::GetRegionalSettingsAwareDateTimeFormatter(_In_ String ^ format) const
{
IIterable<String ^> ^ languageIdentifiers = LocalizationService::GetLanguageIdentifiers();
if (languageIdentifiers == nullptr)
@@ -384,7 +399,7 @@ DateTimeFormatter ^ LocalizationService::GetRegionalSettingsAwareDateTimeFormatt
// If successful, returns a formatter that respects the user's regional format settings,
// as configured by running intl.cpl.
DateTimeFormatter^ LocalizationService::GetRegionalSettingsAwareDateTimeFormatter(_In_ String ^ format, _In_ String ^ calendarIdentifier, _In_ String ^ clockIdentifier) const
DateTimeFormatter ^ LocalizationService::GetRegionalSettingsAwareDateTimeFormatter(_In_ String ^ format, _In_ String ^ calendarIdentifier, _In_ String ^ clockIdentifier) const
{
IIterable<String ^> ^ languageIdentifiers = LocalizationService::GetLanguageIdentifiers();
if (languageIdentifiers == nullptr)
@@ -421,7 +436,7 @@ IIterable<String ^> ^ LocalizationService::GetLanguageIdentifiers() const
if (m_isLanguageOverrided)
{
auto overridedLanguageList = ref new Vector<String^>();
auto overridedLanguageList = ref new Vector<String ^>();
overridedLanguageList->Append(m_language);
return overridedLanguageList;
}
@@ -562,3 +577,11 @@ String ^ LocalizationService::GetNarratorReadableString(String ^ rawString)
return ref new String(readableString.str().c_str());
}
void LocalizationService::Sort(std::vector<Platform::String ^>& source)
{
const collate<wchar_t>& coll = use_facet<collate<wchar_t>>(m_locale);
sort(source.begin(), source.end(), [&coll](Platform::String ^ str1, Platform::String ^ str2) {
return coll.compare(str1->Begin(), str1->End(), str2->Begin(), str2->End()) < 0;
});
}

View File

@@ -30,9 +30,9 @@ namespace CalculatorApp
DEPENDENCY_PROPERTY_ATTACHED_WITH_DEFAULT_AND_CALLBACK(LanguageFontType, FontType, LanguageFontType::UIText);
DEPENDENCY_PROPERTY_ATTACHED_WITH_CALLBACK(double, FontSize);
internal:
static LocalizationService^ GetInstance();
static void OverrideWithLanguage(_In_ const wchar_t * const language);
internal:
static LocalizationService ^ GetInstance();
static void OverrideWithLanguage(_In_ const wchar_t* const language);
Windows::UI::Xaml::FlowDirection GetFlowDirection();
bool IsRtlLayout();
@@ -43,6 +43,19 @@ namespace CalculatorApp
Windows::UI::Text::FontWeight GetFontWeightOverride();
double GetFontScaleFactorOverride(LanguageFontType fontType);
void Sort(std::vector<Platform::String ^>& source);
template <typename T>
void Sort(std::vector<T>& source, std::function<Platform::String ^ (T)> func)
{
const collate<wchar_t>& coll = use_facet<collate<wchar_t>>(m_locale);
sort(source.begin(), source.end(), [&coll, &func](T obj1, T obj2) {
Platform::String ^ str1 = func(obj1);
Platform::String ^ str2 = func(obj2);
return coll.compare(str1->Begin(), str1->End(), str2->Begin(), str2->End()) < 0;
});
}
Windows::Globalization::NumberFormatting::DecimalFormatter ^ GetRegionalSettingsAwareDecimalFormatter() const;
Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter(_In_ Platform::String ^ format) const;
Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter(
@@ -76,15 +89,16 @@ namespace CalculatorApp
static LocalizationService ^ s_singletonInstance;
Windows::Globalization::Fonts::LanguageFontGroup ^ m_fontGroup;
Platform::String ^ m_language;
Windows::UI::Xaml::FlowDirection m_flowDirection;
bool m_overrideFontApiValues;
Platform::String ^ m_fontFamilyOverride;
bool m_isLanguageOverrided;
Windows::UI::Text::FontWeight m_fontWeightOverride;
double m_uiTextFontScaleFactorOverride;
double m_uiCaptionFontScaleFactorOverride;
Windows::Globalization::Fonts::LanguageFontGroup ^ m_fontGroup;
Platform::String ^ m_language;
Windows::UI::Xaml::FlowDirection m_flowDirection;
bool m_overrideFontApiValues;
Platform::String ^ m_fontFamilyOverride;
bool m_isLanguageOverrided;
Windows::UI::Text::FontWeight m_fontWeightOverride;
double m_uiTextFontScaleFactorOverride;
double m_uiCaptionFontScaleFactorOverride;
std::locale m_locale;
};
}

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"
@@ -37,39 +37,163 @@ static constexpr int VOLUME_ID = 4;
static constexpr int LENGTH_ID = 5;
static constexpr int WEIGHT_ID = 6;
static constexpr int TEMPERATURE_ID = 7;
static constexpr int ENERGY_ID = 8;
static constexpr int AREA_ID = 9;
static constexpr int SPEED_ID = 10;
static constexpr int TIME_ID = 11;
static constexpr int POWER_ID = 12;
static constexpr int DATA_ID = 13;
static constexpr int PRESSURE_ID = 14;
static constexpr int ANGLE_ID = 15;
static constexpr int CURRENCY_ID = 16;
static constexpr int ENERGY_ID = 8;
static constexpr int AREA_ID = 9;
static constexpr int SPEED_ID = 10;
static constexpr int TIME_ID = 11;
static constexpr int POWER_ID = 12;
static constexpr int DATA_ID = 13;
static constexpr int PRESSURE_ID = 14;
static constexpr int ANGLE_ID = 15;
static constexpr int CURRENCY_ID = 16;
static constexpr int GRAPHING_ID = 17;
// ^^^ THESE CONSTANTS SHOULD NEVER CHANGE ^^^
// The order of items in this list determines the order of items in the menu.
static constexpr array<const NavCategoryInitializer, 18> s_categoryManifest = {
NavCategoryInitializer { ViewMode::Standard, STANDARD_ID, L"Standard", L"StandardMode", L"\uE8EF", CategoryGroupType::Calculator, MyVirtualKey::Number1, SUPPORTS_ALL },
NavCategoryInitializer { ViewMode::Scientific, SCIENTIFIC_ID, L"Scientific", L"ScientificMode", L"\uF196", CategoryGroupType::Calculator, MyVirtualKey::Number2, SUPPORTS_ALL },
NavCategoryInitializer { ViewMode::Programmer, PROGRAMMER_ID, L"Programmer", L"ProgrammerMode", L"\uECCE", CategoryGroupType::Calculator, MyVirtualKey::Number3, SUPPORTS_ALL },
NavCategoryInitializer { ViewMode::Date, DATE_ID, L"Date", L"DateCalculationMode", L"\uE787", CategoryGroupType::Calculator, MyVirtualKey::Number4, SUPPORTS_ALL },
NavCategoryInitializer { ViewMode::Graphing, GRAPHING_ID, L"Graphing", L"GraphingCalculatorMode", L"\uF770", CategoryGroupType::Calculator, MyVirtualKey::Number5, SUPPORTS_ALL },
NavCategoryInitializer { ViewMode::Currency, CURRENCY_ID, L"Currency", L"CategoryName_Currency", L"\uEB0D", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Volume, VOLUME_ID, L"Volume", L"CategoryName_Volume", L"\uF1AA", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Length, LENGTH_ID, L"Length", L"CategoryName_Length", L"\uECC6", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Weight, WEIGHT_ID, L"Weight and Mass", L"CategoryName_Weight", L"\uF4C1", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Temperature, TEMPERATURE_ID, L"Temperature", L"CategoryName_Temperature", L"\uE7A3", CategoryGroupType::Converter, MyVirtualKey::None, SUPPORTS_NEGATIVE },
NavCategoryInitializer { ViewMode::Energy, ENERGY_ID, L"Energy", L"CategoryName_Energy", L"\uECAD", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Area, AREA_ID, L"Area", L"CategoryName_Area", L"\uE809", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Speed, SPEED_ID, L"Speed", L"CategoryName_Speed", L"\uEADA", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Time, TIME_ID, L"Time", L"CategoryName_Time", L"\uE917", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Power, POWER_ID, L"Power", L"CategoryName_Power", L"\uE945", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Data, DATA_ID, L"Data", L"CategoryName_Data", L"\uF20F", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Pressure, PRESSURE_ID, L"Pressure", L"CategoryName_Pressure", L"\uEC4A", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY },
NavCategoryInitializer { ViewMode::Angle, ANGLE_ID, L"Angle", L"CategoryName_Angle", L"\uF515", CategoryGroupType::Converter, MyVirtualKey::None, POSITIVE_ONLY }
};
static constexpr array<const NavCategoryInitializer, 18> s_categoryManifest = { NavCategoryInitializer{ ViewMode::Standard,
STANDARD_ID,
L"Standard",
L"StandardMode",
L"\uE8EF",
CategoryGroupType::Calculator,
MyVirtualKey::Number1,
SUPPORTS_ALL },
NavCategoryInitializer{ ViewMode::Graphing,
GRAPHING_ID,
L"Graphing",
L"GraphingCalculatorMode",
L"\uF770",
CategoryGroupType::Calculator,
MyVirtualKey::Number5,
SUPPORTS_ALL },
NavCategoryInitializer{ ViewMode::Scientific,
SCIENTIFIC_ID,
L"Scientific",
L"ScientificMode",
L"\uF196",
CategoryGroupType::Calculator,
MyVirtualKey::Number2,
SUPPORTS_ALL },
NavCategoryInitializer{ ViewMode::Programmer,
PROGRAMMER_ID,
L"Programmer",
L"ProgrammerMode",
L"\uECCE",
CategoryGroupType::Calculator,
MyVirtualKey::Number3,
SUPPORTS_ALL },
NavCategoryInitializer{ ViewMode::Date,
DATE_ID,
L"Date",
L"DateCalculationMode",
L"\uE787",
CategoryGroupType::Calculator,
MyVirtualKey::Number4,
SUPPORTS_ALL },
NavCategoryInitializer{ ViewMode::Currency,
CURRENCY_ID,
L"Currency",
L"CategoryName_Currency",
L"\uEB0D",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Volume,
VOLUME_ID,
L"Volume",
L"CategoryName_Volume",
L"\uF1AA",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Length,
LENGTH_ID,
L"Length",
L"CategoryName_Length",
L"\uECC6",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Weight,
WEIGHT_ID,
L"Weight and Mass",
L"CategoryName_Weight",
L"\uF4C1",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Temperature,
TEMPERATURE_ID,
L"Temperature",
L"CategoryName_Temperature",
L"\uE7A3",
CategoryGroupType::Converter,
MyVirtualKey::None,
SUPPORTS_NEGATIVE },
NavCategoryInitializer{ ViewMode::Energy,
ENERGY_ID,
L"Energy",
L"CategoryName_Energy",
L"\uECAD",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Area,
AREA_ID,
L"Area",
L"CategoryName_Area",
L"\uE809",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Speed,
SPEED_ID,
L"Speed",
L"CategoryName_Speed",
L"\uEADA",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Time,
TIME_ID,
L"Time",
L"CategoryName_Time",
L"\uE917",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Power,
POWER_ID,
L"Power",
L"CategoryName_Power",
L"\uE945",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Data,
DATA_ID,
L"Data",
L"CategoryName_Data",
L"\uF20F",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Pressure,
PRESSURE_ID,
L"Pressure",
L"CategoryName_Pressure",
L"\uEC4A",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY },
NavCategoryInitializer{ ViewMode::Angle,
ANGLE_ID,
L"Angle",
L"CategoryName_Angle",
L"\uF515",
CategoryGroupType::Converter,
MyVirtualKey::None,
POSITIVE_ONLY } };
// This function should only be used when storing the mode to app data.
int NavCategory::Serialize(ViewMode mode)

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
#include "CalcManager/Command.h"
#include "TraceActivity.h"
#include "NavCategory.h"
#include "CalculatorButtonUser.h"
static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINEDITEND;
@@ -13,19 +14,17 @@ static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINE
// This class implements a singleton model ensure that only one instance is created.
namespace CalculatorApp
{
struct FuncLog
struct ButtonLog
{
public:
int count;
std::wstring funcName;
FuncLog()
CalculatorApp::NumbersAndOperatorsEnum button;
CalculatorApp::Common::ViewMode mode;
ButtonLog(CalculatorApp::NumbersAndOperatorsEnum btn, CalculatorApp::Common::ViewMode vMode)
{
count = 0;
}
FuncLog(std::wstring fName)
{
funcName = fName;
count = 0;
button = btn;
mode = vMode;
count = 1;
}
};
@@ -38,123 +37,46 @@ namespace CalculatorApp
static TraceLogger& GetInstance();
bool GetTraceLoggingProviderEnabled() const;
void LogAppLaunchStart();
void LogAppLaunchComplete();
void LogAppResumeComplete();
void LogOnAppLaunch(std::wstring_view previousExecutionState) const;
void LogMemoryClearAll(int);
void LogBitFlipPaneClicked() const;
void LogBitFlipUsed() const;
void LogHistoryBodyOpened() const;
void LogHistoryItemLoadBegin() const;
void LogHistoryItemLoadEnd(unsigned int) const;
void LogHistoryFlyoutOpenBegin(unsigned int) const;
void LogHistoryFlyoutOpenEnd(int) const;
void LogCalculatorModeViewed(CalculatorApp::Common::ViewMode, int);
void LogDateCalculatorModeViewed(CalculatorApp::Common::ViewMode, int);
void LogConverterModeViewed(CalculatorApp::Common::ViewMode, int);
void LogModeChangeBegin(CalculatorApp::Common::ViewMode, CalculatorApp::Common::ViewMode, int);
void LogModeChangeEnd(CalculatorApp::Common::ViewMode, int) const;
void LogClearHistory() const;
void InsertIntoMemoryMap(int, bool, bool, bool);
void UpdateMemoryMap(int, int, bool, bool, bool);
void DeleteFromMemoryMap(int, int);
void LogMemoryUsed(int, unsigned int, bool, bool, bool, unsigned int) const;
void LogMultipleMemoryUsed(unsigned int, unsigned int) const;
void LogSingleMemoryUsed(unsigned int) const;
void LogSharedMemoryUsed(std::wstring_view, std::wstring_view, unsigned int) const;
void LogMemoryBodyOpened() const;
void LogMemoryFlyoutOpenBegin(unsigned int) const;
void LogDebug(std::wstring_view debugData);
void LogMemoryFlyoutOpenEnd(unsigned int) const;
void LogInvalidPastedInputOccurred(std::wstring_view reason, CalculatorApp::Common::ViewMode mode, int ProgrammerNumberBase, int bitLengthType);
void LogValidInputPasted(CalculatorApp::Common::ViewMode mode) const;
void UpdateFunctionUsage(int func);
void LogFunctionUsage(int);
void InitFunctionLogArray();
void LogBitLengthButtonUsed(int windowId);
void LogRadixButtonUsed(int windowId);
void LogAngleButtonUsed(int windowId);
void LogHypButtonUsed(int windowId);
void LogNewWindowCreationBegin(int windowId);
void LogNewWindowCreationEnd(int windowId);
void LogError(std::wstring_view errorString);
void LogPrelaunchedAppActivatedByUser();
void LogAppPrelaunchedBySystem();
void UpdateWindowCount(size_t windowCount);
bool UpdateWindowIdLog(int windowId);
void LogMaxWindowCount();
void LogWindowActivated() const;
void LogWindowLaunched() const;
void LogUserRequestedRefreshFailed() const;
void LogConversionResult(std::wstring_view fromValue, std::wstring_view fromUnit, std::wstring_view toValue, std::wstring_view toUnit) const;
void LogAboutFlyoutOpened() const;
void LogModeChange(CalculatorApp::Common::ViewMode mode) const;
void LogHistoryItemLoad(CalculatorApp::Common::ViewMode mode, int historyListSize, int loadedIndex) const;
void LogMemoryItemLoad(CalculatorApp::Common::ViewMode mode, int memoryListSize, int loadedIndex) const;
void UpdateButtonUsage(CalculatorApp::NumbersAndOperatorsEnum button, CalculatorApp::Common::ViewMode mode);
void LogButtonUsage();
void LogDateCalculationModeUsed(bool AddSubtractMode);
void UpdateWindowCount(size_t windowCount = 0);
bool IsWindowIdInLog(int windowId);
void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, std::wstring_view state, bool isAlwaysOnTop = false) const;
void LogWindowCreated(CalculatorApp::Common::ViewMode mode, int windowId);
void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode) const;
void LogNavBarOpened() const;
void LogViewClosingTelemetry(int);
void LogCoreWindowWasNull() const;
// Trace methods for Date Calculator usage
void LogDateDifferenceModeUsed(int windowId);
void LogDateAddSubtractModeUsed(int windowId, bool isAddMode);
void
LogDateClippedTimeDifferenceFound(winrt::Windows::Globalization::Calendar const& today, winrt::Windows::Foundation::DateTime const& clippedTime) const;
void LogStandardException(std::wstring_view functionName, _In_ const std::exception& e) const;
void LogWinRTException(std::wstring_view functionName, _In_ winrt::hresult_error const& e) const;
void LogPlatformException(std::wstring_view functionName, _In_ Platform::Exception ^ e) const;
void LogError(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, std::wstring_view errorString);
void LogStandardException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e) const;
void LogWinRTException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ winrt::hresult_error const& e) const;
void LogPlatformException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ Platform::Exception ^ e) const;
void LogInputPasted(CalculatorApp::Common::ViewMode mode) const;
private:
// Create an instance of TraceLogger
TraceLogger();
// Any new Log method should
// a) decide the level of logging. This will help us in limiting recording of events only up to a certain level. See this link for guidance
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363742(v=vs.85).aspx We're using Verbose level for events that are called frequently and
// needed only for debugging or capturing perf for specific scenarios b) should decide whether or not to log to telemetry and pass
// TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) accordingly c) Should accept a variable number of additional data arguments if needed
void LogTelemetryEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogMeasureEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogCriticalDataEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogPerformanceEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogInfoEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
// As mentioned in Microsoft's Privacy Statement(https://privacy.microsoft.com/en-US/privacystatement#maindiagnosticsmodule),
// sampling is involved in Microsoft's diagnostic data collection process.
// These keywords provide additional input into how frequently an event might be sampled.
// The lower the level of the keyword, the higher the possibility that the corresponding event may be sampled.
void LogLevel1Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogLevel2Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogLevel3Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
std::unique_ptr<TraceActivity> CreateTraceActivity(std::wstring_view activityName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
winrt::Windows::Foundation::Diagnostics::LoggingChannel g_calculatorProvider;
bool isSizeChangeLogged = false;
bool isHideIfShownLogged = false;
bool isSizeChangedFirstTime = true; // to track the first size changed event which is fired on the launch of app
bool isAutoConversionBeginLoggedInSession = false;
bool isAutoConversionEndLoggedInSession = false;
bool angleButtonLoggedInSession = false;
bool radixButtonLoggedInSession = false;
bool bitLengthButtonLoggedInSession = false;
std::vector<ButtonLog> buttonLog;
std::vector<int> windowIdLog;
GUID sessionGuid;
CalculatorApp::Common::ViewMode currentMode = CalculatorApp::Common::ViewMode::None;
std::vector<FuncLog> funcLog;
int functionCount = 0;
bool isHypButtonLogged = false;
bool isAngleButtonInitialized = false;
unsigned int findIndex[maxFunctionSize] = { 0 };
bool GetIndex(int& index);
std::wstring GetProgrammerType(int index);
size_t maxWindowCount = 0;
bool isAppLaunchBeginLogged = false;
bool isAppLaunchEndLogged = false;
std::map<int, int> bitLengthButtonUsage;
std::map<int, int> angleButtonUsage;
std::map<int, int> radixButtonUsage;
std::map<int, bool> windowIdLog;
// Private variables for Date Calculator usage
bool m_dateDiffUsageLoggedInSession = false;
bool m_dateAddUsageLoggedInSession = false;
bool m_dateSubtractUsageLoggedInSession = false;
std::map<int, int> m_dateAddModeUsage;
std::map<int, int> m_dateSubtractModeUsage;
size_t windowLaunchCount = 0;
size_t currentWindowCount = 0;
winrt::Windows::Foundation::Diagnostics::LoggingActivity m_appLaunchActivity;
};

View File

@@ -416,8 +416,12 @@ namespace Utils
Windows::Foundation::DateTime GetUniversalSystemTime();
bool IsDateTimeOlderThan(Windows::Foundation::DateTime dateTime, const long long duration);
concurrency::task<void> WriteFileToFolder(Windows::Storage::IStorageFolder^ folder, Platform::String^ fileName, Platform::String^ contents, Windows::Storage::CreationCollisionOption collisionOption);
concurrency::task<Platform::String^> ReadFileFromFolder(Windows::Storage::IStorageFolder^ folder, Platform::String^ fileName);
concurrency::task<void> WriteFileToFolder(
Windows::Storage::IStorageFolder ^ folder,
Platform::String ^ fileName,
Platform::String ^ contents,
Windows::Storage::CreationCollisionOption collisionOption);
concurrency::task<Platform::String ^> ReadFileFromFolder(Windows::Storage::IStorageFolder ^ folder, Platform::String ^ fileName);
bool AreColorsEqual(const Windows::UI::Color& color1, const Windows::UI::Color& color2);

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"
@@ -39,7 +39,9 @@ static constexpr auto CURRENCY_UNIT_TO_KEY = L"CURRENCY_UNIT_TO_KEY";
static constexpr long long DAY_DURATION = 1LL * 60 * 60 * 24 * 10000000;
static constexpr long long WEEK_DURATION = DAY_DURATION * 7;
static constexpr int FORMATTER_DIGIT_COUNT = 4;
static constexpr int FORMATTER_RATE_FRACTION_PADDING = 2;
static constexpr int FORMATTER_RATE_MIN_DECIMALS = 4;
static constexpr int FORMATTER_RATE_MIN_SIGNIFICANT_DECIMALS = 4;
static constexpr auto CACHE_TIMESTAMP_KEY = L"CURRENCY_CONVERTER_TIMESTAMP";
static constexpr auto CACHE_LANGCODE_KEY = L"CURRENCY_CONVERTER_LANGCODE";
@@ -128,7 +130,7 @@ CurrencyDataLoader::CurrencyDataLoader(_In_ unique_ptr<ICurrencyHttpClient> clie
m_ratioFormatter = localizationService->GetRegionalSettingsAwareDecimalFormatter();
m_ratioFormatter->IsGrouped = true;
m_ratioFormatter->IsDecimalPointAlwaysDisplayed = true;
m_ratioFormatter->FractionDigits = FORMATTER_DIGIT_COUNT;
m_ratioFormatter->FractionDigits = FORMATTER_RATE_FRACTION_PADDING;
m_ratioFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyFromToRatioFormat")->Data();
m_timestampFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyTimestampFormat")->Data();
@@ -267,6 +269,23 @@ pair<wstring, wstring> CurrencyDataLoader::GetCurrencySymbols(const UCM::Unit& u
return make_pair(symbol1, symbol2);
}
double CurrencyDataLoader::RoundCurrencyRatio(double ratio)
{
// Compute how many decimals we need to display two meaningful digits at minimum
// For example: 0.00000000342334 -> 0.000000003423, 0.000212 -> 0.000212
int numberDecimals = FORMATTER_RATE_MIN_DECIMALS;
if (ratio < 1)
{
numberDecimals = max(
FORMATTER_RATE_MIN_DECIMALS,
(int)(-log10(ratio)) + FORMATTER_RATE_MIN_SIGNIFICANT_DECIMALS);
}
unsigned long long scale = (unsigned long long)powl(10l, numberDecimals);
return (double)(round(ratio * scale) / scale);
}
pair<wstring, wstring> CurrencyDataLoader::GetCurrencyRatioEquality(_In_ const UCM::Unit& unit1, _In_ const UCM::Unit& unit2)
{
try
@@ -279,12 +298,7 @@ pair<wstring, wstring> CurrencyDataLoader::GetCurrencyRatioEquality(_In_ const U
if (iter2 != ratioMap.end())
{
double ratio = (iter2->second).ratio;
// Round the ratio to FORMATTER_DIGIT_COUNT digits using int math.
// Ex: to round 1.23456 to three digits, use
// ((int) 1.23456 * (10^3)) / (10^3)
double scale = pow(10, FORMATTER_DIGIT_COUNT);
double rounded = static_cast<int>(ratio * static_cast<int>(scale)) / scale;
double rounded = RoundCurrencyRatio(ratio);
wstring digitSymbol = wstring{ LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1') };
wstring roundedFormat = m_ratioFormatter->Format(rounded)->Data();
@@ -335,12 +349,12 @@ future<bool> CurrencyDataLoader::TryLoadDataFromCacheAsync()
}
catch (Exception ^ ex)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, ex);
TraceLogger::GetInstance().LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex);
co_return false;
}
catch (const exception& e)
{
TraceLogger::GetInstance().LogStandardException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogStandardException(ViewMode::Currency, __FUNCTIONW__, e);
co_return false;
}
catch (...)
@@ -445,12 +459,12 @@ future<bool> CurrencyDataLoader::TryLoadDataFromWebAsync()
}
catch (Exception ^ ex)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, ex);
TraceLogger::GetInstance().LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex);
co_return false;
}
catch (const exception& e)
{
TraceLogger::GetInstance().LogStandardException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogStandardException(ViewMode::Currency, __FUNCTIONW__, e);
co_return false;
}
catch (...)
@@ -466,7 +480,7 @@ future<bool> CurrencyDataLoader::TryLoadDataFromWebOverrideAsync()
if (!didLoad)
{
m_loadStatus = CurrencyLoadStatus::FailedToLoad;
TraceLogger::GetInstance().LogUserRequestedRefreshFailed();
TraceLogger::GetInstance().LogError(ViewMode::Currency, L"CurrencyDataLoader::TryLoadDataFromWebOverrideAsync", L"UserRequestedRefreshFailed");
}
co_return didLoad;
@@ -527,8 +541,11 @@ bool CurrencyDataLoader::TryParseStaticData(_In_ String ^ rawJson, _Inout_ vecto
staticData[i] = CurrencyStaticData{ countryCode, countryName, currencyCode, currencyName, currencySymbol };
}
// TODO - MSFT 8533667: this sort will be replaced by a WinRT call to sort localized strings
sort(begin(staticData), end(staticData), [](CurrencyStaticData unit1, CurrencyStaticData unit2) { return unit1.countryName < unit2.countryName; });
auto sortCountryNames = [](const UCM::CurrencyStaticData & s) {
return ref new String(s.countryName.c_str());
};
LocalizationService::GetInstance()->Sort<UCM::CurrencyStaticData>(staticData, sortCountryNames);
return true;
}

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.
#pragma once
@@ -75,6 +75,7 @@ namespace CalculatorApp
std::pair<std::wstring, std::wstring>
GetCurrencyRatioEquality(_In_ const UnitConversionManager::Unit& unit1, _In_ const UnitConversionManager::Unit& unit2) override;
std::wstring GetCurrencyTimestamp() override;
static double RoundCurrencyRatio(double ratio);
std::future<bool> TryLoadDataFromCacheAsync() override;
std::future<bool> TryLoadDataFromWebAsync() override;

View File

@@ -88,9 +88,6 @@ DateCalculatorViewModel::DateCalculatorViewModel()
if (calendar->DayOfWeek != trueDayOfWeek)
{
calendar->SetDateTime(today);
TraceLogger::GetInstance().LogDateClippedTimeDifferenceFound(
from_cx<winrt::Windows::Globalization::Calendar>(calendar),
winrt::Windows::Foundation::DateTime{ winrt::Windows::Foundation::TimeSpan{ clippedTime.UniversalTime } });
}
}

View File

@@ -118,6 +118,9 @@ void HistoryViewModel::SetCalculatorDisplay(CalculatorDisplay& calculatorDisplay
void HistoryViewModel::ShowItem(_In_ HistoryItemViewModel ^ e)
{
unsigned int index;
Items->IndexOf(e, &index);
TraceLogger::GetInstance().LogHistoryItemLoad((ViewMode)m_currentMode, ItemSize, (int)(index));
HistoryItemClicked(e);
}
@@ -149,7 +152,6 @@ void HistoryViewModel::OnHideCommand(_In_ Platform::Object ^ e)
void HistoryViewModel::OnClearCommand(_In_ Platform::Object ^ e)
{
TraceLogger::GetInstance().LogClearHistory();
if (AreHistoryShortcutsEnabled == true)
{
m_calculatorManager->ClearHistory();

View File

@@ -35,8 +35,10 @@ namespace
StringReference IsStandardPropertyName(L"IsStandard");
StringReference IsScientificPropertyName(L"IsScientific");
StringReference IsProgrammerPropertyName(L"IsProgrammer");
StringReference IsAlwaysOnTopPropertyName(L"IsAlwaysOnTop");
StringReference DisplayValuePropertyName(L"DisplayValue");
StringReference CalculationResultAutomationNamePropertyName(L"CalculationResultAutomationName");
StringReference IsBitFlipCheckedPropertyName(L"IsBitFlipChecked");
}
namespace CalculatorResourceKeys
@@ -65,6 +67,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel()
, m_HexDisplayValue(L"0")
, m_BinaryDisplayValue(L"0")
, m_OctalDisplayValue(L"0")
, m_BinaryDigits(ref new Vector<bool>(64, false))
, m_standardCalculatorManager(&m_calculatorDisplay, &m_resourceProvider)
, m_ExpressionTokens(ref new Vector<DisplayExpressionToken ^>())
, m_MemorizedNumbers(ref new Vector<MemoryItemViewModel ^>())
@@ -72,10 +75,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel()
, m_IsFToEChecked(false)
, m_isShiftChecked(false)
, m_IsShiftProgrammerChecked(false)
, m_IsQwordEnabled(true)
, m_IsDwordEnabled(true)
, m_IsWordEnabled(true)
, m_IsByteEnabled(true)
, m_valueBitLength(BitLength::BitLengthQWord)
, m_isBitFlipChecked(false)
, m_isBinaryBitFlippingEnabled(false)
, m_CurrentRadixType(RADIX_TYPE::DEC_RADIX)
@@ -201,7 +201,12 @@ void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ wstring const& displayS
// not match what the narrator is saying
m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue, localizedDisplayStringValue, isError);
DisplayValue = localizedDisplayStringValue;
AreAlwaysOnTopResultsUpdated = false;
if (DisplayValue != localizedDisplayStringValue)
{
DisplayValue = localizedDisplayStringValue;
AreAlwaysOnTopResultsUpdated = true;
}
IsInError = isError;
@@ -414,7 +419,7 @@ void StandardCalculatorViewModel::SetMemorizedNumbers(const vector<wstring>& new
memorySlot->Value = Utils::LRO + ref new String(stringValue.c_str()) + Utils::PDF;
MemorizedNumbers->InsertAt(0, memorySlot);
IsMemoryEmpty = false;
IsMemoryEmpty = IsAlwaysOnTop;
// Update the slot position for the rest of the slots
for (unsigned int i = 1; i < MemorizedNumbers->Size; i++)
@@ -599,8 +604,6 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
Command cmdenum = ConvertToOperatorsEnum(numOpEnum);
TraceLogger::GetInstance().UpdateFunctionUsage((int)numOpEnum);
if (IsInError)
{
m_standardCalculatorManager.SendCommand(Command::CommandCLEAR);
@@ -668,31 +671,12 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
m_isLastOperationHistoryLoad = false;
}
TraceLogger::GetInstance().UpdateButtonUsage(numOpEnum, GetCalculatorMode());
m_standardCalculatorManager.SendCommand(cmdenum);
}
}
}
int StandardCalculatorViewModel::GetBitLengthType()
{
if (IsQwordEnabled)
{
return QwordType;
}
else if (IsDwordEnabled)
{
return DwordType;
}
else if (IsWordEnabled)
{
return WordType;
}
else
{
return ByteType;
}
}
int StandardCalculatorViewModel::GetNumberBase()
{
if (CurrentRadixType == HEX_RADIX)
@@ -723,9 +707,10 @@ void StandardCalculatorViewModel::OnCopyCommand(Object ^ parameter)
void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
{
auto that(this);
ViewMode mode;
int NumberBase = -1;
int bitLengthType = -1;
BitLength bitLengthType = BitLength::BitLengthUnknown;
if (IsScientific)
{
mode = ViewMode::Scientific;
@@ -734,7 +719,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
{
mode = ViewMode::Programmer;
NumberBase = GetNumberBase();
bitLengthType = GetBitLengthType();
bitLengthType = m_valueBitLength;
}
else
{
@@ -748,7 +733,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
// Ensure that the paste happens on the UI thread
CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType)
.then([this, mode](String ^ pastedString) { OnPaste(pastedString, mode); }, concurrency::task_continuation_context::use_current());
.then([that, mode](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
}
CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum(NumbersAndOperatorsEnum operation)
@@ -756,7 +741,7 @@ CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum(
return safe_cast<Command>(operation);
}
void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
void StandardCalculatorViewModel::OnPaste(String ^ pastedString)
{
// If pastedString is invalid("NoOp") then display pasteError else process the string
if (pastedString == StringReference(CopyPasteManager::PasteErrorString))
@@ -765,7 +750,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
return;
}
TraceLogger::GetInstance().LogValidInputPasted(mode);
TraceLogger::GetInstance().LogInputPasted(GetCalculatorMode());
bool isFirstLegalChar = true;
m_standardCalculatorManager.SendCommand(Command::CommandCENTR);
bool sendNegate = false;
@@ -884,7 +869,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
// Handle exponent and exponent sign (...e+... or ...e-... or ...e...)
if (mappedNumOp == NumbersAndOperatorsEnum::Exp)
{
//Check the following item
// Check the following item
switch (MapCharacterToButtonId(*(it + 1), canSendNegate))
{
case NumbersAndOperatorsEnum::Subtract:
@@ -896,7 +881,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
break;
case NumbersAndOperatorsEnum::Add:
{
//Nothing to do, skip to the next item
// Nothing to do, skip to the next item
++it;
}
break;
@@ -911,8 +896,7 @@ void StandardCalculatorViewModel::OnClearMemoryCommand(Object ^ parameter)
{
m_standardCalculatorManager.MemorizedNumberClearAll();
int windowId = Utils::GetWindowId();
TraceLogger::GetInstance().LogMemoryClearAll(windowId);
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::MemoryCleared, m_localizedMemoryCleared);
Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement);
@@ -1046,8 +1030,7 @@ void StandardCalculatorViewModel::OnMemoryButtonPressed()
{
m_standardCalculatorManager.MemorizeNumber();
int windowId = Utils::GetWindowId();
TraceLogger::GetInstance().InsertIntoMemoryMap(windowId, IsStandard, IsScientific, IsProgrammer);
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::MemorySave, m_localizedMemorySavedAutomationFormat, m_DisplayValue->Data());
@@ -1079,49 +1062,31 @@ void StandardCalculatorViewModel::OnMemoryItemPressed(Object ^ memoryItemPositio
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
m_standardCalculatorManager.MemorizedNumberLoad(boxedPosition->Value);
HideMemoryClicked();
int windowId = Utils::GetWindowId();
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
auto mode = IsStandard ? ViewMode::Standard : IsScientific ? ViewMode::Scientific : ViewMode::Programmer;
TraceLogger::GetInstance().LogMemoryItemLoad(mode, MemorizedNumbers->Size, boxedPosition->Value);
}
}
void StandardCalculatorViewModel::OnMemoryAdd(Object ^ memoryItemPosition)
{
// M+ will add display to memorylist if memory list is empty.
int windowId = Utils::GetWindowId();
if (MemorizedNumbers)
{
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
if (MemorizedNumbers->Size > 0)
{
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
TraceLogger::GetInstance().UpdateMemoryMap(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer);
}
else
{
TraceLogger::GetInstance().InsertIntoMemoryMap(windowId, IsStandard, IsScientific, IsProgrammer);
}
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryAdd, GetCalculatorMode());
m_standardCalculatorManager.MemorizedNumberAdd(boxedPosition->Value);
}
}
void StandardCalculatorViewModel::OnMemorySubtract(Object ^ memoryItemPosition)
{
int windowId = Utils::GetWindowId();
// M- will add negative of displayed number to memorylist if memory list is empty.
if (MemorizedNumbers)
{
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
if (MemorizedNumbers->Size > 0)
{
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
TraceLogger::GetInstance().UpdateMemoryMap(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer);
}
else
{
TraceLogger::GetInstance().InsertIntoMemoryMap(windowId, IsStandard, IsScientific, IsProgrammer);
}
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemorySubtract, GetCalculatorMode());
m_standardCalculatorManager.MemorizedNumberSubtract(boxedPosition->Value);
}
}
@@ -1130,7 +1095,6 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
{
if (MemorizedNumbers && MemorizedNumbers->Size > 0)
{
int windowId = Utils::GetWindowId();
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
if (boxedPosition->Value >= 0)
@@ -1148,9 +1112,7 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
{
IsMemoryEmpty = true;
}
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
TraceLogger::GetInstance().DeleteFromMemoryMap(windowId, boxedPosition->Value);
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode());
wstring localizedIndex = to_wstring(boxedPosition->Value + 1);
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex);
@@ -1191,6 +1153,11 @@ void StandardCalculatorViewModel::OnPropertyChanged(String ^ propertyname)
RaisePropertyChanged(CalculationResultAutomationNamePropertyName);
Announcement = GetDisplayUpdatedNarratorAnnouncement();
}
else if (propertyname == IsBitFlipCheckedPropertyName)
{
TraceLogger::GetInstance().UpdateButtonUsage(
IsBitFlipChecked ? NumbersAndOperatorsEnum::BitflipButton : NumbersAndOperatorsEnum::FullKeypadButton, ViewMode::Programmer);
}
}
void StandardCalculatorViewModel::SetCalculatorType(ViewMode targetState)
@@ -1223,7 +1190,7 @@ void StandardCalculatorViewModel::SetCalculatorType(ViewMode targetState)
}
}
String^ StandardCalculatorViewModel::GetRawDisplayValue()
String ^ StandardCalculatorViewModel::GetRawDisplayValue()
{
if (IsInError)
{
@@ -1654,6 +1621,7 @@ wstring StandardCalculatorViewModel::AddPadding(wstring binaryString)
void StandardCalculatorViewModel::UpdateProgrammerPanelDisplay()
{
constexpr int32_t precision = 64;
wstring hexDisplayString;
wstring decimalDisplayString;
wstring octalDisplayString;
@@ -1661,8 +1629,7 @@ void StandardCalculatorViewModel::UpdateProgrammerPanelDisplay()
if (!IsInError)
{
// we want the precision to be set to maximum value so that the autoconversions result as desired
int32_t precision = 64;
if (m_standardCalculatorManager.GetResultForRadix(16, precision) == L"")
if ((hexDisplayString = m_standardCalculatorManager.GetResultForRadix(16, precision, true)) == L"")
{
hexDisplayString = DisplayValue->Data();
decimalDisplayString = DisplayValue->Data();
@@ -1671,10 +1638,9 @@ void StandardCalculatorViewModel::UpdateProgrammerPanelDisplay()
}
else
{
hexDisplayString = m_standardCalculatorManager.GetResultForRadix(16, precision);
decimalDisplayString = m_standardCalculatorManager.GetResultForRadix(10, precision);
octalDisplayString = m_standardCalculatorManager.GetResultForRadix(8, precision);
binaryDisplayString = m_standardCalculatorManager.GetResultForRadix(2, precision);
decimalDisplayString = m_standardCalculatorManager.GetResultForRadix(10, precision, true);
octalDisplayString = m_standardCalculatorManager.GetResultForRadix(8, precision, true);
binaryDisplayString = m_standardCalculatorManager.GetResultForRadix(2, precision, true);
}
}
const auto& localizer = LocalizationSettings::GetInstance();
@@ -1693,6 +1659,17 @@ void StandardCalculatorViewModel::UpdateProgrammerPanelDisplay()
DecDisplayValue_AutomationName = GetLocalizedStringFormat(m_localizedDecimalAutomationFormat, DecimalDisplayValue);
OctDisplayValue_AutomationName = GetLocalizedStringFormat(m_localizedOctalAutomationFormat, GetNarratorStringReadRawNumbers(OctalDisplayValue));
BinDisplayValue_AutomationName = GetLocalizedStringFormat(m_localizedBinaryAutomationFormat, GetNarratorStringReadRawNumbers(BinaryDisplayValue));
auto binaryValueArray = ref new Vector<bool>(64, false);
auto binaryValue = m_standardCalculatorManager.GetResultForRadix(2, precision, false);
int i = 0;
// To get bit 0, grab from opposite end of string.
for (std::wstring::reverse_iterator it = binaryValue.rbegin(); it != binaryValue.rend(); ++it)
{
binaryValueArray->SetAt(i++, *it == L'1');
}
BinaryDigits = binaryValueArray;
}
void StandardCalculatorViewModel::SwitchAngleType(NumbersAndOperatorsEnum num)
@@ -1884,3 +1861,44 @@ NarratorAnnouncement ^ StandardCalculatorViewModel::GetDisplayUpdatedNarratorAnn
return CalculatorAnnouncement::GetDisplayUpdatedAnnouncement(announcement);
}
ViewMode StandardCalculatorViewModel::GetCalculatorMode()
{
if (IsStandard)
{
return ViewMode::Standard;
}
else if (IsScientific)
{
return ViewMode::Scientific;
}
return ViewMode::Programmer;
}
void StandardCalculatorViewModel::ValueBitLength::set(CalculatorApp::Common::BitLength value)
{
if (m_valueBitLength != value)
{
m_valueBitLength = value;
RaisePropertyChanged(L"ValueBitLength");
switch (value)
{
case BitLength::BitLengthQWord:
ButtonPressed->Execute(NumbersAndOperatorsEnum::Qword);
break;
case BitLength::BitLengthDWord:
ButtonPressed->Execute(NumbersAndOperatorsEnum::Dword);
break;
case BitLength::BitLengthWord:
ButtonPressed->Execute(NumbersAndOperatorsEnum::Word);
break;
case BitLength::BitLengthByte:
ButtonPressed->Execute(NumbersAndOperatorsEnum::Byte);
break;
}
// update memory list according to bit length
SetMemorizedNumbersString();
}
}

View File

@@ -9,6 +9,7 @@
#include "Common/CalculatorButtonUser.h"
#include "HistoryViewModel.h"
#include "MemoryItemViewModel.h"
#include "Common/BitLength.h"
namespace CalculatorFunctionalTests
{
@@ -40,7 +41,6 @@ namespace CalculatorApp
StandardCalculatorViewModel();
void UpdateOperand(int pos, Platform::String ^ text);
void UpdatecommandsInRecordingMode();
int GetBitLengthType();
int GetNumberBase();
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
@@ -54,6 +54,7 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(Platform::String ^, HexDisplayValue);
OBSERVABLE_PROPERTY_RW(Platform::String ^, OctalDisplayValue);
OBSERVABLE_NAMED_PROPERTY_RW(Platform::String ^, BinaryDisplayValue);
OBSERVABLE_NAMED_PROPERTY_R(Windows::Foundation::Collections::IVector<bool> ^, BinaryDigits);
OBSERVABLE_PROPERTY_RW(Platform::String ^, HexDisplayValue_AutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String ^, DecDisplayValue_AutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String ^, OctDisplayValue_AutomationName);
@@ -72,12 +73,9 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(Platform::String ^, CalculationResultAutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String ^, CalculationExpressionAutomationName);
OBSERVABLE_PROPERTY_RW(bool, IsShiftProgrammerChecked);
OBSERVABLE_PROPERTY_RW(bool, IsQwordEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsDwordEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsWordEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsByteEnabled);
OBSERVABLE_PROPERTY_RW(int, CurrentRadixType);
OBSERVABLE_PROPERTY_RW(bool, AreTokensUpdated);
OBSERVABLE_PROPERTY_RW(bool, AreAlwaysOnTopResultsUpdated);
OBSERVABLE_PROPERTY_RW(bool, AreHistoryShortcutsEnabled);
OBSERVABLE_PROPERTY_RW(bool, AreProgrammerRadixOperatorsEnabled);
OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::Automation::NarratorAnnouncement ^, Announcement);
@@ -127,6 +125,13 @@ namespace CalculatorApp
}
}
}
static property Platform::String ^ IsBitFlipCheckedPropertyName
{
Platform::String ^ get()
{
return Platform::StringReference(L"IsBitFlipChecked");
}
}
property bool IsBinaryBitFlippingEnabled
{
@@ -144,6 +149,15 @@ namespace CalculatorApp
}
}
property CalculatorApp::Common::BitLength ValueBitLength
{
CalculatorApp::Common::BitLength get()
{
return m_valueBitLength;
}
void set(CalculatorApp::Common::BitLength value);
}
property bool IsStandard
{
bool get()
@@ -212,6 +226,29 @@ namespace CalculatorApp
}
}
}
static property Platform::String ^ IsProgrammerPropertyName
{
Platform::String ^ get()
{
return Platform::StringReference(L"IsProgrammer");
}
}
property bool IsAlwaysOnTop
{
bool get()
{
return m_isAlwaysOnTop;
}
void set(bool value)
{
if (m_isAlwaysOnTop != value)
{
m_isAlwaysOnTop = value;
RaisePropertyChanged(L"IsAlwaysOnTop");
}
}
}
property bool IsEditingEnabled
{
@@ -317,7 +354,7 @@ namespace CalculatorApp
}
}
internal : void OnPaste(Platform::String ^ pastedString, CalculatorApp::Common::ViewMode mode);
internal : void OnPaste(Platform::String ^ pastedString);
void OnCopyCommand(Platform::Object ^ parameter);
void OnPasteCommand(Platform::Object ^ parameter);
@@ -348,7 +385,6 @@ namespace CalculatorApp
void OnBinaryOperatorReceived();
void OnMemoryItemChanged(unsigned int indexOfMemory);
Platform::String ^ GetLocalizedStringFormat(Platform::String ^ format, Platform::String ^ displayValue);
void OnPropertyChanged(Platform::String ^ propertyname);
void SetCalculatorType(CalculatorApp::Common::ViewMode targetState);
@@ -407,6 +443,7 @@ namespace CalculatorApp
bool m_isStandard;
bool m_isScientific;
bool m_isProgrammer;
bool m_isAlwaysOnTop;
bool m_isBinaryBitFlippingEnabled;
bool m_isBitFlipChecked;
bool m_isShiftChecked;
@@ -416,6 +453,7 @@ namespace CalculatorApp
bool m_operandUpdated;
bool m_completeTextSelection;
bool m_isLastOperationHistoryLoad;
CalculatorApp::Common::BitLength m_valueBitLength;
Platform::String ^ m_selectedExpressionLastData;
Common::DisplayExpressionToken ^ m_selectedExpressionToken;
@@ -451,6 +489,8 @@ namespace CalculatorApp
bool IsViewPinned();
void SetViewPinnedState(bool pinned);
CalculatorApp::Common::ViewMode GetCalculatorMode();
friend class CalculatorDisplay;
friend class CalculatorFunctionalTests::HistoryTests;
friend class CalculatorUnitTests::MultiWindowUnitTests;

View File

@@ -148,7 +148,6 @@ UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConver
Unit2AutomationName = m_localizedOutputUnitName;
IsDecimalEnabled = true;
m_IsFirstTime = true;
m_model->Initialize();
PopulateData();
}
@@ -156,7 +155,6 @@ UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConver
void UnitConverterViewModel::ResetView()
{
m_model->SendCommand(UCM::Command::Reset);
m_IsFirstTime = true;
OnCategoryChanged(nullptr);
}
@@ -239,15 +237,8 @@ void UnitConverterViewModel::OnUnitChanged(Object ^ parameter)
// End timer to show results immediately
m_supplementaryResultsTimer->Cancel();
}
if (!m_IsFirstTime)
{
SaveUserPreferences();
}
else
{
RestoreUserPreferences();
m_IsFirstTime = false;
}
SaveUserPreferences();
}
void UnitConverterViewModel::OnSwitchActive(Platform::Object ^ unused)
@@ -502,6 +493,8 @@ void UnitConverterViewModel::OnButtonPressed(Platform::Object ^ parameter)
}
m_model->SendCommand(command);
TraceLogger::GetInstance().LogConverterInputReceived(Mode);
}
void UnitConverterViewModel::OnCopyCommand(Platform::Object ^ parameter)
@@ -523,7 +516,7 @@ void UnitConverterViewModel::OnPasteCommand(Platform::Object ^ parameter)
// EventWriteClipboardPaste_Start();
// Any converter ViewMode is fine here.
CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode))
.then([this](String ^ pastedString) { OnPaste(pastedString, m_Mode); }, concurrency::task_continuation_context::use_current());
.then([this](String ^ pastedString) { OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
}
void UnitConverterViewModel::InitializeView()
@@ -882,7 +875,7 @@ NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wch
return mappedValue;
}
void UnitConverterViewModel::OnPaste(String ^ stringToPaste, ViewMode mode)
void UnitConverterViewModel::OnPaste(String ^ stringToPaste)
{
// If pastedString is invalid("NoOp") then display pasteError else process the string
if (stringToPaste == StringReference(CopyPasteManager::PasteErrorString))
@@ -891,7 +884,7 @@ void UnitConverterViewModel::OnPaste(String ^ stringToPaste, ViewMode mode)
return;
}
TraceLogger::GetInstance().LogValidInputPasted(mode);
TraceLogger::GetInstance().LogInputPasted(Mode);
bool isFirstLegalChar = true;
bool sendNegate = false;
wstring accumulation = L"";
@@ -1014,7 +1007,6 @@ void UnitConverterViewModel::StartConversionResultTimer()
{
String ^ valueFrom = m_Value1Active ? m_Value1 : m_Value2;
String ^ valueTo = m_Value1Active ? m_Value2 : m_Value1;
TraceLogger::GetInstance().LogConversionResult(valueFrom->Data(), UnitFrom->ToString()->Data(), valueTo->Data(), UnitTo->ToString()->Data());
}
});
}

View File

@@ -204,7 +204,7 @@ namespace CalculatorApp
NumbersAndOperatorsEnum MapCharacterToButtonId(const wchar_t ch, bool& canSendNegate);
void DisplayPasteError();
void OnValueActivated(IActivatable ^ control);
void OnPaste(Platform::String ^ stringToPaste, CalculatorApp::Common::ViewMode mode);
void OnPaste(Platform::String ^ stringToPaste);
void OnCopyCommand(Platform::Object ^ parameter);
void OnPasteCommand(Platform::Object ^ parameter);
@@ -311,8 +311,6 @@ namespace CalculatorApp
std::wstring m_valueFromUnlocalized;
std::wstring m_valueToUnlocalized;
bool m_relocalizeStringOnSwitch;
// For Saving the User Preferences only if the Unit converter ViewModel is initialised for the first time
bool m_IsFirstTime;
Platform::String ^ m_localizedValueFromFormat;
Platform::String ^ m_localizedValueFromDecimalFormat;

View File

@@ -30,6 +30,7 @@
#include <concrt.h>
#include <regex>
#include <iterator>
#include <intsafe.h>
// C++\WinRT Headers
#include "winrt/base.h"
#include "winrt/Windows.Foundation.Diagnostics.h"