Browse Source

Merge remote-tracking branch 'origin/master' into android-keyboard

pull/5735/head
ili 6 years ago
parent
commit
51269cc880
  1. 14
      src/Avalonia.Input/Gestures.cs
  2. 4
      src/Avalonia.Input/PointerEventArgs.cs
  3. 4
      src/Avalonia.Input/PointerPoint.cs
  4. 18
      src/Avalonia.Input/TappedEventArgs.cs
  5. 43
      src/Windows/Avalonia.Win32/WindowImpl.cs

14
src/Avalonia.Input/Gestures.cs

@ -24,7 +24,7 @@ namespace Avalonia.Input
public static readonly RoutedEvent<ScrollGestureEventArgs> ScrollGestureEvent = public static readonly RoutedEvent<ScrollGestureEventArgs> ScrollGestureEvent =
RoutedEvent.Register<ScrollGestureEventArgs>( RoutedEvent.Register<ScrollGestureEventArgs>(
"ScrollGesture", RoutingStrategies.Bubble, typeof(Gestures)); "ScrollGesture", RoutingStrategies.Bubble, typeof(Gestures));
public static readonly RoutedEvent<ScrollGestureEventArgs> ScrollGestureEndedEvent = public static readonly RoutedEvent<ScrollGestureEventArgs> ScrollGestureEndedEvent =
RoutedEvent.Register<ScrollGestureEventArgs>( RoutedEvent.Register<ScrollGestureEventArgs>(
"ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); "ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures));
@ -89,7 +89,7 @@ namespace Avalonia.Input
{ {
if (s_lastPress.TryGetTarget(out var target) && target == e.Source) if (s_lastPress.TryGetTarget(out var target) && target == e.Source)
{ {
e.Source.RaiseEvent(new RoutedEventArgs(DoubleTappedEvent)); e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e));
} }
} }
} }
@ -105,8 +105,14 @@ namespace Avalonia.Input
{ {
if (e.InitialPressMouseButton == MouseButton.Left || e.InitialPressMouseButton == MouseButton.Right) if (e.InitialPressMouseButton == MouseButton.Left || e.InitialPressMouseButton == MouseButton.Right)
{ {
var et = e.InitialPressMouseButton != MouseButton.Right ? TappedEvent : RightTappedEvent; if (e.InitialPressMouseButton == MouseButton.Right)
e.Source.RaiseEvent(new RoutedEventArgs(et)); {
e.Source.RaiseEvent(new TappedEventArgs(RightTappedEvent, e));
}
else
{
e.Source.RaiseEvent(new TappedEventArgs(TappedEvent, e));
}
} }
} }
} }

4
src/Avalonia.Input/PointerEventArgs.cs

@ -107,7 +107,9 @@ namespace Avalonia.Input
None, None,
Left, Left,
Right, Right,
Middle Middle,
XButton1,
XButton2
} }
public class PointerPressedEventArgs : PointerEventArgs public class PointerPressedEventArgs : PointerEventArgs

4
src/Avalonia.Input/PointerPoint.cs

@ -90,6 +90,10 @@ namespace Avalonia.Input
return MouseButton.Middle; return MouseButton.Middle;
if (kind == PointerUpdateKind.RightButtonPressed || kind == PointerUpdateKind.RightButtonReleased) if (kind == PointerUpdateKind.RightButtonPressed || kind == PointerUpdateKind.RightButtonReleased)
return MouseButton.Right; return MouseButton.Right;
if (kind == PointerUpdateKind.XButton1Pressed || kind == PointerUpdateKind.XButton1Released)
return MouseButton.XButton1;
if (kind == PointerUpdateKind.XButton2Pressed || kind == PointerUpdateKind.XButton2Released)
return MouseButton.XButton2;
return MouseButton.None; return MouseButton.None;
} }
} }

18
src/Avalonia.Input/TappedEventArgs.cs

@ -0,0 +1,18 @@
using Avalonia.Interactivity;
using Avalonia.VisualTree;
namespace Avalonia.Input
{
public class TappedEventArgs : RoutedEventArgs
{
private readonly PointerEventArgs lastPointerEventArgs;
public TappedEventArgs(RoutedEvent routedEvent, PointerEventArgs lastPointerEventArgs)
: base(routedEvent)
{
this.lastPointerEventArgs = lastPointerEventArgs;
}
public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo);
}
}

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

@ -85,6 +85,7 @@ namespace Avalonia.Win32
private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default;
private bool _isCloseRequested; private bool _isCloseRequested;
private bool _shown; private bool _shown;
private bool _hiddenWindowIsParent;
public WindowImpl() public WindowImpl()
{ {
@ -571,8 +572,7 @@ namespace Avalonia.Win32
public virtual void Show(bool activate) public virtual void Show(bool activate)
{ {
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent != null ? _parent._hwnd : IntPtr.Zero); SetParent(_parent);
ShowWindow(_showWindowState, activate); ShowWindow(_showWindowState, activate);
} }
@ -580,8 +580,15 @@ namespace Avalonia.Win32
public void SetParent(IWindowImpl parent) public void SetParent(IWindowImpl parent)
{ {
_parent = (WindowImpl)parent; var parentHwnd = ((WindowImpl)parent)?._hwnd ?? IntPtr.Zero;
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent._hwnd);
if (parentHwnd == IntPtr.Zero && !_windowProperties.ShowInTaskbar)
{
parentHwnd = OffscreenParentWindow.Handle;
_hiddenWindowIsParent = true;
}
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, parentHwnd);
} }
public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable); public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable);
@ -1095,16 +1102,38 @@ namespace Avalonia.Win32
if (newProperties.ShowInTaskbar) if (newProperties.ShowInTaskbar)
{ {
exStyle |= WindowStyles.WS_EX_APPWINDOW; exStyle |= WindowStyles.WS_EX_APPWINDOW;
if (_hiddenWindowIsParent)
{
// Can't enable the taskbar icon by clearing the parent window unless the window
// is hidden. Hide the window and show it again with the same activation state
// when we've finished. Interestingly it seems to work fine the other way.
var shown = IsWindowVisible(_hwnd);
var activated = GetActiveWindow() == _hwnd;
if (shown)
Hide();
_hiddenWindowIsParent = false;
SetParent(null);
if (shown)
Show(activated);
}
} }
else else
{ {
// To hide a non-owned window's taskbar icon we need to parent it to a hidden window.
if (_parent is null)
{
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, OffscreenParentWindow.Handle);
_hiddenWindowIsParent = true;
}
exStyle &= ~WindowStyles.WS_EX_APPWINDOW; exStyle &= ~WindowStyles.WS_EX_APPWINDOW;
} }
SetExtendedStyle(exStyle); SetExtendedStyle(exStyle);
// TODO: To hide non-owned window from taskbar we need to parent it to a hidden window.
// Otherwise it will still show in the taskbar.
} }
WindowStyles style; WindowStyles style;

Loading…
Cancel
Save