From c543197bebb116a4008a08170e37cf741415bb7f Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 19 Mar 2024 16:20:01 +0100 Subject: [PATCH] feat: Adding new AppWindow APIs --- .../Microsoft.UI.Windowing/AppWindow.cs | 8 +-- .../Microsoft/UI/Windowing/AppWindow.cs | 50 +++++++++++++++++-- .../UI/Windowing/Native/INativeAppWindow.cs | 22 ++++++++ 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/Uno.UWP/Generated/3.0.0.0/Microsoft.UI.Windowing/AppWindow.cs b/src/Uno.UWP/Generated/3.0.0.0/Microsoft.UI.Windowing/AppWindow.cs index 837cf66eb245..d3dd8a2ffcbf 100644 --- a/src/Uno.UWP/Generated/3.0.0.0/Microsoft.UI.Windowing/AppWindow.cs +++ b/src/Uno.UWP/Generated/3.0.0.0/Microsoft.UI.Windowing/AppWindow.cs @@ -24,7 +24,7 @@ public bool IsShownInSwitchers } #endif // Skipping already declared property Id -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public bool IsVisible { @@ -44,7 +44,7 @@ public bool IsVisible } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public global::Windows.Graphics.PointInt32 Position { @@ -55,7 +55,7 @@ public bool IsVisible } #endif // Skipping already declared property Presenter -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public global::Windows.Graphics.SizeInt32 Size { @@ -76,7 +76,7 @@ public bool IsVisible } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public global::Microsoft.UI.Dispatching.DispatcherQueue DispatcherQueue { diff --git a/src/Uno.UWP/Microsoft/UI/Windowing/AppWindow.cs b/src/Uno.UWP/Microsoft/UI/Windowing/AppWindow.cs index c9581faee53c..b87d86bc8589 100644 --- a/src/Uno.UWP/Microsoft/UI/Windowing/AppWindow.cs +++ b/src/Uno.UWP/Microsoft/UI/Windowing/AppWindow.cs @@ -6,9 +6,14 @@ using Microsoft.UI.Windowing.Native; using Windows.UI.ViewManagement; using MUXWindowId = Microsoft.UI.WindowId; +using Windows.Graphics; +using Microsoft.UI.Dispatching; namespace Microsoft.UI.Windowing; +/// +/// Represents a system-managed container for the content of an app. +/// #if HAS_UNO_WINUI public #else @@ -28,6 +33,8 @@ internal AppWindow() { Id = new(Interlocked.Increment(ref _windowIdIterator)); + TitleBar = new(this); + _windowIdMap[Id] = this; ApplicationView.GetOrCreateForWindowId(Id); } @@ -39,6 +46,43 @@ internal AppWindow() /// public AppWindowTitleBar TitleBar { get; } = new AppWindowTitleBar(); + /// Gets the current size of the window's client area in client coordinates. + /// + public SizeInt32 ClientSize => _nativeAppWindow.ClientSize; + + /// + /// Gets the dispatcher queue associated with the app window. + /// + public DispatcherQueue DispatcherQueue => _nativeAppWindow.DispatcherQueue; + + /// + /// Gets the identifier for the app window. + /// + public MUXWindowId Id { get; } + + /// + /// Gets a value that indicates whether the window is shown. + /// + public bool IsVisible => _nativeAppWindow.IsVisible; + + /// + /// Gets the current position of the window in screen coordinates. + /// + public PointInt32 Position => _nativeAppWindow.Position; + + /// + /// Gets the currently applied presenter for the app window. + /// + public AppWindowPresenter Presenter => _presenter; + + /// + /// Gets the current size of the window in screen coordinates. + /// + public SizeInt32 Size => _nativeAppWindow.Size; + + /// + /// Gets or sets the displayed title of the app window. + /// public string Title { get => _nativeAppWindow is not null ? _nativeAppWindow.Title : _titleCache; @@ -53,6 +97,8 @@ public string Title } } + public AppWindowTitleBar TitleBar { get; } + internal void SetNativeWindow(INativeAppWindow nativeAppWindow) { if (nativeAppWindow is null) @@ -78,10 +124,6 @@ internal void SetNativeWindow(INativeAppWindow nativeAppWindow) internal static MUXWindowId MainWindowId { get; } = new(1); - public MUXWindowId Id { get; } - - public AppWindowPresenter Presenter => _presenter; - public static AppWindow GetFromWindowId(MUXWindowId windowId) { if (!_windowIdMap.TryGetValue(windowId, out var appWindow)) diff --git a/src/Uno.UWP/Microsoft/UI/Windowing/Native/INativeAppWindow.cs b/src/Uno.UWP/Microsoft/UI/Windowing/Native/INativeAppWindow.cs index af1b7ba3dadd..54a1b5bff619 100644 --- a/src/Uno.UWP/Microsoft/UI/Windowing/Native/INativeAppWindow.cs +++ b/src/Uno.UWP/Microsoft/UI/Windowing/Native/INativeAppWindow.cs @@ -3,7 +3,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.UI.Dispatching; using Microsoft.UI.Windowing; +using Windows.Graphics; namespace Microsoft.UI.Windowing.Native; @@ -11,5 +13,25 @@ internal interface INativeAppWindow { string Title { get; set; } + bool IsVisible { get; } + + PointInt32 Position { get; } + + SizeInt32 Size { get; } + + SizeInt32 ClientSize { get; } + + DispatcherQueue DispatcherQueue { get; } + + void Destroy(); + + void Hide(); + + void Move(PointInt32 position); + + void Resize(SizeInt32 size); + + void Show(bool activateWindow); + void SetPresenter(AppWindowPresenter presenter); }