From f6c1ecf3e4d8ece568e3009b70979f10e511c261 Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Wed, 6 Apr 2022 16:45:07 +0200 Subject: [WindowFrameBackend] TransientFrame only associates parenting in both windows (this is taked into account when the window is shown) --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index d5bde8af..b520a67b 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -334,20 +334,14 @@ namespace Xwt.Mac void IWindowFrameBackend.SetTransientFor (IWindowFrameBackend parent) { + //TODO: why this? if (!((IWindowFrameBackend)this).ShowInTaskbar) Window.StyleMask &= ~NSWindowStyle.Miniaturizable; - var win = Window as NSWindow ?? ApplicationContext.Toolkit.GetNativeWindow (parent) as NSWindow; - - if (Window.ParentWindow != win) { - // remove from the previous parent - if (Window.ParentWindow != null) - Window.ParentWindow.RemoveChildWindow (Window); - - Window.ParentWindow = win; - // A window must be visible to be added to a parent. See InternalShow(). - if (Visible) - Window.ParentWindow.AddChildWindow (Window, NSWindowOrderingMode.Above); + //we try to get the native object from the parameter if not we fallback into the real parent + NSWindow nParent = (ApplicationContext.Toolkit.GetNativeWindow(parent) as NSWindow) ?? Window.ParentWindow; + if (nParent != Window.ParentWindow) { + Window.ParentWindow = nParent; } } -- cgit v1.2.3 From 68bb09f96c2c87b18a5b7100134b64caae7e9c26 Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Wed, 6 Apr 2022 16:47:16 +0200 Subject: [WindowFrameBackend] We only add the parenting if the window was not already added+center --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index b520a67b..f96b4ce7 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -96,20 +96,17 @@ namespace Xwt.Mac internal void InternalShow () { Window.MakeKeyAndOrderFront (MacEngine.App); - if (Window.ParentWindow != null) { - if (!Window.ParentWindow.ChildWindows.Contains (Window)) - Window.ParentWindow.AddChildWindow (Window, NSWindowOrderingMode.Above); - - // always use NSWindow for alignment when running in guest mode and - // don't rely on AddChildWindow to position the window correctly - if (!(Window.ParentWindow is WindowBackend)) { - var parentBounds = MacDesktopBackend.ToDesktopRect (Window.ParentWindow.ContentRectFor (Window.ParentWindow.Frame)); - var bounds = ((IWindowFrameBackend)this).Bounds; - bounds.X = parentBounds.Center.X - (Window.Frame.Width / 2); - bounds.Y = parentBounds.Center.Y - (Window.Frame.Height / 2); - ((IWindowFrameBackend)this).Bounds = bounds; - } + var parentWindow = Window.ParentWindow; + + if (parentWindow != null && Visible) + { + //if there is any child window we remove it + if (!parentWindow.ChildWindows.Contains (Window)) + parentWindow.AddChildWindow (Window, NSWindowOrderingMode.Above); } + + //we center in any case + Util.CenterWindow(Window, parentWindow); } public void Present () -- cgit v1.2.3 From 0ee962345da04614d27e63601b9372c11f633681 Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Wed, 6 Apr 2022 16:53:56 +0200 Subject: [WindowFrame] Fixes NRE if transient value is null --- Xwt/Xwt/WindowFrame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xwt/Xwt/WindowFrame.cs b/Xwt/Xwt/WindowFrame.cs index 890b9dc4..788fa589 100644 --- a/Xwt/Xwt/WindowFrame.cs +++ b/Xwt/Xwt/WindowFrame.cs @@ -260,7 +260,7 @@ namespace Xwt get { return transientFor; } set { transientFor = value; - Backend.SetTransientFor ((IWindowFrameBackend)(value as IFrontend).Backend); + Backend.SetTransientFor ((IWindowFrameBackend)(value as IFrontend)?.Backend); } } -- cgit v1.2.3 From dc0bab08d2d176289699362426a13523430bcdfa Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Thu, 7 Apr 2022 13:19:19 +0200 Subject: Ensures un associed both old parent dialog and new if it was already shown --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index f96b4ce7..ae43d353 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -336,8 +336,16 @@ namespace Xwt.Mac Window.StyleMask &= ~NSWindowStyle.Miniaturizable; //we try to get the native object from the parameter if not we fallback into the real parent - NSWindow nParent = (ApplicationContext.Toolkit.GetNativeWindow(parent) as NSWindow) ?? Window.ParentWindow; - if (nParent != Window.ParentWindow) { + if (ApplicationContext.Toolkit.GetNativeWindow(parent) is NSWindow nParent && nParent != Window.ParentWindow) + { + // remove from the previous parent + if (Window.ParentWindow != null) + Window.ParentWindow.RemoveChildWindow(Window); + + // new parent has any associed window we remove it + if (nParent.ParentWindow != null) + nParent.ParentWindow.RemoveChildWindow(nParent); + Window.ParentWindow = nParent; } } -- cgit v1.2.3 From a2487a8cf5dd6446a78bf744b40b409cc345f03a Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Thu, 7 Apr 2022 13:32:13 +0200 Subject: If the window is already visible we set the association --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index ae43d353..86fc236e 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -96,17 +96,21 @@ namespace Xwt.Mac internal void InternalShow () { Window.MakeKeyAndOrderFront (MacEngine.App); + var parentWindow = Window.ParentWindow; + TryAddChildWindowIfVisible(parentWindow, Window); + //we center in any case + Util.CenterWindow(Window, parentWindow); + } + void TryAddChildWindowIfVisible(NSWindow parentWindow, NSWindow window) + { if (parentWindow != null && Visible) { //if there is any child window we remove it - if (!parentWindow.ChildWindows.Contains (Window)) - parentWindow.AddChildWindow (Window, NSWindowOrderingMode.Above); + if (!parentWindow.ChildWindows.Contains(window)) + parentWindow.AddChildWindow(window, NSWindowOrderingMode.Above); } - - //we center in any case - Util.CenterWindow(Window, parentWindow); } public void Present () @@ -347,6 +351,8 @@ namespace Xwt.Mac nParent.ParentWindow.RemoveChildWindow(nParent); Window.ParentWindow = nParent; + + TryAddChildWindowIfVisible(nParent, Window); } } -- cgit v1.2.3 From 037e8e226f1060a97b2d485aab4eb18e81cc6160 Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Thu, 7 Apr 2022 14:02:10 +0200 Subject: Removes unnecessary un-assignment --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index 86fc236e..d9d429a2 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -346,10 +346,6 @@ namespace Xwt.Mac if (Window.ParentWindow != null) Window.ParentWindow.RemoveChildWindow(Window); - // new parent has any associed window we remove it - if (nParent.ParentWindow != null) - nParent.ParentWindow.RemoveChildWindow(nParent); - Window.ParentWindow = nParent; TryAddChildWindowIfVisible(nParent, Window); -- cgit v1.2.3 From 2659fbb990c9ac34153b965a4f1a24a9656f4cec Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Thu, 7 Apr 2022 14:03:28 +0200 Subject: Removes comment --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index d9d429a2..bfae9ac8 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -107,7 +107,6 @@ namespace Xwt.Mac { if (parentWindow != null && Visible) { - //if there is any child window we remove it if (!parentWindow.ChildWindows.Contains(window)) parentWindow.AddChildWindow(window, NSWindowOrderingMode.Above); } -- cgit v1.2.3 From 6128d3e3f348b8858413eaf0fb80c693d200353b Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Thu, 7 Apr 2022 14:06:30 +0200 Subject: fixes indentation --- Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs index bfae9ac8..3344bb95 100644 --- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs @@ -104,7 +104,7 @@ namespace Xwt.Mac } void TryAddChildWindowIfVisible(NSWindow parentWindow, NSWindow window) - { + { if (parentWindow != null && Visible) { if (!parentWindow.ChildWindows.Contains(window)) @@ -340,7 +340,7 @@ namespace Xwt.Mac //we try to get the native object from the parameter if not we fallback into the real parent if (ApplicationContext.Toolkit.GetNativeWindow(parent) is NSWindow nParent && nParent != Window.ParentWindow) - { + { // remove from the previous parent if (Window.ParentWindow != null) Window.ParentWindow.RemoveChildWindow(Window); -- cgit v1.2.3