Browse Source

Merge branch 'master' into fixes/wpfgridcleanup

pull/2620/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
4abc37aa2e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      readme.md
  2. 4
      samples/ControlCatalog/Pages/DataGridPage.xaml
  3. 5
      src/Avalonia.Base/Utilities/MathUtilities.cs
  4. 2
      src/Avalonia.Controls/Grid.cs
  5. 9
      src/Avalonia.Input/MouseDevice.cs
  6. 6
      src/Avalonia.Input/Pointer.cs
  7. 28
      src/Windows/Avalonia.Win32.Interop/Wpf/WpfMouseDevice.cs
  8. 26
      src/Windows/Avalonia.Win32/Input/WindowsMouseDevice.cs
  9. 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

4
readme.md

@ -8,9 +8,9 @@
## About ## About
Avalonia is a WPF-inspired cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of OSs: Windows (.NET Framework, .NET Core), Linux (GTK), MacOS, Android and iOS. Avalonia is a WPF/UWP-inspired cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of OSs: Windows (.NET Framework, .NET Core), Linux (libX11), MacOS, Android (experimental) and iOS (exprerimental).
**Avalonia is currently in beta** which means that the framework is generally usable for writing applications, but there may be some bugs and breaking changes as we continue development. **Avalonia is currently in beta** which means that the framework is generally usable for writing applications, but there may be some bugs and breaking changes as we continue development, for more details about the status see https://github.com/AvaloniaUI/Avalonia/issues/2239
| Control catalog | Desktop platforms | Mobile platforms | | Control catalog | Desktop platforms | Mobile platforms |
|---|---|---| |---|---|---|

4
samples/ControlCatalog/Pages/DataGridPage.xaml

@ -11,7 +11,7 @@
<Setter Property="Background" Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}" /> <Setter Property="Background" Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}" />
</Style> </Style>
</UserControl.Styles> </UserControl.Styles>
<Grid RowDefinitions="Auto,Auto"> <Grid RowDefinitions="Auto,*">
<StackPanel Orientation="Vertical" Spacing="4" Grid.Row="0"> <StackPanel Orientation="Vertical" Spacing="4" Grid.Row="0">
<TextBlock Classes="h1">DataGrid</TextBlock> <TextBlock Classes="h1">DataGrid</TextBlock>
<TextBlock Classes="h2">A control for displaying and interacting with a data source.</TextBlock> <TextBlock Classes="h2">A control for displaying and interacting with a data source.</TextBlock>
@ -52,4 +52,4 @@
</TabItem> </TabItem>
</TabControl> </TabControl>
</Grid> </Grid>
</UserControl> </UserControl>

5
src/Avalonia.Base/Utilities/MathUtilities.cs

@ -30,6 +30,7 @@ namespace Avalonia.Utilities
/// LessThan - Returns whether or not the first double is less than the second double. /// LessThan - Returns whether or not the first double is less than the second double.
/// That is, whether or not the first is strictly less than *and* not within epsilon of /// That is, whether or not the first is strictly less than *and* not within epsilon of
/// the other number. /// the other number.
/// </summary>
/// <param name="value1"> The first double to compare. </param> /// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param> /// <param name="value2"> The second double to compare. </param>
public static bool LessThan(double value1, double value2) public static bool LessThan(double value1, double value2)
@ -41,6 +42,7 @@ namespace Avalonia.Utilities
/// GreaterThan - Returns whether or not the first double is greater than the second double. /// GreaterThan - Returns whether or not the first double is greater than the second double.
/// That is, whether or not the first is strictly greater than *and* not within epsilon of /// That is, whether or not the first is strictly greater than *and* not within epsilon of
/// the other number. /// the other number.
/// </summary>
/// <param name="value1"> The first double to compare. </param> /// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param> /// <param name="value2"> The second double to compare. </param>
public static bool GreaterThan(double value1, double value2) public static bool GreaterThan(double value1, double value2)
@ -52,6 +54,7 @@ namespace Avalonia.Utilities
/// LessThanOrClose - Returns whether or not the first double is less than or close to /// LessThanOrClose - Returns whether or not the first double is less than or close to
/// the second double. That is, whether or not the first is strictly less than or within /// the second double. That is, whether or not the first is strictly less than or within
/// epsilon of the other number. /// epsilon of the other number.
/// </summary>
/// <param name="value1"> The first double to compare. </param> /// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param> /// <param name="value2"> The second double to compare. </param>
public static bool LessThanOrClose(double value1, double value2) public static bool LessThanOrClose(double value1, double value2)
@ -170,4 +173,4 @@ namespace Avalonia.Utilities
} }
} }
} }
} }

