Browse Source

Convert max window size to client size.

pull/145/head
Steven Kirk 11 years ago
parent
commit
a18bc4d913
  1. 5
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  2. 2
      src/Perspex.Controls/Platform/IWindowImpl.cs
  3. 6
      src/Perspex.Controls/Window.cs
  4. 26
      src/Perspex.SceneGraph/Thickness.cs
  5. 49
      src/Windows/Perspex.Win32/WindowImpl.cs

5
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -57,11 +57,12 @@ namespace Perspex.Gtk
set;
}
public Size MaxWindowSize
public Size MaxClientSize
{
get
{
// TODO: This should take into account things such as taskbar etc.
// TODO: This should take into account things such as taskbar and window border
// thickness etc.
return new Size(Screen.Width, Screen.Height);
}
}

2
src/Perspex.Controls/Platform/IWindowImpl.cs

@ -13,7 +13,7 @@ namespace Perspex.Platform
/// <summary>
/// Gets the maximum size of a window on the system.
/// </summary>
Size MaxWindowSize { get; }
Size MaxClientSize { get; }
/// <summary>
/// Sets the title of the window.

6
src/Perspex.Controls/Window.cs

@ -57,7 +57,7 @@ namespace Perspex.Controls
private object _dialogResult;
private Size _maxPlatformWindowSize;
private Size _maxPlatformClientSize;
/// <summary>
/// Initializes static members of the <see cref="Window"/> class.
@ -74,7 +74,7 @@ namespace Perspex.Controls
public Window()
: base(Locator.Current.GetService<IWindowImpl>())
{
_maxPlatformWindowSize = this.PlatformImpl.MaxWindowSize;
_maxPlatformClientSize = this.PlatformImpl.MaxClientSize;
}
/// <summary>
@ -196,7 +196,7 @@ namespace Perspex.Controls
{
var sizeToContent = SizeToContent;
var size = ClientSize;
var desired = base.MeasureOverride(availableSize.Constrain(_maxPlatformWindowSize));
var desired = base.MeasureOverride(availableSize.Constrain(_maxPlatformClientSize));
switch (sizeToContent)
{

26
src/Perspex.SceneGraph/Thickness.cs

@ -138,6 +138,32 @@ namespace Perspex
a.Bottom + b.Bottom);
}
/// <summary>
/// Adds a Thickness to a Size.
/// </summary>
/// <param name="size">The size.</param>
/// <param name="thickness">The thickness.</param>
/// <returns>The equality.</returns>
public static Size operator +(Size size, Thickness thickness)
{
return new Size(
size.Width + thickness.Left + thickness.Right,
size.Height + thickness.Top + thickness.Bottom);
}
/// <summary>
/// Subtracts a Thickness from a Size.
/// </summary>
/// <param name="size">The size.</param>
/// <param name="thickness">The thickness.</param>
/// <returns>The equality.</returns>
public static Size operator -(Size size, Thickness thickness)
{
return new Size(
size.Width - (thickness.Left + thickness.Right),
size.Height - (thickness.Top + thickness.Bottom));
}
/// <summary>
/// Parses a <see cref="Thickness"/> string.
/// </summary>

49
src/Windows/Perspex.Win32/WindowImpl.cs

@ -53,6 +53,25 @@ namespace Perspex.Win32
public Action<Size> Resized { get; set; }
public Thickness BorderThickness
{
get
{
var style = UnmanagedMethods.GetWindowLong(_hwnd, -16);
var exStyle = UnmanagedMethods.GetWindowLong(_hwnd, -20);
var padding = new UnmanagedMethods.RECT();
if (UnmanagedMethods.AdjustWindowRectEx(ref padding, style, false, exStyle))
{
return new Thickness(-padding.left, -padding.top, padding.right, padding.bottom);
}
else
{
throw new Win32Exception();
}
}
}
public Size ClientSize
{
get
@ -66,21 +85,16 @@ namespace Perspex.Win32
{
if (value != ClientSize)
{
var style = UnmanagedMethods.GetWindowLong(_hwnd, -16);
var exStyle = UnmanagedMethods.GetWindowLong(_hwnd, -20);
var padding = new UnmanagedMethods.RECT();
if (UnmanagedMethods.AdjustWindowRectEx(ref padding, style, false, exStyle))
{
UnmanagedMethods.SetWindowPos(
_hwnd,
IntPtr.Zero,
0,
0,
-padding.left + padding.right + (int)value.Width,
-padding.top + padding.bottom + (int)value.Height,
UnmanagedMethods.SetWindowPosFlags.SWP_RESIZE);
}
value += BorderThickness;
UnmanagedMethods.SetWindowPos(
_hwnd,
IntPtr.Zero,
0,
0,
(int)value.Width,
(int)value.Height,
UnmanagedMethods.SetWindowPosFlags.SWP_RESIZE);
}
}
}
@ -97,13 +111,14 @@ namespace Perspex.Win32
set { UnmanagedMethods.EnableWindow(_hwnd, value); }
}
public Size MaxWindowSize
public Size MaxClientSize
{
get
{
return new Size(
UnmanagedMethods.GetSystemMetrics(UnmanagedMethods.SystemMetric.SM_CXMAXTRACK),
UnmanagedMethods.GetSystemMetrics(UnmanagedMethods.SystemMetric.SM_CYMAXTRACK));
UnmanagedMethods.GetSystemMetrics(UnmanagedMethods.SystemMetric.SM_CYMAXTRACK))
- BorderThickness;
}
}

Loading…
Cancel
Save