Browse Source

Added PositionChanged event in TopLevel

Implements #629
pull/683/head
OronDF343 10 years ago
parent
commit
5e0243cfba
  1. 2
      src/Android/Avalonia.Android/Platform/SkiaPlatform/WindowImpl.cs
  2. 1
      src/Avalonia.Controls/Avalonia.Controls.csproj
  3. 5
      src/Avalonia.Controls/Platform/ITopLevelImpl.cs
  4. 27
      src/Avalonia.Controls/PositionChangedEventArgs.cs
  5. 16
      src/Avalonia.Controls/TopLevel.cs
  6. 13
      src/Gtk/Avalonia.Gtk/WindowImpl.cs
  7. 6
      src/Windows/Avalonia.Win32/WindowImpl.cs
  8. 12
      src/iOS/Avalonia.iOS/AvaloniaView.cs

2
src/Android/Avalonia.Android/Platform/SkiaPlatform/WindowImpl.cs

@ -87,6 +87,8 @@ namespace Avalonia.Android.Platform.SkiaPlatform
public Action<double> ScalingChanged { get; set; }
public Action<Point> PositionChanged { get; set; }
public View View => this;
Action ITopLevelImpl.Activated { get; set; }

1
src/Avalonia.Controls/Avalonia.Controls.csproj

@ -56,6 +56,7 @@
<Compile Include="HotkeyManager.cs" />
<Compile Include="IApplicationLifecycle.cs" />
<Compile Include="IScrollable.cs" />
<Compile Include="PositionChangedEventArgs.cs" />
<Compile Include="WindowIcon.cs" />
<Compile Include="IPseudoClasses.cs" />
<Compile Include="DropDownItem.cs" />

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

@ -67,6 +67,11 @@ namespace Avalonia.Platform
/// </summary>
Action<double> ScalingChanged { get; set; }
/// <summary>
/// Gets or sets a method called when the window's position changes.
/// </summary>
Action<Point> PositionChanged { get; set; }
/// <summary>
/// Activates the window.
/// </summary>

27
src/Avalonia.Controls/PositionChangedEventArgs.cs

@ -0,0 +1,27 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
namespace Avalonia.Controls
{
/// <summary>
/// Provides data for the <see cref="TopLevel.PositionChanged"/> event.
/// </summary>
public class PositionChangedEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="PositionChangedEventArgs"/> class.
/// </summary>
/// <param name="newPos">The new window position.</param>
public PositionChangedEventArgs(Point newPos)
{
NewPosition = newPos;
}
/// <summary>
/// Gets the new window position.
/// </summary>
public Point NewPosition { get; }
}
}

16
src/Avalonia.Controls/TopLevel.cs

@ -105,6 +105,7 @@ namespace Avalonia.Controls
PlatformImpl.Input = HandleInput;
PlatformImpl.Resized = HandleResized;
PlatformImpl.ScalingChanged = HandleScalingChanged;
PlatformImpl.PositionChanged = HandlePositionChanged;
_keyboardNavigationHandler?.SetOwner(this);
_accessKeyHandler?.SetOwner(this);
@ -138,6 +139,11 @@ namespace Avalonia.Controls
/// </summary>
public event EventHandler Deactivated;
/// <summary>
/// Fired when the window position is changed.
/// </summary>
public event EventHandler<PositionChangedEventArgs> PositionChanged;
/// <summary>
/// Gets or sets the client size of the window.
/// </summary>
@ -395,6 +401,16 @@ namespace Avalonia.Controls
_inputManager.ProcessInput(e);
}
/// <summary>
/// Handles a window position change notification from
/// <see cref="ITopLevelImpl.PositionChanged"/>.
/// </summary>
/// <param name="pos">The window position.</param>
private void HandlePositionChanged(Point pos)
{
PositionChanged?.Invoke(this, new PositionChangedEventArgs(pos));
}
/// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler
/// </summary>

13
src/Gtk/Avalonia.Gtk/WindowImpl.cs

@ -23,6 +23,8 @@ namespace Avalonia.Gtk
private Size _lastClientSize;
private Point _lastPosition;
private Gtk.IMContext _imContext;
private uint _lastKeyEventTimestamp;
@ -52,6 +54,7 @@ namespace Avalonia.Gtk
DoubleBuffered = false;
Realize();
_lastClientSize = ClientSize;
_lastPosition = Position;
}
protected override void OnRealized ()
@ -175,6 +178,8 @@ namespace Avalonia.Gtk
public Action<double> ScalingChanged { get; set; }
public Action<Point> PositionChanged { get; set; }
public IPopupImpl CreatePopup()
{
return new PopupImpl();
@ -338,6 +343,14 @@ namespace Avalonia.Gtk
_lastClientSize = newSize;
}
var newPosition = new Point(evnt.X, evnt.Y);
if (newPosition != _lastPosition)
{
PositionChanged(newPosition);
_lastPosition = newPosition;
}
return true;
}

6
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -55,6 +55,8 @@ namespace Avalonia.Win32
public Action<double> ScalingChanged { get; set; }
public Action<Point> PositionChanged { get; set; }
public Thickness BorderThickness
{
get
@ -561,6 +563,10 @@ namespace Avalonia.Win32
}
return IntPtr.Zero;
case UnmanagedMethods.WindowsMessage.WM_MOVE:
PositionChanged?.Invoke(new Point(ToInt32(lParam) & 0xffff, ToInt32(lParam) >> 16));
return IntPtr.Zero;
}
if (e != null && Input != null)

12
src/iOS/Avalonia.iOS/AvaloniaView.cs

@ -27,6 +27,7 @@ namespace Avalonia.iOS
private readonly UIViewController _controller;
private IInputRoot _inputRoot;
private readonly KeyboardEventsHelper<AvaloniaView> _keyboardHelper;
private Point _position;
public AvaloniaView(UIWindow window, UIViewController controller) : base(onFrame => PlatformThreadingInterface.Instance.Render = onFrame)
{
@ -72,6 +73,7 @@ namespace Avalonia.iOS
public Action<Rect> Paint { get; set; }
public Action<Size> Resized { get; set; }
public Action<double> ScalingChanged { get; set; }
public Action<Point> PositionChanged { get; set; }
public IPlatformHandle Handle => AvaloniaPlatformHandle;
@ -136,7 +138,15 @@ namespace Avalonia.iOS
//Not supported
}
public Point Position { get; set; }
public Point Position
{
get { return _position; }
set
{
_position = value;
PositionChanged?.Invoke(_position);
}
}
public Size MaxClientSize => Bounds.Size.ToAvalonia();
public void SetTitle(string title)

Loading…
Cancel
Save