Simplify title bar (#442)

Fixes #407 (partially) and #441

Description of the changes:
Remove TitleBarHelper and all <Border x:Name="CustomTitleBar" />
Let the system defines the draggable region
Centralize all events and functions associated to the title bar in a single control TitleBar instead of code splitted between MainPage/TitleBar/HistoryList/Memory.
Use the standard title bar when high contrast is activated instead of the custom one.
Modify the color of the title when the window doesn't have focus
Fix the right padding of the title bar with high contrast

How changes were validated:
Manually tested with LtR and RtL languages
Manually tested with high contrast
Tested when History and Memory flyout are opened
This commit is contained in:
Rudy Huyn 2019-04-19 18:49:08 -07:00 committed by Daniel Belcher
commit bd04c92c1c
19 changed files with 168 additions and 394 deletions

View file

@ -11,7 +11,6 @@
#include "Views/Memory.xaml.h"
#include "Converters/BooleanToVisibilityConverter.h"
#include "Common/AppLifecycleLogger.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
using namespace CalculatorApp::Common::Automation;
@ -69,8 +68,6 @@ MainPage::MainPage() :
{
InitializeComponent();
m_uiSettings = ref new UISettings();
KeyboardShortcutManager::Initialize();
m_model->PropertyChanged += ref new PropertyChangedEventHandler(this, &MainPage::OnAppPropertyChanged);
@ -83,7 +80,7 @@ MainPage::MainPage() :
{
DisplayInformation::AutoRotationPreferences = DisplayOrientations::Portrait | DisplayOrientations::PortraitFlipped;
}
}
}
}
void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
@ -184,7 +181,6 @@ void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows:
ShowHideControls(newValue);
UpdateViewState();
SetTitleBarControlColors();
SetDefaultFocus();
}
else if (propertyName == ApplicationViewModel::CategoryNamePropertyName)
@ -199,7 +195,7 @@ void MainPage::ShowHideControls(ViewMode mode)
auto isCalcViewMode = NavCategory::IsCalculatorViewMode(mode);
auto isDateCalcViewMode = NavCategory::IsDateCalculatorViewMode(mode);
auto isConverterViewMode = NavCategory::IsConverterViewMode(mode);
if (m_calculator)
{
m_calculator->Visibility = BooleanToVisibilityConverter::Convert(isCalcViewMode);
@ -246,14 +242,9 @@ void MainPage::OnPageLoaded(_In_ Object^, _In_ RoutedEventArgs^ args)
m_model->CalculatorViewModel->IsStandard = true;
}
_windowSizeEventToken = Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::WindowSizeChanged);
m_windowSizeEventToken = Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::WindowSizeChanged);
UpdateViewState();
// Set custom XAML Title Bar window caption control button brushes
m_uiSettings->ColorValuesChanged -= m_colorValuesChangedToken;
m_colorValuesChangedToken = m_uiSettings->ColorValuesChanged += ref new TypedEventHandler<UISettings^, Object^>(this, &MainPage::ColorValuesChanged);
SetTitleBarControlColors();
SetHeaderAutomationName();
SetDefaultFocus();
@ -269,12 +260,6 @@ void MainPage::OnPageLoaded(_In_ Object^, _In_ RoutedEventArgs^ args)
}));
}
void MainPage::OnPageUnLoaded(_In_ Object^, _In_ RoutedEventArgs^)
{
// OnPageUnloaded Event Handler does not get fired when the calc window is closed.
// On closing the instance of a window, On Window Consolidate gets fired.
}
void MainPage::SetDefaultFocus()
{
if (m_calculator != nullptr && m_calculator->Visibility == ::Visibility::Visible)
@ -310,9 +295,6 @@ void MainPage::EnsureCalculator()
m_calculator->SetBinding(m_calculator->IsProgrammerProperty, isProgramerBinding);
m_calculator->Style = CalculatorBaseStyle;
m_fullscreenFlyoutClosedToken =
m_calculator->FullscreenFlyoutClosed += ref new FullscreenFlyoutClosedEventHandler(this, &MainPage::OnFullscreenFlyoutClosed);
CalcHolder->Child = m_calculator;
// Calculator's "default" state is visible, but if we get delay loaded
@ -493,62 +475,15 @@ void MainPage::ShowAboutPage()
FlyoutBase::ShowAttachedFlyout(AboutButton);
}
void MainPage::ColorValuesChanged(_In_ UISettings^ sender, _In_ Object^ e)
{
WeakReference weakThis(this);
RunOnUIThreadNonblocking([weakThis]()
{
auto refThis = weakThis.Resolve<MainPage>();
if (refThis != nullptr)
{
refThis->SetTitleBarControlColors();
}
}, this->Dispatcher);
}
void MainPage::SetTitleBarControlColors()
{
auto applicationView = ApplicationView::GetForCurrentView();
if (applicationView == nullptr) { return; }
auto applicationTitleBar = applicationView->TitleBar;
if (applicationTitleBar == nullptr) { return; }
auto bgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundTransparentBrush"));
auto fgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlPageTextBaseHighBrush"));
auto inactivefgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundChromeDisabledLowBrush"));
auto hoverbgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundListLowBrush"));
auto hoverfgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"));
auto pressedbgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundListMediumBrush"));
auto pressedfgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"));
applicationTitleBar->ButtonBackgroundColor = bgbrush->Color;
applicationTitleBar->ButtonForegroundColor = fgbrush->Color;
applicationTitleBar->ButtonInactiveBackgroundColor = bgbrush->Color;
applicationTitleBar->ButtonInactiveForegroundColor = inactivefgbrush->Color;
applicationTitleBar->ButtonHoverBackgroundColor = hoverbgbrush->Color;
applicationTitleBar->ButtonHoverForegroundColor = hoverfgbrush->Color;
applicationTitleBar->ButtonPressedBackgroundColor = pressedbgbrush->Color;
applicationTitleBar->ButtonPressedForegroundColor = pressedfgbrush->Color;
}
void MainPage::UnregisterEventHandlers()
{
m_uiSettings->ColorValuesChanged -= m_colorValuesChangedToken;
m_colorValuesChangedToken.Value = 0;
Window::Current->SizeChanged -= _windowSizeEventToken;
_windowSizeEventToken.Value = 0;
Window::Current->SizeChanged -= m_windowSizeEventToken;
m_windowSizeEventToken.Value = 0;
if (m_calculator != nullptr)
{
m_calculator->FullscreenFlyoutClosed -= m_fullscreenFlyoutClosedToken;
m_fullscreenFlyoutClosedToken.Value = 0;
m_calculator->UnregisterEventHandlers();
}
m_titleBarHelper = nullptr;
}
void MainPage::SetHeaderAutomationName()
@ -572,7 +507,7 @@ void MainPage::SetHeaderAutomationName()
{
full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data();
}
string::size_type found = full.find(L"%1");
wstring strMode = m_model->CategoryName->Data();
full = full.replace(found, 2, strMode);
@ -583,11 +518,6 @@ void MainPage::SetHeaderAutomationName()
AutomationProperties::SetName(Header, name);
}
void MainPage::OnFullscreenFlyoutClosed()
{
this->CustomTitleBar->SetTitleBar();
}
void MainPage::AnnounceCategoryName()
{
String^ categoryName = AutomationProperties::GetName(Header);