diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp
index 20790f8..4752ec9 100644
--- a/src/CalcManager/CEngine/scicomm.cpp
+++ b/src/CalcManager/CEngine/scicomm.cpp
@@ -951,7 +951,7 @@ int CCalcEngine::GetCurrentRadix()
return m_radix;
}
-wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision)
+wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix)
{
Rational rat = (m_bRecord ? m_input.ToRational(m_radix, m_precision) : m_currentVal);
@@ -964,7 +964,14 @@ wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision)
ChangeConstants(m_radix, m_precision);
}
- return GroupDigitsPerRadix(numberString, radix);
+ if (groupDigitsPerRadix)
+ {
+ return GroupDigitsPerRadix(numberString, radix);
+ }
+ else
+ {
+ return numberString;
+ }
}
wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
diff --git a/src/CalcManager/CalculatorManager.cpp b/src/CalcManager/CalculatorManager.cpp
index 12df63b..71eebd2 100644
--- a/src/CalcManager/CalculatorManager.cpp
+++ b/src/CalcManager/CalculatorManager.cpp
@@ -613,9 +613,9 @@ namespace CalculationManager
}
}
- wstring CalculatorManager::GetResultForRadix(uint32_t radix, int32_t precision)
+ wstring CalculatorManager::GetResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix)
{
- return m_currentCalculatorEngine ? m_currentCalculatorEngine->GetCurrentResultForRadix(radix, precision) : L"";
+ return m_currentCalculatorEngine ? m_currentCalculatorEngine->GetCurrentResultForRadix(radix, precision, groupDigitsPerRadix) : L"";
}
void CalculatorManager::SetPrecision(int32_t precision)
diff --git a/src/CalcManager/CalculatorManager.h b/src/CalcManager/CalculatorManager.h
index d34d2e3..358c2da 100644
--- a/src/CalcManager/CalculatorManager.h
+++ b/src/CalcManager/CalculatorManager.h
@@ -124,7 +124,7 @@ namespace CalculationManager
}
void SetRadix(RADIX_TYPE iRadixType);
void SetMemorizedNumbersString();
- std::wstring GetResultForRadix(uint32_t radix, int32_t precision);
+ std::wstring GetResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix);
void SetPrecision(int32_t precision);
void UpdateMaxIntDigits();
wchar_t DecimalSeparator();
diff --git a/src/CalcManager/Header Files/CalcEngine.h b/src/CalcManager/Header Files/CalcEngine.h
index 9da5762..2444185 100644
--- a/src/CalcManager/Header Files/CalcEngine.h
+++ b/src/CalcManager/Header Files/CalcEngine.h
@@ -75,7 +75,7 @@ public:
void SettingsChanged();
bool IsCurrentTooBigForTrig();
int GetCurrentRadix();
- std::wstring GetCurrentResultForRadix(uint32_t radix, int32_t precision);
+ std::wstring GetCurrentResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix);
void ChangePrecision(int32_t precision)
{
m_precision = precision;
diff --git a/src/CalcViewModel/CalcViewModel.vcxproj b/src/CalcViewModel/CalcViewModel.vcxproj
index c9fae3c..ec2a2a2 100644
--- a/src/CalcViewModel/CalcViewModel.vcxproj
+++ b/src/CalcViewModel/CalcViewModel.vcxproj
@@ -322,6 +322,7 @@
+
@@ -439,4 +440,4 @@
-
+
\ No newline at end of file
diff --git a/src/CalcViewModel/CalcViewModel.vcxproj.filters b/src/CalcViewModel/CalcViewModel.vcxproj.filters
index bd0d75f..6c723f1 100644
--- a/src/CalcViewModel/CalcViewModel.vcxproj.filters
+++ b/src/CalcViewModel/CalcViewModel.vcxproj.filters
@@ -219,6 +219,9 @@
DataLoaders
+
+ Common
+
diff --git a/src/CalcViewModel/Common/BitLength.h b/src/CalcViewModel/Common/BitLength.h
new file mode 100644
index 0000000..8c38e7e
--- /dev/null
+++ b/src/CalcViewModel/Common/BitLength.h
@@ -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,
+ };
+ }
+}
diff --git a/src/CalcViewModel/Common/CopyPasteManager.cpp b/src/CalcViewModel/Common/CopyPasteManager.cpp
index 8c00d41..89c401d 100644
--- a/src/CalcViewModel/Common/CopyPasteManager.cpp
+++ b/src/CalcViewModel/Common/CopyPasteManager.cpp
@@ -65,7 +65,7 @@ void CopyPasteManager::CopyToClipboard(String ^ stringToCopy)
Clipboard::SetContent(dataPackage);
}
-task CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
+task CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
// Retrieve the text in the clipboard
auto dataPackageView = Clipboard::GetContent();
@@ -97,14 +97,14 @@ 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)
{
@@ -241,7 +241,7 @@ vector CopyPasteManager::ExtractOperands(const wstring& pasteExpression
return operands;
}
-bool CopyPasteManager::ExpressionRegExMatch(vector operands, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
+bool CopyPasteManager::ExpressionRegExMatch(vector operands, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
if (operands.empty())
{
@@ -317,7 +317,7 @@ bool CopyPasteManager::ExpressionRegExMatch(vector operands, ViewMode m
return expMatched;
}
-pair CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
+pair 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 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;
}
diff --git a/src/CalcViewModel/Common/CopyPasteManager.h b/src/CalcViewModel/Common/CopyPasteManager.h
index 0359e18..9571cdb 100644
--- a/src/CalcViewModel/Common/CopyPasteManager.h
+++ b/src/CalcViewModel/Common/CopyPasteManager.h
@@ -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,14 +38,18 @@ 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
ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode);
@@ -57,13 +58,13 @@ 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 std::pair 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(
diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp
index c9717b8..af2c7bc 100644
--- a/src/CalcViewModel/StandardCalculatorViewModel.cpp
+++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp
@@ -67,6 +67,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel()
, m_HexDisplayValue(L"0")
, m_BinaryDisplayValue(L"0")
, m_OctalDisplayValue(L"0")
+ , m_BinaryDigits(ref new Vector(64, false))
, m_standardCalculatorManager(&m_calculatorDisplay, &m_resourceProvider)
, m_ExpressionTokens(ref new Vector())
, m_MemorizedNumbers(ref new Vector())
@@ -74,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)
@@ -679,26 +677,6 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
}
}
-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)
@@ -729,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;
@@ -740,7 +719,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
{
mode = ViewMode::Programmer;
NumberBase = GetNumberBase();
- bitLengthType = GetBitLengthType();
+ bitLengthType = m_valueBitLength;
}
else
{
@@ -754,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); }, 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)
@@ -1642,6 +1621,7 @@ wstring StandardCalculatorViewModel::AddPadding(wstring binaryString)
void StandardCalculatorViewModel::UpdateProgrammerPanelDisplay()
{
+ constexpr int32_t precision = 64;
wstring hexDisplayString;
wstring decimalDisplayString;
wstring octalDisplayString;
@@ -1649,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();
@@ -1659,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();
@@ -1681,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(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)
@@ -1885,3 +1874,31 @@ ViewMode StandardCalculatorViewModel::GetCalculatorMode()
}
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();
+ }
+}
diff --git a/src/CalcViewModel/StandardCalculatorViewModel.h b/src/CalcViewModel/StandardCalculatorViewModel.h
index 350155d..77480dd 100644
--- a/src/CalcViewModel/StandardCalculatorViewModel.h
+++ b/src/CalcViewModel/StandardCalculatorViewModel.h
@@ -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 ^, BinaryDigits);
OBSERVABLE_PROPERTY_RW(Platform::String ^, HexDisplayValue_AutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String ^, DecDisplayValue_AutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String ^, OctDisplayValue_AutomationName);
@@ -72,10 +73,6 @@ 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);
@@ -128,6 +125,13 @@ namespace CalculatorApp
}
}
}
+ static property Platform::String ^ IsBitFlipCheckedPropertyName
+ {
+ Platform::String ^ get()
+ {
+ return Platform::StringReference(L"IsBitFlipChecked");
+ }
+ }
property bool IsBinaryBitFlippingEnabled
{
@@ -145,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()
@@ -213,6 +226,13 @@ namespace CalculatorApp
}
}
}
+ static property Platform::String ^ IsProgrammerPropertyName
+ {
+ Platform::String ^ get()
+ {
+ return Platform::StringReference(L"IsProgrammer");
+ }
+ }
property bool IsAlwaysOnTop
{
@@ -433,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;
diff --git a/src/Calculator/Calculator.vcxproj b/src/Calculator/Calculator.vcxproj
index d5493c4..1a35583 100644
--- a/src/Calculator/Calculator.vcxproj
+++ b/src/Calculator/Calculator.vcxproj
@@ -240,7 +240,6 @@
-
@@ -370,7 +369,6 @@
-
diff --git a/src/Calculator/Calculator.vcxproj.filters b/src/Calculator/Calculator.vcxproj.filters
index 0ce2b95..46e1a69 100644
--- a/src/Calculator/Calculator.vcxproj.filters
+++ b/src/Calculator/Calculator.vcxproj.filters
@@ -318,9 +318,6 @@
Controls
-
- Converters
-
Converters
@@ -362,9 +359,6 @@
-
- Converters
-
Controls
diff --git a/src/Calculator/Converters/BitFlipAutomationNameConverter.cpp b/src/Calculator/Converters/BitFlipAutomationNameConverter.cpp
deleted file mode 100644
index 6059ef0..0000000
--- a/src/Calculator/Converters/BitFlipAutomationNameConverter.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-#include "pch.h"
-#include "CalcViewModel/Common/AppResourceProvider.h"
-#include "CalcViewModel/Common/LocalizationSettings.h"
-#include "BitFlipAutomationNameConverter.h"
-
-using namespace CalculatorApp::Common;
-using namespace CalculatorApp::Converters;
-using namespace Platform;
-using namespace std;
-using namespace Windows::ApplicationModel::Resources;
-using namespace Windows::Foundation;
-using namespace Windows::UI::Xaml::Interop;
-
-// returns automationName in form "Nth bit Value zero/one" depending if bit is set/unset at corresponding index of binary display
-Object ^ BitFlipAutomationNameConverter::Convert(_In_ Object ^ value, TypeName targetType, _In_ Object ^ parameter, _In_ String ^ language)
-{
- auto resourceLoader = AppResourceProvider::GetInstance();
-
- // initialising the updated display with 64 bits of zeros
- wstring updatedBinaryDisplay(64, L'0');
-
- const auto& localizationSettings = LocalizationSettings::GetInstance();
- wchar_t ch0 = localizationSettings.GetDigitSymbolFromEnUsDigit('0');
- wchar_t ch1 = localizationSettings.GetDigitSymbolFromEnUsDigit('1');
-
- String ^ indexName = resourceLoader.GetResourceString(static_cast(parameter));
- String ^ bitName = resourceLoader.GetResourceString(L"BitAutomationName");
- String ^ valueName = resourceLoader.GetResourceString(L"ValueAutomationName");
- String ^ zero = resourceLoader.GetResourceString(L"BinaryZeroValueAutomationName");
- String ^ one = resourceLoader.GetResourceString(L"BinaryOneValueAutomationName");
- if ((value != nullptr) && (parameter != nullptr))
- {
- wstring binaryDisplay = (static_cast(value))->Data();
- wstring indexString = (static_cast(parameter))->Data();
- wstringstream converter;
- converter << indexString;
- unsigned int index;
- converter >> index;
- unsigned int binaryLength = 0;
-
- // remove all the characters except 0 and 1 from the array.
- for (wchar_t bit : binaryDisplay)
- {
- if ((bit == ch1) || (bit == ch0))
- {
- updatedBinaryDisplay[binaryLength++] = bit;
- }
- if (binaryLength == 63)
- {
- break;
- }
- }
-
- // return if binaryDisplay is empty
- if (binaryLength == 0)
- {
- return (indexName + bitName + valueName + zero);
- }
-
- // if index is more than the length of binary display return automation name with zero
- if (index >= binaryLength)
- {
- return (indexName + bitName + valueName + zero);
- }
- // if bit is set return automation name with one else return zero
- if (updatedBinaryDisplay[binaryLength - index - 1] == ch1)
- {
- return (indexName + bitName + valueName + one);
- }
- }
- return (indexName + bitName + valueName + zero);
-}
-
-Object ^ BitFlipAutomationNameConverter::ConvertBack(_In_ Object ^ value, TypeName targetType, _In_ Object ^ parameter, _In_ String ^ language)
-{
- return value;
-}
diff --git a/src/Calculator/Converters/BitFlipAutomationNameConverter.h b/src/Calculator/Converters/BitFlipAutomationNameConverter.h
deleted file mode 100644
index 101779e..0000000
--- a/src/Calculator/Converters/BitFlipAutomationNameConverter.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-#pragma once
-
-namespace CalculatorApp
-{
- namespace Converters
- {
- ///
- /// Value converter that translates binary value to automation name for a bit.
- ///
- [Windows::Foundation::Metadata::WebHostHidden] public ref class BitFlipAutomationNameConverter sealed : Windows::UI::Xaml::Data::IValueConverter
- {
- public:
- virtual Platform::Object
- ^ Convert(
- _In_ Platform::Object ^ value,
- Windows::UI::Xaml::Interop::TypeName targetType,
- _In_ Platform::Object ^ parameter,
- _In_ Platform::String ^ language);
- virtual Platform::Object
- ^ ConvertBack(
- _In_ Platform::Object ^ value,
- Windows::UI::Xaml::Interop::TypeName targetType,
- _In_ Platform::Object ^ parameter,
- _In_ Platform::String ^ language);
- };
- }
-}
diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw
index 96262f2..4b24313 100644
--- a/src/Calculator/Resources/en-US/Resources.resw
+++ b/src/Calculator/Resources/en-US/Resources.resw
@@ -545,276 +545,268 @@
Insert
{Locked}This is the alternate shortcut for paste, SHIFT+Insert
-
- Bit
- Sub-string used in automation name for each bit in bit flip
+
+ %1, value %2
+ {Locked="%1","%2"}. String used in automation name for each bit in bit flip. %1 will be replaced by the position of the bit (1st bit, 3rd bit), %2 by a binary value (1 or 0)
-
- Value
- Sub-string used in automation name for each bit in bit flip
+
+ %1 bit
+ {Locked="%1"}. Sub-string used to indicate the position of a bit (e.g. 1st bit, 2nd bit...)
-
- Zero
- Sub-string used in automation name for each bit in bit flip
-
-
- One
- Sub-string used in automation name for each bit in bit flip
-
-
- 63rd
+
+ 63rd
Sub-string used in automation name for 63 bit in bit flip
- 62nd
+ 62nd
Sub-string used in automation name for 62 bit in bit flip
- 61st
+ 61st
Sub-string used in automation name for 61 bit in bit flip
- 60th
+ 60th
Sub-string used in automation name for 60 bit in bit flip
- 59th
+ 59th
Sub-string used in automation name for 59 bit in bit flip
- 58th
+ 58th
Sub-string used in automation name for 58 bit in bit flip
- 57th
+ 57th
Sub-string used in automation name for 57 bit in bit flip
- 56th
+ 56th
Sub-string used in automation name for 56 bit in bit flip
- 55th
+ 55th
Sub-string used in automation name for 55 bit in bit flip
- 54th
+ 54th
Sub-string used in automation name for 54 bit in bit flip
- 53rd
+ 53rd
Sub-string used in automation name for 53 bit in bit flip
- 52nd
+ 52nd
Sub-string used in automation name for 52 bit in bit flip
- 51st
+ 51st
Sub-string used in automation name for 51 bit in bit flip
- 50th
+ 50th
Sub-string used in automation name for 50 bit in bit flip
- 49th
+ 49th
Sub-string used in automation name for 49 bit in bit flip
- 48th
+ 48th
Sub-string used in automation name for 48 bit in bit flip
- 47th
+ 47th
Sub-string used in automation name for 47 bit in bit flip
- 46th
+ 46th
Sub-string used in automation name for 46 bit in bit flip
- 45th
+ 45th
Sub-string used in automation name for 45 bit in bit flip
- 44th
+ 44th
Sub-string used in automation name for 44 bit in bit flip
- 43rd
+ 43rd
Sub-string used in automation name for 43 bit in bit flip
- 42nd
+ 42nd
Sub-string used in automation name for 42 bit in bit flip
- 41st
+ 41st
Sub-string used in automation name for 41 bit in bit flip
- 40th
+ 40th
Sub-string used in automation name for 40 bit in bit flip
- 39th
+ 39th
Sub-string used in automation name for 39 bit in bit flip
- 38th
+ 38th
Sub-string used in automation name for 38 bit in bit flip
- 37th
+ 37th
Sub-string used in automation name for 37 bit in bit flip
- 36th
+ 36th
Sub-string used in automation name for 36 bit in bit flip
- 35th
+ 35th
Sub-string used in automation name for 35 bit in bit flip
- 34th
+ 34th
Sub-string used in automation name for 34 bit in bit flip
- 33rd
+ 33rd
Sub-string used in automation name for 33 bit in bit flip
- 32nd
+ 32nd
Sub-string used in automation name for 32 bit in bit flip
- 31st
+ 31st
Sub-string used in automation name for 31 bit in bit flip
- 30th
+ 30th
Sub-string used in automation name for 30 bit in bit flip
- 29th
+ 29th
Sub-string used in automation name for 29 bit in bit flip
- 28th
+ 28th
Sub-string used in automation name for 28 bit in bit flip
- 27th
+ 27th
Sub-string used in automation name for 27 bit in bit flip
- 26th
+ 26th
Sub-string used in automation name for 26 bit in bit flip
- 25th
+ 25th
Sub-string used in automation name for 25 bit in bit flip
- 24th
+ 24th
Sub-string used in automation name for 24 bit in bit flip
- 23rd
+ 23rd
Sub-string used in automation name for 23 bit in bit flip
- 22nd
+ 22nd
Sub-string used in automation name for 22 bit in bit flip
- 21st
+ 21st
Sub-string used in automation name for 21 bit in bit flip
- 20th
+ 20th
Sub-string used in automation name for 20 bit in bit flip
- 19th
+ 19th
Sub-string used in automation name for 19 bit in bit flip
- 18th
+ 18th
Sub-string used in automation name for 18 bit in bit flip
- 17th
+ 17th
Sub-string used in automation name for 17 bit in bit flip
- 16th
+ 16th
Sub-string used in automation name for 16 bit in bit flip
- 15th
+ 15th
Sub-string used in automation name for 15 bit in bit flip
- 14th
+ 14th
Sub-string used in automation name for 14 bit in bit flip
- 13th
+ 13th
Sub-string used in automation name for 13 bit in bit flip
- 12th
+ 12th
Sub-string used in automation name for 12 bit in bit flip
- 11th
+ 11th
Sub-string used in automation name for 11 bit in bit flip
- 10th
+ 10th
Sub-string used in automation name for 10 bit in bit flip
- 9th
+ 9th
Sub-string used in automation name for 9 bit in bit flip
- 8th
+ 8th
Sub-string used in automation name for 8 bit in bit flip
- 7th
+ 7th
Sub-string used in automation name for 7 bit in bit flip
- 6th
+ 6th
Sub-string used in automation name for 6 bit in bit flip
- 5th
+ 5th
Sub-string used in automation name for 5 bit in bit flip
- 4th
+ 4th
Sub-string used in automation name for 4 bit in bit flip
- 3rd
+ 3rd
Sub-string used in automation name for 3 bit in bit flip
- 2nd
+ 2nd
Sub-string used in automation name for 2 bit in bit flip
- 1st
+ 1st
Sub-string used in automation name for 1 bit in bit flip
- 0th
+ 0th
Sub-string used in automation name for 0 bit in bit flip
diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml
index f5de3ad..e5f8193 100644
--- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml
+++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml
@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="using:CalculatorApp.Common"
xmlns:controls="using:CalculatorApp.Controls"
- xmlns:converters="using:CalculatorApp.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:CalculatorApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -14,11 +13,6 @@
Unloaded="OnUnloaded"
mc:Ignorable="d">
-
-
-
-
-
-
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 63), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 63
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 62), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 62
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 61), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 61
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 60), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 60
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 59), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 59
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 58), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 58
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 57), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 57
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 56), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 56
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 55), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 55
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 54), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 54
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 53), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 53
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 52), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 52
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 51), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 51
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 50), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 50
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 49), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 49
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 48), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 48
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 47), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 47
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 46), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 46
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 45), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 45
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 44), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 44
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 43), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 43
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 42), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 42
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 41), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 41
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 40), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 40
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 39), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 39
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 38), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 38
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 37), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 37
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 36), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 36
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 35), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 35
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 34), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 34
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 33), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 33
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 32), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 32
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 31), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 31
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 30), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 30
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 29), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 29
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 28), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 28
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 27), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 27
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 26), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 26
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 25), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 25
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 24), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 24
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 23), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 23
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 22), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 22
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 21), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 21
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 20), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 20
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 19), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 19
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 18), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 18
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 17), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 17
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 16), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 16
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 15), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 15
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 14), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 14
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 13), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 13
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 12), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 12
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 11), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 11
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 10), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 10
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 9), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 9
+
+
+ IsEnabled="{x:Bind ShouldEnableBit(Model.ValueBitLength, 8), Mode=OneWay}"
+ Unchecked="OnBitToggled">
+
+ 8
+
+
+ Unchecked="OnBitToggled">
+
+ 7
+
+
+ Unchecked="OnBitToggled">
+
+ 6
+
+
+ Unchecked="OnBitToggled">
+
+ 5
+
+
+ Unchecked="OnBitToggled">
+
+ 4
+
+
+ Unchecked="OnBitToggled">
+
+ 3
+
+
+ Unchecked="OnBitToggled">
+
+ 2
+
+
+ Unchecked="OnBitToggled">
+
+ 1
+
+
+ Unchecked="OnBitToggled">
+
+ 0
+
+
diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp
index 1d2dee2..068f48d 100644
--- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp
+++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp
@@ -11,6 +11,8 @@
#include "CalcViewModel/Common/TraceLogger.h"
#include "CalcViewModel/Common/LocalizationSettings.h"
#include "Converters/BooleanToVisibilityConverter.h"
+#include
+#include "CalcViewModel/Common/LocalizationStringUtil.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
@@ -19,6 +21,7 @@ using namespace CalculatorApp::ViewModel;
using namespace Platform;
using namespace std;
using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Automation;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
@@ -29,15 +32,11 @@ CalculatorProgrammerBitFlipPanel::CalculatorProgrammerBitFlipPanel()
: m_updatingCheckedStates(false)
{
InitializeComponent();
- auto booleanToVisibilityConverter = ref new Converters::BooleanToVisibilityConverter;
- SetVisibilityBinding(BitFlipPanel, L"IsBinaryBitFlippingEnabled", booleanToVisibilityConverter);
-
AssignFlipButtons();
}
void CalculatorProgrammerBitFlipPanel::OnLoaded(Object ^ sender, RoutedEventArgs ^ e)
{
- UnsubscribePropertyChanged();
SubscribePropertyChanged();
}
@@ -51,8 +50,7 @@ void CalculatorProgrammerBitFlipPanel::SubscribePropertyChanged()
if (Model != nullptr)
{
m_propertyChangedToken = Model->PropertyChanged += ref new PropertyChangedEventHandler(this, &CalculatorProgrammerBitFlipPanel::OnPropertyChanged);
-
- UpdateCheckedStates();
+ UpdateCheckedStates(true);
}
}
@@ -67,9 +65,19 @@ void CalculatorProgrammerBitFlipPanel::UnsubscribePropertyChanged()
void CalculatorProgrammerBitFlipPanel::OnPropertyChanged(Object ^ sender, PropertyChangedEventArgs ^ e)
{
- if (e->PropertyName == StandardCalculatorViewModel::BinaryDisplayValuePropertyName)
+ if (e->PropertyName == StandardCalculatorViewModel::BinaryDigitsPropertyName)
{
- UpdateCheckedStates();
+ UpdateCheckedStates(false);
+ }
+ else if (e->PropertyName == StandardCalculatorViewModel::IsBitFlipCheckedPropertyName
+ || e->PropertyName == StandardCalculatorViewModel::IsProgrammerPropertyName)
+ {
+ if (Model->IsBitFlipChecked && Model->IsProgrammer)
+ {
+ // OnBitToggle won't update the automation properties when this control isn't displayed
+ // We need to update all automation properties names manually when the BitFlipPanel is displayed again
+ UpdateAutomationPropertiesNames();
+ }
}
}
@@ -148,14 +156,6 @@ void CalculatorProgrammerBitFlipPanel::AssignFlipButtons()
m_flipButtons[63] = this->Bit63;
}
-void CalculatorProgrammerBitFlipPanel::SetVisibilityBinding(_In_ FrameworkElement ^ element, _In_ String ^ path, _In_ IValueConverter ^ converter)
-{
- Binding ^ commandBinding = ref new Binding();
- commandBinding->Path = ref new PropertyPath(path);
- commandBinding->Converter = converter;
- element->SetBinding(VisibilityProperty, commandBinding);
-}
-
void CalculatorProgrammerBitFlipPanel::OnBitToggled(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
{
if (m_updatingCheckedStates)
@@ -168,14 +168,16 @@ void CalculatorProgrammerBitFlipPanel::OnBitToggled(_In_ Object ^ sender, _In_ R
// Also, if the mode is switched to other Calculator modes when the BitFlip panel is open,
// a race condition exists in which the IsProgrammerMode property is still true and the UpdatePrimaryResult() is called,
// which continuously alters the Display Value and the state of the Bit Flip buttons.
- if ((Model->IsBitFlipChecked) && Model->IsProgrammer)
+ if (Model->IsBitFlipChecked && Model->IsProgrammer)
{
auto flipButton = static_cast(sender);
+ int index = static_cast(flipButton->Tag);
+ flipButton->SetValue(AutomationProperties::NameProperty, GenerateAutomationPropertiesName(index, flipButton->IsChecked->Value));
Model->ButtonPressed->Execute(flipButton->ButtonId);
}
}
-void CalculatorProgrammerBitFlipPanel::UpdateCheckedStates()
+void CalculatorProgrammerBitFlipPanel::UpdateCheckedStates(bool updateAutomationPropertiesNames)
{
assert(!m_updatingCheckedStates);
assert(m_flipButtons.size() == s_numBits);
@@ -185,35 +187,57 @@ void CalculatorProgrammerBitFlipPanel::UpdateCheckedStates()
return;
}
- static const wchar_t ch0 = LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'0');
-
- // Filter any unwanted characters from the displayed string.
- static constexpr array unwantedChars = { L' ', Utils::LRE, Utils::PDF, Utils::LRO };
-
- wstringstream stream;
- wstring displayValue = Model->BinaryDisplayValue->Data();
- for (const wchar_t& c : displayValue)
- {
- if (find(begin(unwantedChars), end(unwantedChars), c) == unwantedChars.end())
- {
- stream << c;
- }
- }
-
- wstring rawDisplay = stream.str();
- size_t paddingCount = s_numBits - rawDisplay.length();
- wstring setBits = wstring(paddingCount, ch0) + rawDisplay;
- assert(setBits.length() == s_numBits);
-
m_updatingCheckedStates = true;
- for (unsigned int bitIndex = 0; bitIndex < s_numBits; bitIndex++)
+ auto it = m_flipButtons.begin();
+ int index = 0;
+ for (bool val : Model->BinaryDigits)
{
- // Highest bit (64) is at index 0 in bit string.
- // To get bit 0, grab from opposite end of string.
- wchar_t bit = setBits[s_numBits - bitIndex - 1];
-
- m_flipButtons[bitIndex]->IsChecked = (bit != ch0);
+ FlipButtons ^ flipButton = *it;
+ if (updateAutomationPropertiesNames)
+ {
+ flipButton->SetValue(AutomationProperties::NameProperty, GenerateAutomationPropertiesName(index, flipButton->IsChecked->Value));
+ }
+ flipButton->IsChecked = val;
+ ++it;
+ ++index;
}
m_updatingCheckedStates = false;
}
+
+void CalculatorProgrammerBitFlipPanel::UpdateAutomationPropertiesNames()
+{
+ for (FlipButtons ^ flipButton : m_flipButtons)
+ {
+ int index = static_cast(flipButton->Tag);
+ flipButton->SetValue(AutomationProperties::NameProperty, GenerateAutomationPropertiesName(index, flipButton->IsChecked->Value));
+ }
+}
+
+bool CalculatorProgrammerBitFlipPanel::ShouldEnableBit(BitLength length, int index)
+{
+ switch (length)
+ {
+ case BitLength::BitLengthQWord:
+ return index <= 63;
+ case BitLength::BitLengthDWord:
+ return index <= 31;
+ case BitLength::BitLengthWord:
+ return index <= 15;
+ case BitLength::BitLengthByte:
+ return index <= 7;
+ }
+ return false;
+}
+
+String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value) const
+{
+ auto resourceLoader = AppResourceProvider::GetInstance();
+
+ String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
+ String ^ automationNameTemplate = resourceLoader.GetResourceString(L"BitFlipItemAutomationName");
+ String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition");
+
+ wstring bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data());
+ return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str());
+}
diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h
index 3ec6355..7ff77ea 100644
--- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h
+++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
@@ -10,9 +10,6 @@
#include "Views/CalculatorProgrammerBitFlipPanel.g.h"
#include "Controls/FlipButtons.h"
-#include "Converters/BitFlipAutomationNameConverter.h"
-#include "Converters/BooleanNegationConverter.h"
-#include "Converters/VisibilityNegationConverter.h"
#include "CalcViewModel/StandardCalculatorViewModel.h"
namespace CalculatorApp
@@ -22,6 +19,8 @@ namespace CalculatorApp
public:
CalculatorProgrammerBitFlipPanel();
+ bool ShouldEnableBit(CalculatorApp::Common::BitLength length, int index);
+
property CalculatorApp::ViewModel::StandardCalculatorViewModel
^ Model { CalculatorApp::ViewModel::StandardCalculatorViewModel ^ get(); }
@@ -34,15 +33,13 @@ namespace CalculatorApp
void AssignFlipButtons();
- void SetVisibilityBinding(
- _In_ Windows::UI::Xaml::FrameworkElement ^ element,
- _In_ Platform::String ^ path,
- _In_ Windows::UI::Xaml::Data::IValueConverter ^ converter);
void OnBitToggled(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e);
- void UpdateCheckedStates();
private:
Windows::Foundation::EventRegistrationToken m_propertyChangedToken;
+ Platform::String ^ GenerateAutomationPropertiesName(int position, bool value) const;
+ void UpdateCheckedStates(bool updateAutomationPropertiesNames);
+ void UpdateAutomationPropertiesNames();
static const unsigned int s_numBits = 64;
std::array m_flipButtons;
diff --git a/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cpp
index 2766ea2..b3da313 100644
--- a/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cpp
+++ b/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cpp
@@ -37,42 +37,29 @@ void CalculatorProgrammerDisplayPanel::OnBitLengthButtonPressed(Object ^ paramet
ByteButton->Visibility = ::Visibility::Collapsed;
if (buttonId == "0")
{
- Model->ButtonPressed->Execute(NumbersAndOperatorsEnum::Dword);
+ Model->ValueBitLength = BitLength::BitLengthDWord;
DwordButton->Visibility = ::Visibility::Visible;
DwordButton->Focus(::FocusState::Programmatic);
- Model->IsQwordEnabled = false;
- Model->IsDwordEnabled = true;
- Model->IsWordEnabled = true;
}
else if (buttonId == "1")
{
- Model->ButtonPressed->Execute(NumbersAndOperatorsEnum::Word);
+ Model->ValueBitLength = BitLength::BitLengthWord;
WordButton->Visibility = ::Visibility::Visible;
WordButton->Focus(::FocusState::Programmatic);
- Model->IsQwordEnabled = false;
- Model->IsDwordEnabled = false;
- Model->IsWordEnabled = true;
}
else if (buttonId == "2")
{
- Model->ButtonPressed->Execute(NumbersAndOperatorsEnum::Byte);
+ Model->ValueBitLength = BitLength::BitLengthByte;
ByteButton->Visibility = ::Visibility::Visible;
ByteButton->Focus(::FocusState::Programmatic);
- Model->IsQwordEnabled = false;
- Model->IsDwordEnabled = false;
- Model->IsWordEnabled = false;
}
else if (buttonId == "3")
{
- Model->ButtonPressed->Execute(NumbersAndOperatorsEnum::Qword);
+ Model->ValueBitLength = BitLength::BitLengthQWord;
QwordButton->Visibility = ::Visibility::Visible;
QwordButton->Focus(::FocusState::Programmatic);
- Model->IsQwordEnabled = true;
- Model->IsDwordEnabled = true;
- Model->IsWordEnabled = true;
}
- // update memory list according to bit length
- Model->SetMemorizedNumbersString();
+
}
bool CalculatorProgrammerDisplayPanel::IsErrorVisualState::get()
diff --git a/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp
index b869bf6..7d067fe 100644
--- a/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp
+++ b/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp
@@ -27,9 +27,6 @@ CalculatorProgrammerRadixOperators::CalculatorProgrammerRadixOperators()
: m_isErrorVisualState(false)
{
InitializeComponent();
-
- auto booleanToVisibilityNegationConverter = ref new Converters::BooleanToVisibilityNegationConverter;
- SetVisibilityBinding(ProgRadixOps, L"IsBinaryBitFlippingEnabled", booleanToVisibilityNegationConverter);
}
void CalculatorProgrammerRadixOperators::OnLoaded(Object ^, RoutedEventArgs ^)
@@ -70,14 +67,6 @@ void CalculatorProgrammerRadixOperators::Shift_Clicked(Platform::Object ^ sender
}
}
-void CalculatorProgrammerRadixOperators::SetVisibilityBinding(FrameworkElement ^ element, String ^ path, IValueConverter ^ converter)
-{
- Binding ^ commandBinding = ref new Binding();
- commandBinding->Path = ref new PropertyPath(path);
- commandBinding->Converter = converter;
- element->SetBinding(VisibilityProperty, commandBinding);
-}
-
void CalculatorProgrammerRadixOperators::ProgModeRadixChange()
{
NumberPad->ProgModeRadixChange();
diff --git a/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.h b/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.h
index 83431f8..c0055e7 100644
--- a/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.h
+++ b/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.h
@@ -32,7 +32,6 @@ namespace CalculatorApp
private:
void Shift_Clicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
- void SetVisibilityBinding(Windows::UI::Xaml::FrameworkElement ^ element, Platform::String ^ path, Windows::UI::Xaml::Data::IValueConverter ^ converter);
void OnLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnUnloaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void ProgModeRadixChange();
diff --git a/src/Calculator/Views/MainPage.xaml b/src/Calculator/Views/MainPage.xaml
index a275e9c..bd011c5 100644
--- a/src/Calculator/Views/MainPage.xaml
+++ b/src/Calculator/Views/MainPage.xaml
@@ -100,7 +100,7 @@
-
+
@@ -156,29 +156,29 @@
-
-
+
+
+ Visibility="{x:Bind Model.IsAlwaysOnTop, Converter={StaticResource BooleanToVisibilityNegationConverter}, Mode=OneWay}"/>
+ Click="AlwaysOnTopButtonClick"
+ Content=""
+ Visibility="{x:Bind Model.DisplayNormalAlwaysOnTopOption, Mode=OneWay}"/>
diff --git a/src/Calculator/Views/OperatorsPanel.xaml b/src/Calculator/Views/OperatorsPanel.xaml
index d2af567..d12719d 100644
--- a/src/Calculator/Views/OperatorsPanel.xaml
+++ b/src/Calculator/Views/OperatorsPanel.xaml
@@ -1,15 +1,12 @@
+ Visibility="{x:Bind Model.IsBinaryBitFlippingEnabled, Mode=OneWay}"/>
+ Visibility="{x:Bind Model.AreProgrammerRadixOperatorsEnabled, Mode=OneWay}"/>
diff --git a/src/CalculatorUnitTests/CopyPasteManagerTest.cpp b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp
index ff0e8c5..2c2a61c 100644
--- a/src/CalculatorUnitTests/CopyPasteManagerTest.cpp
+++ b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp
@@ -59,27 +59,30 @@ namespace CalculatorUnitTests
exp_TooLong += L"-1234567";
}
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1),
+ m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(exp_TooLong.c_str()),
L"Verify ValidatePasteExpression handles expressions up to max length");
exp_TooLong += L"1";
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1),
+ m_CopyPasteManager.ValidatePasteExpression(
+ StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify ValidatePasteExpression returns NoOp for strings over max length");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.ValidatePasteExpression(StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1),
+ m_CopyPasteManager.ValidatePasteExpression(
+ StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify empty string is invalid");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.ValidatePasteExpression(StringReference(L"123e456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1),
+ m_CopyPasteManager.ValidatePasteExpression(
+ StringReference(L"123e456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify pasting unsupported strings for the current mode is invalid");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.ValidatePasteExpression(StringReference(L"123"), ViewMode::None, CategoryGroupType::None, -1, -1),
+ m_CopyPasteManager.ValidatePasteExpression(StringReference(L"123"), ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify pasting without a ViewMode or Category is invalid");
};
@@ -137,54 +140,60 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidateExpressionRegExMatch)
{
VERIFY_IS_FALSE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1),
+ m_CopyPasteManager.ExpressionRegExMatch(vector{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
L"Verify empty list of operands returns false.");
VERIFY_IS_FALSE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, -1),
+ m_CopyPasteManager.ExpressionRegExMatch(
+ vector{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
L"Verify invalid ViewMode/CategoryGroups return false.");
VERIFY_IS_FALSE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, -1),
+ m_CopyPasteManager.ExpressionRegExMatch(
+ vector{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
L"Verify invalid ViewMode/CategoryGroups return false.");
Logger::WriteMessage(L"Verify operand lengths > max return false.");
- VERIFY_IS_FALSE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1));
- VERIFY_IS_FALSE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, -1));
+ vector{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, QwordType));
+ vector{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType));
+ vector{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, QwordType));
+ vector{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, BitLength::BitLengthQWord));
+ VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
+ vector{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord));
+ VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
+ vector{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector{ L"10000000000000000000000000000000000000000000000000000000000000000" },
ViewMode::Programmer,
CategoryGroupType::Calculator,
BinBase,
- QwordType));
+ BitLength::BitLengthQWord));
VERIFY_IS_FALSE(
m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType),
+ vector{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
L"Verify operand values > max return false.");
VERIFY_IS_TRUE(
m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"((((((((((((((((((((123))))))))))))))))))))" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1),
+ vector{ L"((((((((((((((((((((123))))))))))))))))))))" },
+ ViewMode::Scientific,
+ CategoryGroupType::Calculator,
+ -1,
+ BitLength::BitLengthUnknown),
L"Verify sanitized operand is detected as within max length.");
VERIFY_IS_TRUE(
m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType),
+ vector{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
L"Verify operand values == max return true.");
Logger::WriteMessage(L"Verify all operands must match patterns.");
- VERIFY_IS_TRUE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1));
- VERIFY_IS_FALSE(
- m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1));
+ VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(
+ vector{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
+ VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
+ vector{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_TRUE(
m_CopyPasteManager.ExpressionRegExMatch(
@@ -192,16 +201,20 @@ namespace CalculatorUnitTests
ViewMode::Scientific,
CategoryGroupType::Calculator,
-1,
- -1),
+ BitLength::BitLengthUnknown),
L"Verify exponents are accepted in scientific mode.");
VERIFY_IS_FALSE(
m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1),
+ vector{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
L"Verify all operands must be within maxlength");
VERIFY_IS_FALSE(
m_CopyPasteManager.ExpressionRegExMatch(
- vector{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType),
+ vector{ L"123", L"9223372036854775808" },
+ ViewMode::Programmer,
+ CategoryGroupType::Calculator,
+ DecBase,
+ BitLength::BitLengthQWord),
L"Verify all operand must be within max value.");
};
@@ -211,15 +224,15 @@ namespace CalculatorUnitTests
pair scientificModeMaximums = make_pair(m_CopyPasteManager.MaxScientificOperandLength, 0);
pair converterModeMaximums = make_pair(m_CopyPasteManager.MaxConverterInputLength, 0);
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, -1),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
standardModeMaximums,
L"Verify Standard mode maximum values");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, -1),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
scientificModeMaximums,
L"Verify Scientific mode maximum values");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, -1),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown),
converterModeMaximums,
L"Verify Converter mode maximum values");
@@ -229,62 +242,64 @@ namespace CalculatorUnitTests
unsigned long long int ullByteMax = UINT8_MAX;
Logger::WriteMessage(L"Verify Programmer Mode HexBase maximum values");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, QwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthQWord),
make_pair((size_t)16u, ullQwordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, DwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthDWord),
make_pair((size_t)8u, ullDwordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, WordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthWord),
make_pair((size_t)4u, ullWordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, ByteType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthByte),
make_pair((size_t)2u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode DecBase maximum values");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, QwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthQWord),
make_pair((size_t)19u, ullQwordMax >> 1));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, DwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthDWord),
make_pair((size_t)10u, ullDwordMax >> 1));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, WordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthWord),
make_pair((size_t)5u, ullWordMax >> 1));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, ByteType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthByte),
make_pair((size_t)3u, ullByteMax >> 1));
Logger::WriteMessage(L"Verify Programmer Mode OctBase maximum values");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, QwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthQWord),
make_pair((size_t)22u, ullQwordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, DwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthDWord),
make_pair((size_t)11u, ullDwordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, WordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthWord),
make_pair((size_t)6u, ullWordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, ByteType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthByte),
make_pair((size_t)3u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode BinBase maximum values");
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, QwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthQWord),
make_pair((size_t)64u, ullQwordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, DwordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthDWord),
make_pair((size_t)32u, ullDwordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, WordType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthWord),
make_pair((size_t)16u, ullWordMax));
VERIFY_ARE_EQUAL(
- m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, ByteType),
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthByte),
make_pair((size_t)8u, ullByteMax));
Logger::WriteMessage(L"Verify invalid ViewModes/Categories return 0 for max values");
- VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, -1, -1), make_pair((size_t)0u, 0ull));
+ VERIFY_ARE_EQUAL(
+ m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, - 1, BitLength::BitLengthUnknown),
+ make_pair((size_t)0u, 0ull));
};
TEST_METHOD(ValidateSanitizeOperand)
@@ -438,97 +453,97 @@ namespace CalculatorUnitTests
CopyPasteManager m_CopyPasteManager;
String^ ValidateStandardPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, -1/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, BitLength::BitLengthUnknown);
}
String^ ValidateScientificPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, -1/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, BitLength::BitLengthUnknown);
}
String^ ValidateConverterPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, -1/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, BitLength::BitLengthUnknown);
}
String^ ValidateProgrammerHexQwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, QwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerHexDwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, DwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerHexWordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, WordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthWord);
}
String^ ValidateProgrammerHexBytePasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, ByteType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthByte);
}
String^ ValidateProgrammerDecQwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, QwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerDecDwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, DwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerDecWordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, WordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthWord);
}
String^ ValidateProgrammerDecBytePasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, ByteType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthByte);
}
String^ ValidateProgrammerOctQwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, QwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerOctDwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, DwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerOctWordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, WordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthWord);
}
String^ ValidateProgrammerOctBytePasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, ByteType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthByte);
}
String^ ValidateProgrammerBinQwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, QwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerBinDwordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, DwordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerBinWordPasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, WordType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthWord);
}
String^ ValidateProgrammerBinBytePasteExpression(_In_ String^ pastedText)
{
- return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, ByteType/*bitlength Type*/);
+ return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthByte);
}
};
diff --git a/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp
index 92fb834..6a82173 100644
--- a/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp
+++ b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp
@@ -16,9 +16,22 @@ using namespace CalculatorApp::Common;
using namespace CalculatorApp::ViewModel;
using namespace Platform;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace Windows::Foundation::Collections;
namespace CalculatorUnitTests
{
+ template
+ void CompareVector(IVector ^ vecA, IVector ^ vecB)
+ {
+ if (vecA->Size != vecB->Size)
+ Assert::Fail();
+
+ for (unsigned int i = 0; i < vecA->Size; ++i)
+ {
+ VERIFY_ARE_EQUAL(vecA->GetAt(i), vecB->GetAt(i));
+ }
+ }
+
void ChangeMode(StandardCalculatorViewModel ^ viewModel, int mode)
{
if (mode == 0)
@@ -496,6 +509,12 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"15"));
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"17"));
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"1111"));
+ auto val = ref new PC::Vector(64, false);
+ val->SetAt(0, true);
+ val->SetAt(1, true);
+ val->SetAt(2, true);
+ val->SetAt(3, true);
+ CompareVector(m_viewModel->BinaryDigits, val);
}
// Test Button disabling in different Radixes
@@ -543,6 +562,24 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"123,456,789"));
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"726 746 425"));
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"0111 0101 1011 1100 1101 0001 0101"));
+ auto val = ref new PC::Vector(64, false);
+ val->SetAt(0, true);
+ val->SetAt(2, true);
+ val->SetAt(4, true);
+ val->SetAt(8, true);
+ val->SetAt(10, true);
+ val->SetAt(11, true);
+ val->SetAt(14, true);
+ val->SetAt(15, true);
+ val->SetAt(16, true);
+ val->SetAt(17, true);
+ val->SetAt(19, true);
+ val->SetAt(20, true);
+ val->SetAt(22, true);
+ val->SetAt(24, true);
+ val->SetAt(25, true);
+ val->SetAt(26, true);
+ CompareVector(m_viewModel->BinaryDigits, val);
}
// Test Not functionality
@@ -562,6 +599,9 @@ namespace CalculatorUnitTests
Utils::GetStringValue(m_viewModel->BinaryDisplayValue),
StringReference(L"1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1110"));
VERIFY_ARE_EQUAL(m_viewModel->DisplayValue, StringReference(L"-2"));
+ auto val = ref new PC::Vector(64, true);
+ val->SetAt(0, false);
+ CompareVector(m_viewModel->BinaryDigits, val);
}
// Test And Or functionality