From 042a3323ee87a47eff4f0276a65da6ad6cbb8352 Mon Sep 17 00:00:00 2001 From: T Paine Date: Fri, 18 Jan 2019 10:33:27 -0800 Subject: [PATCH] Update TwoPaneView for API changes (#193) --- SdkVersion.props | 2 +- dev/TwoPaneView/DisplayRegionHelper.cpp | 49 ++++++++++++------------- dev/dll/SharedHelpers.cpp | 8 ++-- dev/inc/SharedHelpers.h | 2 +- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/SdkVersion.props b/SdkVersion.props index ccb74f6566..7156022650 100644 --- a/SdkVersion.props +++ b/SdkVersion.props @@ -6,7 +6,7 @@ 10.0.16299.0 10.0.17134.0 10.0.17763.0 - 10.0.18283.0 + 10.0.18312.0 diff --git a/dev/TwoPaneView/DisplayRegionHelper.cpp b/dev/TwoPaneView/DisplayRegionHelper.cpp index 87cc346fbb..c9bccb1ec4 100644 --- a/dev/TwoPaneView/DisplayRegionHelper.cpp +++ b/dev/TwoPaneView/DisplayRegionHelper.cpp @@ -49,42 +49,39 @@ DisplayRegionHelperInfo DisplayRegionHelper::GetRegionInfo() } } #ifdef USE_INSIDER_SDK - else if (SharedHelpers::IsDisplayRegionGetForCurrentViewAvailable()) + else if (SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable()) { - // TODO: remove try/catch after bug 14084372 is fixed. These APIs currently throw on failure. - winrt::WindowingEnvironment environment{ nullptr }; + // ApplicationView::GetForCurrentView throws on failure; in that case we just won't do anything. + winrt::ApplicationView view{ nullptr }; try { - environment = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView().WindowingEnvironment(); + view = winrt::ApplicationView::GetForCurrentView(); } catch(...) {} // Verify that the window is Tiled - if (environment) + if (view) { - if (environment.Kind() == winrt::WindowingEnvironmentKind::Tiled) + auto regions = view.GetDisplayRegions(); + info.RegionCount = std::min(regions.Size(), c_maxRegions); + + // More than one region + if (info.RegionCount == 2) { - winrt::IVectorView regions = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView().GetDisplayRegions(); - info.RegionCount = std::min(regions.Size(), c_maxRegions); + winrt::Rect windowRect = WindowRect(); - // More than one region - if (info.RegionCount == 2) + if (windowRect.Width > windowRect.Height) + { + info.Mode = winrt::TwoPaneViewMode::Wide; + float width = windowRect.Width / 2; + info.Regions[0] = { 0, 0, width, windowRect.Height }; + info.Regions[1] = { width, 0, width, windowRect.Height }; + } + else { - winrt::Rect windowRect = WindowRect(); - - if (windowRect.Width > windowRect.Height) - { - info.Mode = winrt::TwoPaneViewMode::Wide; - float width = windowRect.Width / 2; - info.Regions[0] = { 0, 0, width, windowRect.Height }; - info.Regions[1] = { width, 0, width, windowRect.Height }; - } - else - { - info.Mode = winrt::TwoPaneViewMode::Tall; - float height = windowRect.Height / 2; - info.Regions[0] = { 0, 0, windowRect.Width, height }; - info.Regions[1] = { 0, height, windowRect.Width, height }; - } + info.Mode = winrt::TwoPaneViewMode::Tall; + float height = windowRect.Height / 2; + info.Regions[0] = { 0, 0, windowRect.Width, height }; + info.Regions[1] = { 0, height, windowRect.Width, height }; } } } diff --git a/dev/dll/SharedHelpers.cpp b/dev/dll/SharedHelpers.cpp index 364d1c77db..bf6febb030 100644 --- a/dev/dll/SharedHelpers.cpp +++ b/dev/dll/SharedHelpers.cpp @@ -161,12 +161,12 @@ bool SharedHelpers::IsFrameworkElementInvalidateViewportAvailable() return s_isFrameworkElementInvalidateViewportAvailable; } -bool SharedHelpers::IsDisplayRegionGetForCurrentViewAvailable() +bool SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable() { - static bool s_isDisplayRegionGetForCurrentViewAvailable = + static bool s_isApplicationViewGetDisplayRegionsAvailable = Is19H1OrHigher() || - winrt::ApiInformation::IsMethodPresent(L"Windows.ApplicationModel.Core.DisplayRegion", L"GetForCurrentView"); - return s_isDisplayRegionGetForCurrentViewAvailable; + winrt::ApiInformation::IsMethodPresent(L"Windows.UI.ViewManagement.ApplicationView", L"GetDisplayRegions"); + return s_isApplicationViewGetDisplayRegionsAvailable; } bool SharedHelpers::IsTranslationFacadeAvailable(const winrt::UIElement& element) diff --git a/dev/inc/SharedHelpers.h b/dev/inc/SharedHelpers.h index e23ea057c7..bf09d58c95 100644 --- a/dev/inc/SharedHelpers.h +++ b/dev/inc/SharedHelpers.h @@ -43,7 +43,7 @@ class SharedHelpers static bool IsFrameworkElementInvalidateViewportAvailable(); - static bool IsDisplayRegionGetForCurrentViewAvailable(); + static bool IsApplicationViewGetDisplayRegionsAvailable(); static bool IsTranslationFacadeAvailable(const winrt::UIElement& element);