Browse Source

Merge branch 'master' into jmacato/missing-skia-api-lottie

pull/5683/head
Jumar Macato 6 years ago
committed by GitHub
parent
commit
bc8ee71635
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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. 62
      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);
}
}

62
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()
{ {
@ -483,8 +484,8 @@ namespace Avalonia.Win32
IntPtr.Zero, IntPtr.Zero,
0, 0,
0, 0,
requestedClientWidth + (windowRect.Width - clientRect.Width), requestedClientWidth + (_isClientAreaExtended ? 0 : windowRect.Width - clientRect.Width),
requestedClientHeight + (windowRect.Height - clientRect.Height), requestedClientHeight + (_isClientAreaExtended ? 0 : windowRect.Height - clientRect.Height),
SetWindowPosFlags.SWP_RESIZE); SetWindowPosFlags.SWP_RESIZE);
} }
} }
@ -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);
@ -883,20 +890,19 @@ namespace Avalonia.Win32
_isClientAreaExtended = false; _isClientAreaExtended = false;
return; return;
} }
GetClientRect(_hwnd, out var rcClient);
GetWindowRect(_hwnd, out var rcClient); GetWindowRect(_hwnd, out var rcWindow);
// Inform the application of the frame change. // Inform the application of the frame change.
SetWindowPos(_hwnd, SetWindowPos(_hwnd,
IntPtr.Zero, IntPtr.Zero,
rcClient.left, rcClient.top, rcWindow.left, rcWindow.top,
rcClient.Width, rcClient.Height, rcClient.Width, rcClient.Height,
SetWindowPosFlags.SWP_FRAMECHANGED); SetWindowPosFlags.SWP_FRAMECHANGED);
if (_isClientAreaExtended && WindowState != WindowState.FullScreen) if (_isClientAreaExtended && WindowState != WindowState.FullScreen)
{ {
var margins = UpdateExtendMargins(); var margins = UpdateExtendMargins();
DwmExtendFrameIntoClientArea(_hwnd, ref margins); DwmExtendFrameIntoClientArea(_hwnd, ref margins);
} }
else else
@ -906,6 +912,8 @@ namespace Avalonia.Win32
_offScreenMargin = new Thickness(); _offScreenMargin = new Thickness();
_extendedMargins = new Thickness(); _extendedMargins = new Thickness();
Resize(new Size(rcWindow.Width/ RenderScaling, rcWindow.Height / RenderScaling));
} }
if(!_isClientAreaExtended || (_extendChromeHints.HasFlagCustom(ExtendClientAreaChromeHints.SystemChrome) && if(!_isClientAreaExtended || (_extendChromeHints.HasFlagCustom(ExtendClientAreaChromeHints.SystemChrome) &&
@ -1094,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