Browse Source

Merge pull request #683 from OronDF343/master

Added Window.PositionChanged
pull/727/head
Steven Kirk 10 years ago
committed by GitHub
parent
commit
cd2f5f291a
  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/PointEventArgs.cs
  5. 16
      src/Avalonia.Controls/TopLevel.cs
  6. 20
      src/Gtk/Avalonia.Gtk/WindowImpl.cs
  7. 2
      src/Gtk/Avalonia.Gtk/WindowImplBase.cs
  8. 6
      src/Windows/Avalonia.Win32/WindowImpl.cs
  9. 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="PointEventArgs.cs" />
<Compile Include="Embedding\EmbeddableControlRoot.cs" />
<Compile Include="Platform\IEmbeddableWindowImpl.cs" />
<Compile Include="WindowIcon.cs" />

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

@ -72,6 +72,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/PointEventArgs.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 <see cref="Point"/> data for events.
/// </summary>
public class PointEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="PointEventArgs"/> class.
/// </summary>
/// <param name="point">The <see cref="Point"/> data.</param>
public PointEventArgs(Point point)
{
Point = point;
}
/// <summary>
/// Gets the <see cref="Point"/> data.
/// </summary>
public Point Point { 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<PointEventArgs> 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 PointEventArgs(pos));
}
/// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler
/// </summary>

20
src/Gtk/Avalonia.Gtk/WindowImpl.cs

@ -10,9 +10,7 @@ namespace Avalonia.Gtk
{
private Gtk.Window _window;
private Gtk.Window Window => _window ?? (_window = (Gtk.Window) Widget);
public WindowImpl(Gtk.WindowType type) : base(new PlatformHandleAwareWindow(type))
{
Init();
@ -29,8 +27,10 @@ namespace Avalonia.Gtk
Window.FocusActivated += OnFocusActivated;
Window.ConfigureEvent += OnConfigureEvent;
_lastClientSize = ClientSize;
_lastPosition = Position;
}
private Size _lastClientSize;
private Point _lastPosition;
void OnConfigureEvent(object o, Gtk.ConfigureEventArgs args)
{
var evnt = args.Event;
@ -42,6 +42,14 @@ namespace Avalonia.Gtk
Resized(newSize);
_lastClientSize = newSize;
}
var newPosition = new Point(evnt.X, evnt.Y);
if (newPosition != _lastPosition)
{
PositionChanged(newPosition);
_lastPosition = newPosition;
}
}
public override Size ClientSize
@ -107,12 +115,12 @@ namespace Avalonia.Gtk
return Disposable.Empty;
}
public override void SetSystemDecorations(bool enabled) => Window.Decorated = enabled;
public override void SetIcon(IWindowIconImpl icon)
{
Window.Icon = ((IconImpl)icon).Pixbuf;
}
}
}
}

2
src/Gtk/Avalonia.Gtk/WindowImplBase.cs

@ -122,6 +122,8 @@ namespace Avalonia.Gtk
public Action<Rect> Paint { get; set; }
public Action<Size> Resized { get; set; }
public Action<Point> PositionChanged { get; set; }
public Action<double> ScalingChanged { get; set; }

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((short)(ToInt32(lParam) & 0xffff), (short)(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