Skip to content

Commit

Permalink
Merge pull request #2733 from cwensley/curtis/mac-fix-setting-owner-o…
Browse files Browse the repository at this point in the history
…f-invisible-form

Mac: Setting Form.Owner shouldn't make it visible if previously hidden
  • Loading branch information
cwensley authored Jan 29, 2025
2 parents 6a62c13 + dfdbcfa commit 5b3fb1e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Eto.Mac/Forms/MacWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,15 @@ public override bool Visible
{
if (Visible != value)
{
if (!value)
InternalSetOwner(null);

Control.IsVisible = value;
if (Widget.Loaded && value)
{
EnsureOwner();
FireOnShown();
}
}
}
}
Expand Down Expand Up @@ -1319,7 +1325,7 @@ bool InternalSetOwner(Window owner)
// since this can get called multiple times
Widget.GotFocus -= HandleGotFocusAsChild;

if (owner != null)
if (owner != null && Visible)
{
var macWindow = owner.Handler as IMacWindow;
if (macWindow != null && macWindow.Control.TabbedWindows?.Contains(Control) != true)
Expand Down
48 changes: 48 additions & 0 deletions test/Eto.Test/UnitTests/Forms/FormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,52 @@ public void CallingShowAfterShownShouldNotBringItTopMost() => Async(-1, async ()

await tcs.Task;
});

class MyModel
{
public int IntValue { get; set; }
}

[Test]
public void HiddenFormShouldNotShowWhenSettingOwner() => Async(async () => {
var child = new Form();
var parent = new Form();
try
{
child.Content = "This form should only show briefly";
child.Size = new Size(200, 200);
child.Location = new Point(100, 100);
child.Show();
child.Visible = false;

parent.Content = "This form should show";
parent.Size = new Size(200, 200);
parent.Location = new Point(400, 400);
parent.Show();
await Task.Delay(250);
child.Owner = parent;
await Task.Delay(250);

Assert.That(child.Visible, Is.False, "Child should not be visible");
Assert.That(parent.Visible, Is.True, "Parent should be visible");

// Set visible and test
child.Visible = true;
await Task.Delay(250);
Assert.That(child.Visible, Is.True, "Child should be visible");
Assert.That(parent.Visible, Is.True, "Parent should be visible");

// Hide again
child.Visible = false;
await Task.Delay(250);

Assert.That(child.Visible, Is.False, "Child should not be visible");
Assert.That(parent.Visible, Is.True, "Parent should be visible");
}
finally
{
child.Close();
parent.Close();
}
});
}

0 comments on commit 5b3fb1e

Please sign in to comment.