Fix crash and high contrast (#773)
This commit is contained in:
@@ -6,7 +6,9 @@ using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace CalculatorApp::Controls;
|
||||
using namespace Platform;
|
||||
using namespace Platform::Collections;
|
||||
using namespace std;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::UI;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
@@ -24,11 +26,18 @@ namespace
|
||||
|
||||
EquationInputArea::EquationInputArea()
|
||||
: m_lastLineColorIndex{ -1 }
|
||||
, m_AvailableColors{ ref new Vector<SolidColorBrush ^>() }
|
||||
, m_accessibilitySettings{ ref new AccessibilitySettings() }
|
||||
{
|
||||
InitializeComponent();
|
||||
m_accessibilitySettings->HighContrastChanged +=
|
||||
ref new TypedEventHandler<AccessibilitySettings ^, Object ^>(this, &EquationInputArea::OnHighContrastChanged);
|
||||
|
||||
ReloadAvailableColors(m_accessibilitySettings->HighContrast);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
void EquationInputArea::OnPropertyChanged(String^ propertyName)
|
||||
void EquationInputArea::OnPropertyChanged(String ^ propertyName)
|
||||
{
|
||||
if (propertyName == EquationsPropertyName)
|
||||
{
|
||||
@@ -44,7 +53,7 @@ void EquationInputArea::OnEquationsPropertyChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void EquationInputArea::AddEquationButton_Click(Object^ sender, RoutedEventArgs^ e)
|
||||
void EquationInputArea::AddEquationButton_Click(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
AddNewEquation();
|
||||
}
|
||||
@@ -52,31 +61,36 @@ void EquationInputArea::AddEquationButton_Click(Object^ sender, RoutedEventArgs^
|
||||
void EquationInputArea::AddNewEquation()
|
||||
{
|
||||
auto eq = ref new EquationViewModel();
|
||||
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % AvailableColors->Size;
|
||||
|
||||
eq->LineColor = AvailableColors->GetAt(m_lastLineColorIndex);
|
||||
|
||||
Equations->Append(eq);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_GotFocus(Object^ sender, RoutedEventArgs^ e)
|
||||
void EquationInputArea::InputTextBox_GotFocus(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
KeyboardShortcutManager::HonorShortcuts(false);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_LostFocus(Object^ sender, RoutedEventArgs^ e)
|
||||
void EquationInputArea::InputTextBox_LostFocus(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
KeyboardShortcutManager::HonorShortcuts(true);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_Submitted(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
auto tb = static_cast<EquationTextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
auto tb = static_cast<EquationTextBox ^>(sender);
|
||||
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
|
||||
eq->Expression = tb->GetEquationText();
|
||||
FocusManager::TryMoveFocus(::FocusNavigationDirection::Left);
|
||||
}
|
||||
|
||||
void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object^ sender, RoutedEventArgs^ e)
|
||||
void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
auto tb = static_cast<EquationTextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
auto tb = static_cast<EquationTextBox ^>(sender);
|
||||
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
|
||||
unsigned int index;
|
||||
if (Equations->IndexOf(eq, &index))
|
||||
{
|
||||
@@ -90,8 +104,57 @@ void EquationInputArea::EquationTextBoxLoaded(Object ^ sender, RoutedEventArgs ^
|
||||
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
|
||||
|
||||
auto colorChooser = static_cast<EquationStylePanelControl ^>(tb->ColorChooserFlyout->Content);
|
||||
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % colorChooser->AvailableColors->Size;
|
||||
|
||||
eq->LineColor = colorChooser->AvailableColors->GetAt(m_lastLineColorIndex);
|
||||
colorChooser->AvailableColors = AvailableColors;
|
||||
}
|
||||
|
||||
void EquationInputArea::OnHighContrastChanged(AccessibilitySettings ^ sender, Object ^ args)
|
||||
{
|
||||
ReloadAvailableColors(sender->HighContrast);
|
||||
}
|
||||
|
||||
void EquationInputArea::ReloadAvailableColors(bool isHighContrast)
|
||||
{
|
||||
m_AvailableColors->Clear();
|
||||
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush1")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush2")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush3")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush4")));
|
||||
|
||||
// If this is not high contrast, we have all 16 colors, otherwise we will restrict this to a subset of high contrast colors
|
||||
if (!isHighContrast)
|
||||
{
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush5")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush6")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush7")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush8")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush9")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush10")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush11")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush12")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush13")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush14")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush15")));
|
||||
m_AvailableColors->Append(safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush16")));
|
||||
}
|
||||
|
||||
// If there are no equations to reload, quit early
|
||||
if (Equations == nullptr || Equations->Size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Use a blank brush to clear out the color before setting it. This is needed because going
|
||||
// from High Contrast White -> High Contrast Black, the high contrast colors seem to be equivalent,
|
||||
// causing the change to not take place.
|
||||
auto blankBrush = ref new SolidColorBrush();
|
||||
|
||||
// Reassign colors for each equation
|
||||
m_lastLineColorIndex = -1;
|
||||
for (auto equationViewModel : Equations)
|
||||
{
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % AvailableColors->Size;
|
||||
equationViewModel->LineColor = blankBrush;
|
||||
equationViewModel->LineColor = AvailableColors->GetAt(m_lastLineColorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user