Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#3403 from jp2masa/update-obsolete-api-u…
Browse files Browse the repository at this point in the history
…sages

Fixed drag and drop obsolete API usage
  • Loading branch information
MarchingCube authored Jan 21, 2020
2 parents 8a3f592 + 3dca330 commit d69e815
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/Avalonia.Input/DragDropDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private Interactive GetTarget(IInputRoot root, Point local)
return null;
}

private DragDropEffects RaiseDragEvent(Interactive target, IInputRoot inputRoot, Point point, RoutedEvent<DragEventArgs> routedEvent, DragDropEffects operation, IDataObject data, InputModifiers modifiers)
private DragDropEffects RaiseDragEvent(Interactive target, IInputRoot inputRoot, Point point, RoutedEvent<DragEventArgs> routedEvent, DragDropEffects operation, IDataObject data, KeyModifiers modifiers)
{
if (target == null)
return DragDropEffects.None;
Expand All @@ -38,13 +38,13 @@ private DragDropEffects RaiseDragEvent(Interactive target, IInputRoot inputRoot,
return args.DragEffects;
}

private DragDropEffects DragEnter(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
private DragDropEffects DragEnter(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, KeyModifiers modifiers)
{
_lastTarget = GetTarget(inputRoot, point);
return RaiseDragEvent(_lastTarget, inputRoot, point, DragDrop.DragEnterEvent, effects, data, modifiers);
}

private DragDropEffects DragOver(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
private DragDropEffects DragOver(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, KeyModifiers modifiers)
{
var target = GetTarget(inputRoot, point);

Expand Down Expand Up @@ -77,7 +77,7 @@ private void DragLeave(IInputElement inputRoot)
}
}

private DragDropEffects Drop(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
private DragDropEffects Drop(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, KeyModifiers modifiers)
{
try
{
Expand All @@ -100,16 +100,16 @@ private void ProcessRawEvent(RawDragEvent e)
switch (e.Type)
{
case RawDragEventType.DragEnter:
e.Effects = DragEnter(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
e.Effects = DragEnter(e.Root, e.Location, e.Data, e.Effects, e.KeyModifiers);
break;
case RawDragEventType.DragOver:
e.Effects = DragOver(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
e.Effects = DragOver(e.Root, e.Location, e.Data, e.Effects, e.KeyModifiers);
break;
case RawDragEventType.DragLeave:
DragLeave(e.Root);
break;
case RawDragEventType.Drop:
e.Effects = Drop(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
e.Effects = Drop(e.Root, e.Location, e.Data, e.Effects, e.KeyModifiers);
break;
}
}
Expand Down
23 changes: 19 additions & 4 deletions src/Avalonia.Input/DragEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public class DragEventArgs : RoutedEventArgs

public IDataObject Data { get; private set; }

[Obsolete("Use KeyModifiers")]
public InputModifiers Modifiers { get; private set; }

public KeyModifiers KeyModifiers { get; private set; }

public Point GetPosition(IVisual relativeTo)
{
var point = new Point(0, 0);
Expand All @@ -32,13 +35,25 @@ public Point GetPosition(IVisual relativeTo)
return point;
}

[Obsolete("Use constructor taking KeyModifiers")]
public DragEventArgs(RoutedEvent<DragEventArgs> routedEvent, IDataObject data, Interactive target, Point targetLocation, InputModifiers modifiers)
: base(routedEvent)
{
this.Data = data;
this._target = target;
this._targetLocation = targetLocation;
this.Modifiers = modifiers;
Data = data;
_target = target;
_targetLocation = targetLocation;
Modifiers = modifiers;
KeyModifiers = (KeyModifiers)(((int)modifiers) & 0xF);
}

public DragEventArgs(RoutedEvent<DragEventArgs> routedEvent, IDataObject data, Interactive target, Point targetLocation, KeyModifiers keyModifiers)
: base(routedEvent)
{
Data = data;
_target = target;
_targetLocation = targetLocation;
Modifiers = (InputModifiers)keyModifiers;
KeyModifiers = keyModifiers;
}

}
Expand Down
7 changes: 6 additions & 1 deletion src/Avalonia.Input/Raw/RawDragEvent.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace Avalonia.Input.Raw
using System;

namespace Avalonia.Input.Raw
{
public class RawDragEvent : RawInputEventArgs
{
public Point Location { get; set; }
public IDataObject Data { get; }
public DragDropEffects Effects { get; set; }
public RawDragEventType Type { get; }
[Obsolete("Use KeyModifiers")]
public InputModifiers Modifiers { get; }
public KeyModifiers KeyModifiers { get; }

public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type,
IInputRoot root, Point location, IDataObject data, DragDropEffects effects, RawInputModifiers modifiers)
Expand All @@ -17,6 +21,7 @@ public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type,
Data = data;
Effects = effects;
Modifiers = (InputModifiers)modifiers;
KeyModifiers = KeyModifiersUtils.ConvertToKey(modifiers);
}
}
}

0 comments on commit d69e815

Please sign in to comment.