Browse Source

replace Min Max properties with function

pull/1495/head
Stano Turza 8 years ago
parent
commit
586e8654f3
  1. 18
      src/Avalonia.Controls/Platform/IWindowBaseImpl.cs
  2. 14
      src/Avalonia.Controls/WindowBase.cs
  3. 10
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  4. 10
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  5. 2
      src/Gtk/Avalonia.Gtk3/Interop/Native.cs
  6. 26
      src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs
  7. 10
      src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs
  8. 31
      src/Windows/Avalonia.Win32/WindowImpl.cs

18
src/Avalonia.Controls/Platform/IWindowBaseImpl.cs

@ -69,22 +69,8 @@ namespace Avalonia.Platform
/// <summary>
/// Minimum width of the window.
/// </summary>
double MinWidth { get; set; }
/// <summary>
/// Maximum width of the window.
/// </summary>
double MaxWidth { get; set; }
/// <summary>
/// Minimum height of the window.
/// </summary>
double MinHeight { get; set; }
/// <summary>
/// Maximum height of the window.
/// </summary>
double MaxHeight { get; set; }
///
void SetMinMaxSize(Size minSize, Size maxSize);
/// <summary>
/// Gets platform specific display information

14
src/Avalonia.Controls/WindowBase.cs

@ -47,6 +47,11 @@ namespace Avalonia.Controls
{
IsVisibleProperty.OverrideDefaultValue<WindowBase>(false);
IsVisibleProperty.Changed.AddClassHandler<WindowBase>(x => x.IsVisibleChanged);
MinWidthProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size((double)e.NewValue, w.MinHeight), new Size(w.MaxWidth, w.MaxHeight)));
MinHeightProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, (double)e.NewValue), new Size(w.MaxWidth, w.MaxHeight)));
MaxWidthProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size((double)e.NewValue, w.MaxHeight)));
MaxHeightProperty.Changed.AddClassHandler<WindowBase>((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));

10
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();

10
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)
{

2
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;
}

26
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)
{

10
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
{

31
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<UnmanagedMethods.MINMAXINFO>(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;

Loading…
Cancel
Save