2
src/Avalonia.Controls/Grid.cs

@ -1726,7 +1726,7 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
/// <param name="definitions">Array of definitions to process.</param> /// <param name="definitions">Array of definitions to process.</param>
/// <param name="finalSize">Final size to lay out to.</param> /// <param name="finalSize">Final size to lay out to.</param>
/// <param name="columns">True if sizing row definitions, false for columns</param> /// <param name="columns">True if sizing column definitions, false for rows</param>
private void SetFinalSize( private void SetFinalSize(
IReadOnlyList<DefinitionBase> definitions, IReadOnlyList<DefinitionBase> definitions,
double finalSize, double finalSize,

9
src/Avalonia.Input/MouseDevice.cs

@ -20,8 +20,13 @@ namespace Avalonia.Input
private Rect _lastClickRect; private Rect _lastClickRect;
private ulong _lastClickTime; private ulong _lastClickTime;
private readonly Pointer _pointer = new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true); private readonly Pointer _pointer;
public MouseDevice(Pointer pointer = null)
{
_pointer = pointer ?? new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true);
}
/// <summary> /// <summary>
/// Gets the control that is currently capturing by the mouse, if any. /// Gets the control that is currently capturing by the mouse, if any.
/// </summary> /// </summary>
@ -51,7 +56,7 @@ namespace Avalonia.Input
/// within the control's bounds or not. The current mouse capture control is exposed /// within the control's bounds or not. The current mouse capture control is exposed
/// by the <see cref="Captured"/> property. /// by the <see cref="Captured"/> property.
/// </remarks> /// </remarks>
public virtual void Capture(IInputElement control) public void Capture(IInputElement control)
{ {
_pointer.Capture(control); _pointer.Capture(control);
} }

6
src/Avalonia.Input/Pointer.cs

