Propagate window style changes to the titlebar and minmax (#3025)
Fixes #1780
This commit is contained in:
parent
621d841538
commit
64c98db024
|
@ -19,16 +19,6 @@ namespace winrt::TerminalApp::implementation
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
void MinMaxCloseControl::Maximize()
|
||||
{
|
||||
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
|
||||
}
|
||||
|
||||
void MinMaxCloseControl::RestoreDown()
|
||||
{
|
||||
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
|
||||
}
|
||||
|
||||
// These event handlers simply forward each buttons click events up to the
|
||||
// events we've exposed.
|
||||
void MinMaxCloseControl::_MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
|
||||
|
@ -48,6 +38,21 @@ namespace winrt::TerminalApp::implementation
|
|||
_closeClickHandlers(*this, e);
|
||||
}
|
||||
|
||||
void MinMaxCloseControl::SetWindowVisualState(WindowVisualState visualState)
|
||||
{
|
||||
switch (visualState)
|
||||
{
|
||||
case WindowVisualState::WindowVisualStateMaximized:
|
||||
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
|
||||
break;
|
||||
case WindowVisualState::WindowVisualStateNormal:
|
||||
case WindowVisualState::WindowVisualStateIconified:
|
||||
default:
|
||||
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
|
||||
|
|
|
@ -18,8 +18,7 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
MinMaxCloseControl();
|
||||
|
||||
void Maximize();
|
||||
void RestoreDown();
|
||||
void SetWindowVisualState(WindowVisualState visualState);
|
||||
|
||||
void _MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
|
||||
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import "..\TitlebarControl.idl";
|
||||
|
||||
namespace TerminalApp
|
||||
{
|
||||
[default_interface] runtimeclass MinMaxCloseControl : Windows.UI.Xaml.Controls.StackPanel
|
||||
{
|
||||
MinMaxCloseControl();
|
||||
|
||||
void Maximize();
|
||||
void RestoreDown();
|
||||
void SetWindowVisualState(WindowVisualState visualState);
|
||||
|
||||
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MinimizeClick;
|
||||
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MaximizeClick;
|
||||
|
|
|
@ -59,12 +59,10 @@ namespace winrt::TerminalApp::implementation
|
|||
::GetWindowPlacement(_window, &placement);
|
||||
if (placement.showCmd == SW_SHOWNORMAL)
|
||||
{
|
||||
MinMaxCloseControl().Maximize();
|
||||
::PostMessage(_window, WM_SYSCOMMAND, SC_MAXIMIZE | flag, lParam);
|
||||
}
|
||||
else if (placement.showCmd == SW_SHOWMAXIMIZED)
|
||||
{
|
||||
MinMaxCloseControl().RestoreDown();
|
||||
::PostMessage(_window, WM_SYSCOMMAND, SC_RESTORE | flag, lParam);
|
||||
}
|
||||
}
|
||||
|
@ -92,4 +90,9 @@ namespace winrt::TerminalApp::implementation
|
|||
::PostQuitMessage(0);
|
||||
}
|
||||
|
||||
void TitlebarControl::SetWindowVisualState(WindowVisualState visualState)
|
||||
{
|
||||
MinMaxCloseControl().SetWindowVisualState(visualState);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ namespace winrt::TerminalApp::implementation
|
|||
Windows::UI::Xaml::UIElement Content();
|
||||
void Content(Windows::UI::Xaml::UIElement content);
|
||||
|
||||
void SetWindowVisualState(WindowVisualState visualState);
|
||||
|
||||
void Root_SizeChanged(const IInspectable& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);
|
||||
|
||||
void Minimize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
|
|
@ -3,9 +3,17 @@
|
|||
|
||||
namespace TerminalApp
|
||||
{
|
||||
enum WindowVisualState
|
||||
{
|
||||
WindowVisualStateNormal = 0,
|
||||
WindowVisualStateMaximized,
|
||||
WindowVisualStateIconified
|
||||
};
|
||||
|
||||
[default_interface] runtimeclass TitlebarControl : Windows.UI.Xaml.Controls.Grid
|
||||
{
|
||||
TitlebarControl(UInt64 parentWindowHandle);
|
||||
void SetWindowVisualState(WindowVisualState visualState);
|
||||
|
||||
Windows.UI.Xaml.UIElement Content;
|
||||
Windows.UI.Xaml.Controls.Border DragBar { get; };
|
||||
|
|
|
@ -667,6 +667,17 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
|
|||
return false;
|
||||
}
|
||||
|
||||
const auto windowStyle = GetWindowStyle(_window.get());
|
||||
const auto isMaximized = WI_IsFlagSet(windowStyle, WS_MAXIMIZE);
|
||||
const auto isIconified = WI_IsFlagSet(windowStyle, WS_ICONIC);
|
||||
|
||||
if (_titlebar)
|
||||
{
|
||||
_titlebar.SetWindowVisualState(isMaximized ? winrt::TerminalApp::WindowVisualState::WindowVisualStateMaximized :
|
||||
isIconified ? winrt::TerminalApp::WindowVisualState::WindowVisualStateIconified :
|
||||
winrt::TerminalApp::WindowVisualState::WindowVisualStateNormal);
|
||||
}
|
||||
|
||||
// Figure out the suggested dimensions
|
||||
RECT rcSuggested;
|
||||
rcSuggested.left = windowPos->x;
|
||||
|
@ -714,9 +725,6 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
|
|||
}
|
||||
}
|
||||
|
||||
const auto windowStyle = GetWindowStyle(_window.get());
|
||||
const auto isMaximized = WI_IsFlagSet(windowStyle, WS_MAXIMIZE);
|
||||
|
||||
// If we're about to maximize the window, determine how much we're about to
|
||||
// overhang by, and adjust for that.
|
||||
// We need to do this because maximized windows will typically overhang the
|
||||
|
|
Loading…
Reference in a new issue