Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Add MacWindow.FullSizeContentView and Window fixes #2323

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/monomac
Submodule monomac updated 2 files
+66 −13 src/AppKit/Enums.cs
+161 −0 src/appkit.cs
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/FloatingFormHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void SetLevelAdjustment()
// only need to adjust level when window style is not utility and we actually want it to be topmost (default for FloatingForm).
var wantsTopmost = WantsTopmost;
var owner = Widget.Owner;
var needsLevelAdjust = wantsTopmost && WindowStyle != WindowStyle.Utility && owner != null;
var needsLevelAdjust = wantsTopmost && owner != null;

var lastOwner = Widget.Properties.Get<Window>(LastOwner_Key);

Expand Down
44 changes: 37 additions & 7 deletions src/Eto.Mac/Forms/MacWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void SetButtonStates()
button.Hidden = hideButtons;
button.Enabled = Minimizable;
}

button = Control.StandardWindowButton(NSWindowButton.CloseButton);
if (button != null)
{
Expand Down Expand Up @@ -615,7 +615,7 @@ public bool ShowInTaskbar
get;
set;
}

public bool Closeable
{
get { return Control.StyleMask.HasFlag(NSWindowStyle.Closable); }
Expand Down Expand Up @@ -647,9 +647,9 @@ public virtual bool Topmost
}
}
}

internal virtual bool DefaultTopmost => false;

internal bool WantsTopmost
{
get => Widget.Properties.Get(MacWindow.Topmost_Key, DefaultTopmost);
Expand Down Expand Up @@ -1272,16 +1272,16 @@ public virtual void SetOwner(Window owner)
}
}
}

void HandleGotFocusAsChild(object sender, EventArgs e)
{
// When there are multiple modeless child windows, clicking on one doesn't bring it to front
// so, we remove then re-add the child window to get it to come above again.
var parentWindow = Control.ParentWindow;
var childWindows = parentWindow?.ChildWindows;

// .. only if it isn't already the last child window
if (parentWindow != null && childWindows?.Length > 1 && !Equals(Control.Handle, childWindows[childWindows.Length -1].Handle))
if (parentWindow != null && childWindows?.Length > 1 && !Equals(Control.Handle, childWindows[childWindows.Length - 1].Handle))
{
parentWindow.RemoveChildWindow(Control);
parentWindow.AddChildWindow(Control, NSWindowOrderingMode.Above);
Expand All @@ -1295,5 +1295,35 @@ internal virtual void OnSetAsChildWindow()
}

public float LogicalPixelSize => Screen?.LogicalPixelSize ?? 1f;

public bool FullSizeContentView
{
get => Control.StyleMask.HasFlag(NSWindowStyle.FullSizeContentView);
set
{
if (value)
{
Control.TitleVisibility = NSWindowTitleVisibility.Hidden;
Control.TitlebarAppearsTransparent = true;
Control.StyleMask |= NSWindowStyle.FullSizeContentView;
}
else
{
Control.TitleVisibility = NSWindowTitleVisibility.Visible;
Control.TitlebarAppearsTransparent = false;
Control.StyleMask &= ~NSWindowStyle.FullSizeContentView;
}
}
}

protected override void Dispose(bool disposing)
{
if (disposing && Widget.Loaded)
{
// we can't cancel closing in this case, so don't bother firing the closing event
Control.Close();
}
base.Dispose(disposing);
}
}
}
76 changes: 33 additions & 43 deletions test/Eto.Test/Sections/Behaviors/WindowsSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ public class WindowsSection : Panel, INotifyPropertyChanged
EnumRadioButtonList<WindowStyle> styleCombo;
EnumRadioButtonList<WindowState> stateCombo;
EnumRadioButtonList<WindowType> typeRadio;
CheckBox resizableCheckBox;
CheckBox maximizableCheckBox;
CheckBox minimizableCheckBox;
CheckBox movableByWindowBackgroundCheckBox;
CheckBox showInTaskBarCheckBox;
CheckBox closeableCheckBox;
CheckBox topMostCheckBox;
CheckBox setOwnerCheckBox;
CheckBox visibleCheckBox;
CheckBox showActivatedCheckBox;
CheckBox canFocusCheckBox;
CheckBox createMenuBar;
EnumCheckBoxList<MenuBarSystemItems> systemMenuItems;
EnumDropDown<DialogDisplayMode?> dialogDisplayModeDropDown;
Expand Down Expand Up @@ -223,79 +213,79 @@ Control WindowState()

Control Resizable()
{
resizableCheckBox = new CheckBox { Text = "Resizable" };
var resizableCheckBox = new CheckBox { Text = "Resizable" };
resizableCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
resizableCheckBox.CheckedBinding.BindDataContext((Window w) => w.Resizable);
return resizableCheckBox;
}

Control Maximizable()
{
maximizableCheckBox = new CheckBox { Text = "Maximizable" };
var maximizableCheckBox = new CheckBox { Text = "Maximizable" };
maximizableCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
maximizableCheckBox.CheckedBinding.BindDataContext((Window w) => w.Maximizable);
return maximizableCheckBox;
}

Control MovableByWindowBackground()
{
movableByWindowBackgroundCheckBox = new CheckBox { Text = "MovableByWindowBackground" };
var movableByWindowBackgroundCheckBox = new CheckBox { Text = "MovableByWindowBackground" };
movableByWindowBackgroundCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
movableByWindowBackgroundCheckBox.CheckedBinding.BindDataContext((Window w) => w.MovableByWindowBackground);
return movableByWindowBackgroundCheckBox;
}

