diff --git a/src/Avalonia.Controls/Platform/IWindowBaseImpl.cs b/src/Avalonia.Controls/Platform/IWindowBaseImpl.cs index f043371e9d..4f7ac82df7 100644 --- a/src/Avalonia.Controls/Platform/IWindowBaseImpl.cs +++ b/src/Avalonia.Controls/Platform/IWindowBaseImpl.cs @@ -69,22 +69,8 @@ namespace Avalonia.Platform /// /// Minimum width of the window. /// - double MinWidth { get; set; } - - /// - /// Maximum width of the window. - /// - double MaxWidth { get; set; } - - /// - /// Minimum height of the window. - /// - double MinHeight { get; set; } - - /// - /// Maximum height of the window. - /// - double MaxHeight { get; set; } + /// + void SetMinMaxSize(Size minSize, Size maxSize); /// /// Gets platform specific display information diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index 16fc8117d5..c427df1c26 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -47,6 +47,11 @@ namespace Avalonia.Controls { IsVisibleProperty.OverrideDefaultValue(false); IsVisibleProperty.Changed.AddClassHandler(x => x.IsVisibleChanged); + + MinWidthProperty.Changed.AddClassHandler((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size((double)e.NewValue, w.MinHeight), new Size(w.MaxWidth, w.MaxHeight))); + MinHeightProperty.Changed.AddClassHandler((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, (double)e.NewValue), new Size(w.MaxWidth, w.MaxHeight))); + MaxWidthProperty.Changed.AddClassHandler((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size((double)e.NewValue, w.MaxHeight))); + MaxHeightProperty.Changed.AddClassHandler((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size(w.MaxWidth, (double)e.NewValue))); } public WindowBase(IWindowBaseImpl impl) : this(impl, AvaloniaLocator.Current) @@ -197,14 +202,7 @@ namespace Avalonia.Controls { using (BeginAutoSizing()) { - if (PlatformImpl != null) - { - PlatformImpl.MinHeight = MinHeight; - PlatformImpl.MaxHeight = MaxHeight; - PlatformImpl.MinWidth = MinWidth; - PlatformImpl.MaxWidth = MaxWidth; - PlatformImpl.Resize(finalSize); - } + PlatformImpl?.Resize(finalSize); } return base.ArrangeOverride(PlatformImpl?.ClientSize ?? default(Size)); diff --git a/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs b/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs index 703f5ec5c8..f2676925a3 100644 --- a/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs +++ b/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs @@ -67,13 +67,9 @@ namespace Avalonia.DesignerSupport.Remote RenderIfNeeded(); } - public double MinWidth { get; set; } - - public double MaxWidth { get; set; } - - public double MinHeight { get; set; } - - public double MaxHeight { get; set; } + public void SetMinMaxSize(Size minSize, Size maxSize) + { + } public IScreenImpl Screen { get; } = new ScreenStub(); diff --git a/src/Avalonia.DesignerSupport/Remote/Stubs.cs b/src/Avalonia.DesignerSupport/Remote/Stubs.cs index 6dd207178d..08c2c77ad1 100644 --- a/src/Avalonia.DesignerSupport/Remote/Stubs.cs +++ b/src/Avalonia.DesignerSupport/Remote/Stubs.cs @@ -78,13 +78,9 @@ namespace Avalonia.DesignerSupport.Remote public IScreenImpl Screen { get; } = new ScreenStub(); - public double MinWidth { get; set; } - - public double MaxWidth { get; set; } - - public double MinHeight { get; set; } - - public double MaxHeight { get; set; } + public void SetMinMaxSize(Size minSize, Size maxSize) + { + } public void SetTitle(string title) { diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Native.cs b/src/Gtk/Avalonia.Gtk3/Interop/Native.cs index 7cf0a0b256..0240e15a19 100644 --- a/src/Gtk/Avalonia.Gtk3/Interop/Native.cs +++ b/src/Gtk/Avalonia.Gtk3/Interop/Native.cs @@ -421,6 +421,7 @@ namespace Avalonia.Gtk3.Interop public static D.gdk_window_set_override_redirect GdkWindowSetOverrideRedirect; public static D.gtk_widget_set_size_request GtkWindowSetSizeRequest; public static D.gtk_window_set_default_size GtkWindowSetDefaultSize; + public static D.gtk_window_set_geometry_hints GtkWindowSetGeometryHints; public static D.gtk_window_get_position GtkWindowGetPosition; public static D.gtk_window_move GtkWindowMove; public static D.gtk_file_chooser_dialog_new GtkFileChooserDialogNew; @@ -503,7 +504,6 @@ namespace Avalonia.Gtk3.Interop public static D.cairo_move_to CairoMoveTo; public static D.cairo_destroy CairoDestroy; - public static D.gtk_window_set_geometry_hints GtkWindowSetGeometryHints; public const int G_TYPE_OBJECT = 80; } diff --git a/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs b/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs index 7e55892570..0ebfea998a 100644 --- a/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs +++ b/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs @@ -341,13 +341,19 @@ namespace Avalonia.Gtk3 } } - public double MinWidth { get; set; } - - public double MaxWidth { get; set; } + public void SetMinMaxSize(Size minSize, Size maxSize) + { + if (GtkWidget.IsClosed) + return; - public double MinHeight { get; set; } + GdkGeometry geometry = new GdkGeometry(); + geometry.min_width = minSize.Width > 0 ? (int)minSize.Width : -1; + geometry.min_height = minSize.Height > 0 ? (int)minSize.Height : -1; + geometry.max_width = !Double.IsInfinity(maxSize.Width) && maxSize.Width > 0 ? (int)maxSize.Width : 999999; + geometry.max_height = !Double.IsInfinity(maxSize.Height) && maxSize.Height > 0 ? (int)maxSize.Height : 999999; - public double MaxHeight { get; set; } + Native.GtkWindowSetGeometryHints(GtkWidget, IntPtr.Zero, ref geometry, GdkWindowHints.GDK_HINT_MIN_SIZE | GdkWindowHints.GDK_HINT_MAX_SIZE); + } public IMouseDevice MouseDevice => Gtk3Platform.Mouse; @@ -439,15 +445,7 @@ namespace Avalonia.Gtk3 { if (GtkWidget.IsClosed) return; - - GdkGeometry geometry = new GdkGeometry(); - geometry.min_width = MinWidth > 0 ? (int)MinWidth : -1; - geometry.min_height = MinHeight > 0 ? (int)MinHeight : -1; - geometry.max_width = !Double.IsInfinity(MaxWidth) && MaxWidth > 0 ? (int)MaxWidth : 999999; - geometry.max_height = !Double.IsInfinity(MaxHeight) && MaxHeight > 0 ? (int)MaxHeight : 999999; - - Native.GtkWindowSetGeometryHints(GtkWidget, IntPtr.Zero, ref geometry, GdkWindowHints.GDK_HINT_MIN_SIZE | GdkWindowHints.GDK_HINT_MAX_SIZE); - + Native.GtkWindowResize(GtkWidget, (int)value.Width, (int)value.Height); if (OverrideRedirect) { diff --git a/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs b/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs index 0b64aae36b..8cbc6cbdd8 100644 --- a/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs +++ b/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs @@ -161,13 +161,9 @@ namespace Avalonia.MonoMac Position = pos; } - public double MinWidth { get; set; } - - public double MaxWidth { get; set; } - - public double MinHeight { get; set; } - - public double MaxHeight { get; set; } + public void SetMinMaxSize(Size minSize, Size maxSize) + { + } public IScreenImpl Screen { diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 73d8228bab..d9d4e4520c 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -35,6 +35,9 @@ namespace Avalonia.Win32 private WindowState _showWindowState; private FramebufferManager _framebuffer; private OleDropTarget _dropTarget; + private Size _minSize; + private Size _maxSize; + #if USE_MANAGED_DRAG private readonly ManagedWindowResizeDragHelper _managedDrag; #endif @@ -102,13 +105,11 @@ namespace Avalonia.Win32 } } - public double MinWidth { get; set; } - - public double MaxWidth { get; set; } - - public double MinHeight { get; set; } - - public double MaxHeight { get; set; } + public void SetMinMaxSize(Size minSize, Size maxSize) + { + _minSize = minSize; + _maxSize = maxSize; + } public IScreenImpl Screen { @@ -624,17 +625,17 @@ namespace Avalonia.Win32 MINMAXINFO mmi = Marshal.PtrToStructure(lParam); - if (MinWidth > 0) - mmi.ptMinTrackSize.X = (int)((MinWidth * Scaling) + BorderThickness.Left + BorderThickness.Right); + if (_minSize.Width > 0) + mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right); - if (MinHeight > 0) - mmi.ptMinTrackSize.Y = (int)((MinHeight * Scaling) + BorderThickness.Top + BorderThickness.Bottom); + if (_minSize.Height > 0) + mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom); - if (!Double.IsInfinity(MaxWidth) && MaxWidth > 0) - mmi.ptMaxTrackSize.X = (int)((MaxWidth * Scaling) + BorderThickness.Left + BorderThickness.Right); + if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0) + mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right); - if (!Double.IsInfinity(MaxHeight) && MaxHeight > 0) - mmi.ptMaxTrackSize.Y = (int)((MaxHeight * Scaling) + BorderThickness.Top + BorderThickness.Bottom); + if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0) + mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom); Marshal.StructureToPtr(mmi, lParam, true); return IntPtr.Zero;