@ -27,6 +27,11 @@ namespace Avalonia.Input
var seen = new HashSet<IInputElement>(control1.GetSelfAndVisualAncestors().OfType<IInputElement>()); var seen = new HashSet<IInputElement>(control1.GetSelfAndVisualAncestors().OfType<IInputElement>());
return control2.GetSelfAndVisualAncestors().OfType<IInputElement>().FirstOrDefault(seen.Contains); return control2.GetSelfAndVisualAncestors().OfType<IInputElement>().FirstOrDefault(seen.Contains);
} }
protected virtual void PlatformCapture(IInputElement element)
{
}
public void Capture(IInputElement control) public void Capture(IInputElement control)
{ {
@ -34,6 +39,7 @@ namespace Avalonia.Input
Captured.DetachedFromVisualTree -= OnCaptureDetached; Captured.DetachedFromVisualTree -= OnCaptureDetached;
var oldCapture = control; var oldCapture = control;
Captured = control; Captured = control;
PlatformCapture(control);
if (oldCapture != null) if (oldCapture != null)
{ {
var commonParent = FindCommonParent(control, oldCapture); var commonParent = FindCommonParent(control, oldCapture);

28
src/Windows/Avalonia.Win32.Interop/Wpf/WpfMouseDevice.cs

@ -9,22 +9,32 @@ namespace Avalonia.Win32.Interop.Wpf
{ {
private readonly WpfTopLevelImpl _impl; private readonly WpfTopLevelImpl _impl;
public WpfMouseDevice(WpfTopLevelImpl impl) public WpfMouseDevice(WpfTopLevelImpl impl) : base(new WpfMousePointer(impl))
{ {
_impl = impl; _impl = impl;
} }
public override void Capture(IInputElement control) class WpfMousePointer : Pointer
{ {
if (control == null) private readonly WpfTopLevelImpl _impl;
public WpfMousePointer(WpfTopLevelImpl impl) : base(Pointer.GetNextFreeId(), PointerType.Mouse, true)
{
_impl = impl;
}
protected override void PlatformCapture(IInputElement control)
{ {
System.Windows.Input.Mouse.Capture(null); if (control == null)
{
System.Windows.Input.Mouse.Capture(null);
}
else if ((control.GetVisualRoot() as EmbeddableControlRoot)?.PlatformImpl != _impl)
throw new ArgumentException("Visual belongs to unknown toplevel");
else
System.Windows.Input.Mouse.Capture(_impl);
} }
else if ((control.GetVisualRoot() as EmbeddableControlRoot)?.PlatformImpl != _impl)
throw new ArgumentException("Visual belongs to unknown toplevel");
else
System.Windows.Input.Mouse.Capture(_impl);
base.Capture(control);
} }
} }
} }

26
src/Windows/Avalonia.Win32/Input/WindowsMouseDevice.cs

@ -1,7 +1,10 @@
// Copyright (c) The Avalonia Project. All rights reserved. // 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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.VisualTree;
using Avalonia.Win32.Interop; using Avalonia.Win32.Interop;
namespace Avalonia.Win32.Input namespace Avalonia.Win32.Input
@ -10,23 +13,32 @@ namespace Avalonia.Win32.Input
{ {
public static WindowsMouseDevice Instance { get; } = new WindowsMouseDevice(); public static WindowsMouseDevice Instance { get; } = new WindowsMouseDevice();
public WindowsMouseDevice() : base(new WindowsMousePointer())
{
}
public WindowImpl CurrentWindow public WindowImpl CurrentWindow
{ {
get; get;
set; set;
} }
public override void Capture(IInputElement control) class WindowsMousePointer : Pointer
{ {
base.Capture(control); public WindowsMousePointer() : base(Pointer.GetNextFreeId(),PointerType.Mouse, true)
if (control != null)
{ {
UnmanagedMethods.SetCapture(CurrentWindow.Handle.Handle);
} }
else
protected override void PlatformCapture(IInputElement element)
{ {
UnmanagedMethods.ReleaseCapture(); var hwnd = ((element?.GetVisualRoot() as TopLevel)?.PlatformImpl as WindowImpl)
?.Handle.Handle;
if (hwnd.HasValue && hwnd != IntPtr.Zero)
UnmanagedMethods.SetCapture(hwnd.Value);
else
UnmanagedMethods.ReleaseCapture();
} }
} }
} }

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

@ -336,6 +336,7 @@ namespace Avalonia.Win32
public void BeginMoveDrag() public void BeginMoveDrag()
{ {
WindowsMouseDevice.Instance.Capture(null);
UnmanagedMethods.DefWindowProc(_hwnd, (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN, UnmanagedMethods.DefWindowProc(_hwnd, (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN,
new IntPtr((int)UnmanagedMethods.HitTestValues.HTCAPTION), IntPtr.Zero); new IntPtr((int)UnmanagedMethods.HitTestValues.HTCAPTION), IntPtr.Zero);
} }
@ -357,6 +358,7 @@ namespace Avalonia.Win32
#if USE_MANAGED_DRAG #if USE_MANAGED_DRAG
_managedDrag.BeginResizeDrag(edge, ScreenToClient(MouseDevice.Position)); _managedDrag.BeginResizeDrag(edge, ScreenToClient(MouseDevice.Position));
#else #else
WindowsMouseDevice.Instance.Capture(null);
UnmanagedMethods.DefWindowProc(_hwnd, (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN, UnmanagedMethods.DefWindowProc(_hwnd, (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN,
new IntPtr((int)EdgeDic[edge]), IntPtr.Zero); new IntPtr((int)EdgeDic[edge]), IntPtr.Zero);
#endif #endif

Loading…
Cancel
Save