Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Medrano <josmed@microsoft.com>2022-04-07 15:28:05 +0300
committerGitHub <noreply@github.com>2022-04-07 15:28:05 +0300
commit40ba4a4ef71f346fab445a40a064147eee1fdff0 (patch)
tree648af9637ff0dcf747272815cd11e575a8142882
parent54bf3faa58f3474670e732136d3bd54e9d78c168 (diff)
parent6128d3e3f348b8858413eaf0fb80c693d200353b (diff)
Merge pull request #1100 from mono/more-window-fixes
[WindowFrameBackend] Only add parenting when dialog is preparing it be shown
-rw-r--r--Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs42
-rw-r--r--Xwt/Xwt/WindowFrame.cs2
2 files changed, 22 insertions, 22 deletions
diff --git a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs
index d5bde8af..3344bb95 100644
--- a/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs
+++ b/Xwt.XamMac/Xwt.Mac/WindowFrameBackend.cs
@@ -96,19 +96,19 @@ 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;
+ TryAddChildWindowIfVisible(parentWindow, Window);
+ //we center in any case
+ Util.CenterWindow(Window, parentWindow);
+ }
+
+ void TryAddChildWindowIfVisible(NSWindow parentWindow, NSWindow window)
+ {
+ if (parentWindow != null && Visible)
+ {
+ if (!parentWindow.ChildWindows.Contains(window))
+ parentWindow.AddChildWindow(window, NSWindowOrderingMode.Above);
}
}
@@ -334,20 +334,20 @@ 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) {
+ //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);
+ Window.ParentWindow.RemoveChildWindow(Window);
+
+ Window.ParentWindow = nParent;
- Window.ParentWindow = win;
- // A window must be visible to be added to a parent. See InternalShow().
- if (Visible)
- Window.ParentWindow.AddChildWindow (Window, NSWindowOrderingMode.Above);
+ TryAddChildWindowIfVisible(nParent, Window);
}
}
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);
}
}