Control Minimizable()
{
minimizableCheckBox = new CheckBox { Text = "Minimizable" };
var minimizableCheckBox = new CheckBox { Text = "Minimizable" };
minimizableCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
minimizableCheckBox.CheckedBinding.BindDataContext((Window w) => w.Minimizable);
return minimizableCheckBox;
}

Control ShowInTaskBar()
{
showInTaskBarCheckBox = new CheckBox { Text = "Show In TaskBar" };
var showInTaskBarCheckBox = new CheckBox { Text = "Show In TaskBar" };
showInTaskBarCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
showInTaskBarCheckBox.CheckedBinding.BindDataContext((Window w) => w.ShowInTaskbar);
return showInTaskBarCheckBox;
}

Control CloseableCheckBox()
{
closeableCheckBox = new CheckBox { Text = "Closeable" };
var closeableCheckBox = new CheckBox { Text = "Closeable" };
closeableCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
closeableCheckBox.CheckedBinding.BindDataContext((Window w) => w.Closeable);
return closeableCheckBox;
}

Control CreateCanFocus()
{
canFocusCheckBox = new CheckBox { Text = "CanFocus" };
var canFocusCheckBox = new CheckBox { Text = "CanFocus" };
canFocusCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
canFocusCheckBox.CheckedBinding.BindDataContext((Form w) => w.CanFocus);
return canFocusCheckBox;
}

Control TopMost()
{
topMostCheckBox = new CheckBox { Text = "Top Most" };
var topMostCheckBox = new CheckBox { Text = "Top Most" };
topMostCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
topMostCheckBox.CheckedBinding.BindDataContext((Window w) => w.Topmost);
return topMostCheckBox;
}

Control VisibleCheckbox()
{
visibleCheckBox = new CheckBox { Text = "Visible" };
var visibleCheckBox = new CheckBox { Text = "Visible" };
visibleCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow w) => w.ThreeState);
visibleCheckBox.CheckedBinding.BindDataContext((Window w) => w.Visible);
return visibleCheckBox;
}

Control CreateShowActivatedCheckbox()
{
showActivatedCheckBox = new CheckBox { Text = "ShowActivated" };
var showActivatedCheckBox = new CheckBox { Text = "ShowActivated" };
showActivatedCheckBox.BindDataContext(c => c.ThreeState, (SettingsWindow s) => s.ThreeState);
showActivatedCheckBox.CheckedBinding.BindDataContext((Form w) => w.ShowActivated);
showActivatedCheckBox.Bind(c => c.Enabled, typeRadio, Binding.Property((RadioButtonList t) => t.SelectedKey).ToBool("dialog").Convert(v => !v));
Expand Down Expand Up @@ -457,21 +447,21 @@ void CreateChild()
var form = new Form();
child = form;
show = form.Show;
if (showActivatedCheckBox.Checked != null)
form.ShowActivated = showActivatedCheckBox.Checked == true;
if (canFocusCheckBox.Checked != null)
form.CanFocus = canFocusCheckBox.Checked == true;
if (settings.ShowActivated != null)
form.ShowActivated = settings.ShowActivated == true;
if (settings.CanFocus != null)
form.CanFocus = settings.CanFocus == true;
}
break;
case WindowType.FloatingForm:
{
var form = new FloatingForm();
child = form;
show = form.Show;
if (showActivatedCheckBox.Checked != null)
form.ShowActivated = showActivatedCheckBox.Checked == true;
if (canFocusCheckBox.Checked != null)
form.CanFocus = canFocusCheckBox.Checked == true;
if (settings.ShowActivated != null)
form.ShowActivated = settings.ShowActivated == true;
if (settings.CanFocus != null)
form.CanFocus = settings.CanFocus == true;
}
break;
case WindowType.Dialog:
Expand Down Expand Up @@ -513,20 +503,20 @@ void CreateChild()
if (styleCombo.Enabled)
child.WindowStyle = styleCombo.SelectedValue;
child.WindowState = stateCombo.SelectedValue;
if (topMostCheckBox.Checked != null)
child.Topmost = topMostCheckBox.Checked ?? false;
if (resizableCheckBox.Checked != null)
child.Resizable = resizableCheckBox.Checked ?? false;
if (maximizableCheckBox.Checked != null)
child.Maximizable = maximizableCheckBox.Checked ?? false;
if (minimizableCheckBox.Checked != null)
child.Minimizable = minimizableCheckBox.Checked ?? false;
if (showInTaskBarCheckBox.Checked != null)
child.ShowInTaskbar = showInTaskBarCheckBox.Checked ?? false;
if (closeableCheckBox.Checked != null)
child.Closeable = closeableCheckBox.Checked ?? false;
if (movableByWindowBackgroundCheckBox.Checked != null)
child.MovableByWindowBackground = movableByWindowBackgroundCheckBox.Checked ?? false;
if (settings.Topmost != null)
child.Topmost = settings.Topmost ?? false;
if (settings.Resizable != null)
child.Resizable = settings.Resizable ?? false;
if (settings.Maximizable != null)
child.Maximizable = settings.Maximizable ?? false;
if (settings.Minimizable != null)
child.Minimizable = settings.Minimizable ?? false;
if (settings.ShowInTaskbar != null)
child.ShowInTaskbar = settings.ShowInTaskbar ?? false;
if (settings.Closeable != null)
child.Closeable = settings.Closeable ?? false;
if (settings.MovableByWindowBackground != null)
child.MovableByWindowBackground = settings.MovableByWindowBackground ?? false;
if (setInitialLocation)
child.Location = initialLocation;
if (setInitialClientSize)
Expand Down