Browse Source

Listen for DPI changes and update layout.

pull/447/head
Steven Kirk 10 years ago
parent
commit
e55ecb9960
  1. 2
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  2. 5
      src/Perspex.Controls/Platform/ITopLevelImpl.cs
  3. 8
      src/Perspex.Controls/Platform/PlatformManager.cs
  4. 15
      src/Perspex.Controls/TopLevel.cs
  5. 1
      src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs
  6. 8
      src/Windows/Perspex.Win32/WindowImpl.cs

2
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -129,6 +129,8 @@ namespace Perspex.Gtk
public Action<Size> Resized { get; set; } public Action<Size> Resized { get; set; }
public Action<double> ScalingChanged { get; set; }
public IPopupImpl CreatePopup() public IPopupImpl CreatePopup()
{ {
return new PopupImpl(); return new PopupImpl();

5
src/Perspex.Controls/Platform/ITopLevelImpl.cs

@ -62,6 +62,11 @@ namespace Perspex.Platform
/// </summary> /// </summary>
Action<Size> Resized { get; set; } Action<Size> Resized { get; set; }
/// <summary>
/// Gets or sets a method called when the window's scaling changes.
/// </summary>
Action<double> ScalingChanged { get; set; }
/// <summary> /// <summary>
/// Activates the window. /// Activates the window.
/// </summary> /// </summary>

8
src/Perspex.Controls/Platform/PlatformManager.cs

@ -131,8 +131,6 @@ namespace Perspex.Controls.Platform
public Action<Rect> Paint { get; set; } public Action<Rect> Paint { get; set; }
public Action<Size> Resized { get; set; } public Action<Size> Resized { get; set; }
public Action Activated public Action Activated
{ {
get { return _tl.Activated; } get { return _tl.Activated; }
@ -151,6 +149,12 @@ namespace Perspex.Controls.Platform
set { _tl.Deactivated = value; } set { _tl.Deactivated = value; }
} }
public Action<double> ScalingChanged
{
get { return _tl.ScalingChanged; }
set { _tl.ScalingChanged = value; }
}
public void Dispose() => _tl.Dispose(); public void Dispose() => _tl.Dispose();
public IPlatformHandle Handle => _tl.Handle; public IPlatformHandle Handle => _tl.Handle;

15
src/Perspex.Controls/TopLevel.cs

@ -12,6 +12,7 @@ using Perspex.Layout;
using Perspex.Platform; using Perspex.Platform;
using Perspex.Rendering; using Perspex.Rendering;
using Perspex.Styling; using Perspex.Styling;
using Perspex.VisualTree;
namespace Perspex.Controls namespace Perspex.Controls
{ {
@ -99,6 +100,7 @@ namespace Perspex.Controls
PlatformImpl.Closed = HandleClosed; PlatformImpl.Closed = HandleClosed;
PlatformImpl.Input = HandleInput; PlatformImpl.Input = HandleInput;
PlatformImpl.Resized = HandleResized; PlatformImpl.Resized = HandleResized;
PlatformImpl.ScalingChanged = HandleScalingChanged;
_keyboardNavigationHandler?.SetOwner(this); _keyboardNavigationHandler?.SetOwner(this);
_accessKeyHandler?.SetOwner(this); _accessKeyHandler?.SetOwner(this);
@ -280,6 +282,19 @@ namespace Perspex.Controls
PlatformImpl.Invalidate(new Rect(clientSize)); PlatformImpl.Invalidate(new Rect(clientSize));
} }
/// <summary>
/// Handles a window scaling change notification from
/// <see cref="ITopLevelImpl.ScalingChanged"/>.
/// </summary>
/// <param name="scaling">The window scaling.</param>
protected virtual void HandleScalingChanged(double scaling)
{
foreach (ILayoutable control in this.GetSelfAndVisualDescendents())
{
control.InvalidateMeasure();
}
}
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{ {

1
src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs

@ -489,6 +489,7 @@ namespace Perspex.Win32.Interop
WM_WTSSESSION_CHANGE = 0x02B1, WM_WTSSESSION_CHANGE = 0x02B1,
WM_TABLET_FIRST = 0x02c0, WM_TABLET_FIRST = 0x02c0,
WM_TABLET_LAST = 0x02df, WM_TABLET_LAST = 0x02df,
WM_DPICHANGED = 0x02E0,
WM_CUT = 0x0300, WM_CUT = 0x0300,
WM_COPY = 0x0301, WM_COPY = 0x0301,
WM_PASTE = 0x0302, WM_PASTE = 0x0302,

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

@ -52,6 +52,8 @@ namespace Perspex.Win32
public Action<Size> Resized { get; set; } public Action<Size> Resized { get; set; }
public Action<double> ScalingChanged { get; set; }
public Thickness BorderThickness public Thickness BorderThickness
{ {
get get
@ -359,6 +361,12 @@ namespace Perspex.Win32
return IntPtr.Zero; return IntPtr.Zero;
case UnmanagedMethods.WindowsMessage.WM_DPICHANGED:
var dpi = (int)wParam & 0xffff;
_scaling = dpi / 96.0;
ScalingChanged?.Invoke(_scaling);
break;
case UnmanagedMethods.WindowsMessage.WM_KEYDOWN: case UnmanagedMethods.WindowsMessage.WM_KEYDOWN:
case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN: case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN:
e = new RawKeyEventArgs( e = new RawKeyEventArgs(

Loading…
Cancel
Save