Hello GitHub
This commit is contained in:
80
src/Calculator/Converters/BitFlipAutomationNameConverter.cpp
Normal file
80
src/Calculator/Converters/BitFlipAutomationNameConverter.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// 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<String^>(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<String^>(value))->Data();
|
||||
wstring indexString = (static_cast<String^>(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 each (wchar_t bit in 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;
|
||||
}
|
||||
22
src/Calculator/Converters/BitFlipAutomationNameConverter.h
Normal file
22
src/Calculator/Converters/BitFlipAutomationNameConverter.h
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Value converter that translates binary value to automation name for a bit.
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
33
src/Calculator/Converters/BooleanNegationConverter.cpp
Normal file
33
src/Calculator/Converters/BooleanNegationConverter.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "BooleanNegationConverter.h"
|
||||
|
||||
using namespace CalculatorApp::Converters;
|
||||
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::Xaml::Interop;
|
||||
|
||||
Object^ BooleanNegationConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto boxedBool = dynamic_cast<Box<bool>^>(value);
|
||||
auto boolValue = (boxedBool != nullptr && boxedBool->Value);
|
||||
return !boolValue;
|
||||
}
|
||||
|
||||
Object^ BooleanNegationConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto boxedBool = dynamic_cast<Box<bool>^>(value);
|
||||
auto boolValue = (boxedBool != nullptr && boxedBool->Value);
|
||||
return !boolValue;
|
||||
}
|
||||
21
src/Calculator/Converters/BooleanNegationConverter.h
Normal file
21
src/Calculator/Converters/BooleanNegationConverter.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Value converter that translates true to false and vice versa.
|
||||
/// </summary>
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
public ref class BooleanNegationConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
}
|
||||
}
|
||||
61
src/Calculator/Converters/BooleanToVisibilityConverter.cpp
Normal file
61
src/Calculator/Converters/BooleanToVisibilityConverter.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "BooleanToVisibilityConverter.h"
|
||||
|
||||
using namespace CalculatorApp::Common;
|
||||
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Interop;
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
Object^ BooleanToVisibilityConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto boxedBool = dynamic_cast<Box<bool>^>(value);
|
||||
auto boolValue = (boxedBool != nullptr && boxedBool->Value);
|
||||
return BooleanToVisibilityConverter::Convert(boolValue);
|
||||
}
|
||||
|
||||
Object^ BooleanToVisibilityConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto visibility = dynamic_cast<Box<Visibility>^>(value);
|
||||
return (visibility != nullptr && visibility->Value == Visibility::Visible);
|
||||
}
|
||||
|
||||
Object^ BooleanToVisibilityNegationConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto boxedBool = dynamic_cast<Box<bool>^>(value);
|
||||
auto boolValue = (boxedBool != nullptr && boxedBool->Value);
|
||||
return BooleanToVisibilityConverter::Convert(!boolValue);
|
||||
}
|
||||
|
||||
Object^ BooleanToVisibilityNegationConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto visibility = dynamic_cast<Box<Visibility>^>(value);
|
||||
return (visibility != nullptr && visibility->Value != Visibility::Visible);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
40
src/Calculator/Converters/BooleanToVisibilityConverter.h
Normal file
40
src/Calculator/Converters/BooleanToVisibilityConverter.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Value converter that translates true to <see cref="Visibility::Visible"/> and false
|
||||
/// to <see cref="Visibility::Collapsed"/>.
|
||||
/// </summary>
|
||||
public ref class BooleanToVisibilityConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
static constexpr Windows::UI::Xaml::Visibility Convert(bool visibility)
|
||||
{
|
||||
return visibility
|
||||
? Windows::UI::Xaml::Visibility::Visible
|
||||
: Windows::UI::Xaml::Visibility::Collapsed;
|
||||
}
|
||||
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Value converter that translates false to <see cref="Visibility::Visible"/> and true
|
||||
/// to <see cref="Visibility::Collapsed"/>.
|
||||
/// </summary>
|
||||
public ref class BooleanToVisibilityNegationConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
44
src/Calculator/Converters/ExpressionItemContainerStyle.cpp
Normal file
44
src/Calculator/Converters/ExpressionItemContainerStyle.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "ExpressionItemContainerStyle.h"
|
||||
#include "CalcViewModel\Common\DisplayExpressionToken.h"
|
||||
|
||||
using namespace CalculatorApp::Common;
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
Windows::UI::Xaml::Style^ ExpressionItemContainerStyle::SelectStyleCore(Platform::Object^ item, Windows::UI::Xaml::DependencyObject^ container)
|
||||
{
|
||||
DisplayExpressionToken^ token = dynamic_cast<DisplayExpressionToken^>(item);
|
||||
if (token != nullptr)
|
||||
{
|
||||
Common::TokenType type = token->Type;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case TokenType::Operator:
|
||||
if (token->IsTokenEditable)
|
||||
{
|
||||
return m_editableOperatorStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_nonEditableOperatorStyle;
|
||||
}
|
||||
case TokenType::Operand:
|
||||
return m_operandStyle;
|
||||
case TokenType::Separator:
|
||||
return m_separatorStyle;
|
||||
default:
|
||||
throw ref new Platform::Exception(E_FAIL, L"Invalid token type");
|
||||
}
|
||||
}
|
||||
|
||||
return m_separatorStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/Calculator/Converters/ExpressionItemContainerStyle.h
Normal file
71
src/Calculator/Converters/ExpressionItemContainerStyle.h
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
[Windows::UI::Xaml::Data::Bindable]
|
||||
public ref class ExpressionItemContainerStyle sealed : public Windows::UI::Xaml::Controls::StyleSelector
|
||||
{
|
||||
public:
|
||||
virtual Windows::UI::Xaml::Style^ SelectStyleCore(Platform::Object^ item, Windows::UI::Xaml::DependencyObject^ container) override;
|
||||
|
||||
property Windows::UI::Xaml::Style^ EditableOperatorStyle
|
||||
{
|
||||
Windows::UI::Xaml::Style^ get()
|
||||
{
|
||||
return m_editableOperatorStyle;
|
||||
}
|
||||
void set(Windows::UI::Xaml::Style^ val)
|
||||
{
|
||||
m_editableOperatorStyle = val;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::UI::Xaml::Style^ OperandStyle
|
||||
{
|
||||
Windows::UI::Xaml::Style^ get()
|
||||
{
|
||||
return m_operandStyle;
|
||||
}
|
||||
void set(Windows::UI::Xaml::Style^ val)
|
||||
{
|
||||
m_operandStyle = val;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::UI::Xaml::Style^ SeparatorStyle
|
||||
{
|
||||
Windows::UI::Xaml::Style^ get()
|
||||
{
|
||||
return m_separatorStyle;
|
||||
}
|
||||
void set(Windows::UI::Xaml::Style^ val)
|
||||
{
|
||||
m_separatorStyle = val;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::UI::Xaml::Style^ NonEditableOperatorStyle
|
||||
{
|
||||
Windows::UI::Xaml::Style^ get()
|
||||
{
|
||||
return m_nonEditableOperatorStyle;
|
||||
}
|
||||
void set(Windows::UI::Xaml::Style^ val)
|
||||
{
|
||||
m_nonEditableOperatorStyle = val;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Windows::UI::Xaml::Style^ m_editableOperatorStyle;
|
||||
Windows::UI::Xaml::Style^ m_nonEditableOperatorStyle;
|
||||
Windows::UI::Xaml::Style^ m_operandStyle;
|
||||
Windows::UI::Xaml::Style^ m_separatorStyle;
|
||||
};
|
||||
}
|
||||
}
|
||||
37
src/Calculator/Converters/ExpressionItemTemplateSelector.cpp
Normal file
37
src/Calculator/Converters/ExpressionItemTemplateSelector.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "ExpressionItemTemplateSelector.h"
|
||||
#include "CalcViewModel\Common\DisplayExpressionToken.h"
|
||||
|
||||
using namespace CalculatorApp::Common;
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
Windows::UI::Xaml::DataTemplate^ ExpressionItemTemplateSelector::SelectTemplateCore(Platform::Object^ item, Windows::UI::Xaml::DependencyObject^ container)
|
||||
{
|
||||
DisplayExpressionToken^ token = dynamic_cast<DisplayExpressionToken^>(item);
|
||||
if (token != nullptr)
|
||||
{
|
||||
Common::TokenType type = token->Type;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case TokenType::Operator:
|
||||
return m_operatorTemplate;
|
||||
case TokenType::Operand:
|
||||
return m_operandTemplate;
|
||||
case TokenType::Separator:
|
||||
return m_separatorTemplate;
|
||||
default:
|
||||
throw ref new Platform::Exception(E_FAIL, L"Invalid token type");
|
||||
}
|
||||
}
|
||||
|
||||
return m_separatorTemplate;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/Calculator/Converters/ExpressionItemTemplateSelector.h
Normal file
58
src/Calculator/Converters/ExpressionItemTemplateSelector.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
[Windows::UI::Xaml::Data::Bindable]
|
||||
public ref class ExpressionItemTemplateSelector sealed : public Windows::UI::Xaml::Controls::DataTemplateSelector
|
||||
{
|
||||
public:
|
||||
virtual Windows::UI::Xaml::DataTemplate^ SelectTemplateCore(Platform::Object^ item, Windows::UI::Xaml::DependencyObject^ container) override;
|
||||
|
||||
property Windows::UI::Xaml::DataTemplate^ OperatorTemplate
|
||||
{
|
||||
Windows::UI::Xaml::DataTemplate^ get()
|
||||
{
|
||||
return m_operatorTemplate;
|
||||
}
|
||||
void set(Windows::UI::Xaml::DataTemplate^ val)
|
||||
{
|
||||
m_operatorTemplate = val;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::UI::Xaml::DataTemplate^ OperandTemplate
|
||||
{
|
||||
Windows::UI::Xaml::DataTemplate^ get()
|
||||
{
|
||||
return m_operandTemplate;
|
||||
}
|
||||
void set(Windows::UI::Xaml::DataTemplate^ val)
|
||||
{
|
||||
m_operandTemplate = val;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::UI::Xaml::DataTemplate^ SeparatorTemplate
|
||||
{
|
||||
Windows::UI::Xaml::DataTemplate^ get()
|
||||
{
|
||||
return m_separatorTemplate;
|
||||
}
|
||||
void set(Windows::UI::Xaml::DataTemplate^ val)
|
||||
{
|
||||
m_separatorTemplate = val;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Windows::UI::Xaml::DataTemplate^ m_operatorTemplate;
|
||||
Windows::UI::Xaml::DataTemplate^ m_operandTemplate;
|
||||
Windows::UI::Xaml::DataTemplate^ m_separatorTemplate;
|
||||
};
|
||||
}
|
||||
}
|
||||
44
src/Calculator/Converters/ItemSizeToVisibilityConverter.cpp
Normal file
44
src/Calculator/Converters/ItemSizeToVisibilityConverter.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "ItemSizeToVisibilityConverter.h"
|
||||
#include "BooleanToVisibilityConverter.h"
|
||||
|
||||
using namespace CalculatorApp::Converters;
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Interop;
|
||||
|
||||
Object^ ItemSizeToVisibilityConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto items = dynamic_cast<Box<int>^>(value);
|
||||
auto boolValue = (items != nullptr && (items->Value == 0));
|
||||
return BooleanToVisibilityConverter::Convert(boolValue);
|
||||
}
|
||||
|
||||
Object^ ItemSizeToVisibilityConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
throw ref new NotImplementedException();
|
||||
}
|
||||
|
||||
Object^ ItemSizeToVisibilityNegationConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void) targetType; // Unused parameter
|
||||
(void) parameter; // Unused parameter
|
||||
(void) language; // Unused parameter
|
||||
|
||||
auto items = dynamic_cast<Box<int>^>(value);
|
||||
auto boolValue = (items != nullptr && (items->Value > 0));
|
||||
return BooleanToVisibilityConverter::Convert(boolValue);
|
||||
}
|
||||
|
||||
Object^ ItemSizeToVisibilityNegationConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
throw ref new NotImplementedException();
|
||||
}
|
||||
25
src/Calculator/Converters/ItemSizeToVisibilityConverter.h
Normal file
25
src/Calculator/Converters/ItemSizeToVisibilityConverter.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
public ref class ItemSizeToVisibilityConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
|
||||
public ref class ItemSizeToVisibilityNegationConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
}
|
||||
}
|
||||
64
src/Calculator/Converters/RadixToStringConverter.cpp
Normal file
64
src/Calculator/Converters/RadixToStringConverter.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "CalcViewModel\Common\AppResourceProvider.h"
|
||||
#include "RadixToStringConverter.h"
|
||||
|
||||
using namespace CalculatorApp::Common;
|
||||
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::Xaml::Interop;
|
||||
using namespace Windows::ApplicationModel::Resources;
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
Object^ RadixToStringConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
(void)targetType; // Unused parameter
|
||||
(void)parameter; // Unused parameter
|
||||
(void)language; // Unused parameter
|
||||
|
||||
auto boxedInt = dynamic_cast<Box<int>^>(value);
|
||||
Platform::String^ convertedValue;
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
switch (boxedInt->Value)
|
||||
{
|
||||
case RADIX_TYPE::BIN_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Bin");
|
||||
break;
|
||||
}
|
||||
case RADIX_TYPE::OCT_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Oct");
|
||||
break;
|
||||
}
|
||||
case RADIX_TYPE::DEC_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Dec");
|
||||
break;
|
||||
}
|
||||
case RADIX_TYPE::HEX_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Hex");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
};
|
||||
return convertedValue;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Object^ RadixToStringConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
throw ref new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
21
src/Calculator/Converters/RadixToStringConverter.h
Normal file
21
src/Calculator/Converters/RadixToStringConverter.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Value converter that translates true to false and vice versa.
|
||||
/// </summary>
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
public ref class RadixToStringConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
}
|
||||
}
|
||||
32
src/Calculator/Converters/VisibilityNegationConverter.cpp
Normal file
32
src/Calculator/Converters/VisibilityNegationConverter.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "VisibilityNegationConverter.h"
|
||||
|
||||
using namespace Platform;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Interop;
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Common
|
||||
{
|
||||
Object^ VisibilityNegationConverter::Convert(Object^ value, TypeName /*targetType*/, Object^ /*parameter*/, String^ /*language*/)
|
||||
{
|
||||
auto boxedVisibility = dynamic_cast<Box<Visibility>^>(value);
|
||||
Visibility visibility = Visibility::Collapsed;
|
||||
if (boxedVisibility != nullptr && boxedVisibility->Value == Visibility::Collapsed)
|
||||
{
|
||||
visibility = Visibility::Visible;
|
||||
}
|
||||
return visibility;
|
||||
}
|
||||
|
||||
Object^ VisibilityNegationConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
|
||||
{
|
||||
return Convert(value, targetType, parameter, language);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/Calculator/Converters/VisibilityNegationConverter.h
Normal file
21
src/Calculator/Converters/VisibilityNegationConverter.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Value converter that translates Visible to Collapsed and vice versa
|
||||
/// </summary>
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
public ref class VisibilityNegationConverter sealed : Windows::UI::Xaml::Data::IValueConverter
|
||||
{
|
||||
public:
|
||||
virtual Platform::Object^ Convert(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
virtual Platform::Object^ ConvertBack(Platform::Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object^ parameter, Platform::String^ language);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user