Skip to content

Commit d69e815

Browse files
authored
Merge pull request AvaloniaUI#3403 from jp2masa/update-obsolete-api-usages
Fixed drag and drop obsolete API usage
2 parents 8a3f592 + 3dca330 commit d69e815

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/Avalonia.Input/DragDropDevice.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private Interactive GetTarget(IInputRoot root, Point local)
1919
return null;
2020
}
2121

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

41-
private DragDropEffects DragEnter(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
41+
private DragDropEffects DragEnter(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, KeyModifiers modifiers)
4242
{
4343
_lastTarget = GetTarget(inputRoot, point);
4444
return RaiseDragEvent(_lastTarget, inputRoot, point, DragDrop.DragEnterEvent, effects, data, modifiers);
4545
}
4646

47-
private DragDropEffects DragOver(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
47+
private DragDropEffects DragOver(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, KeyModifiers modifiers)
4848
{
4949
var target = GetTarget(inputRoot, point);
5050

@@ -77,7 +77,7 @@ private void DragLeave(IInputElement inputRoot)
7777
}
7878
}
7979

80-
private DragDropEffects Drop(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
80+
private DragDropEffects Drop(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, KeyModifiers modifiers)
8181
{
8282
try
8383
{
@@ -100,16 +100,16 @@ private void ProcessRawEvent(RawDragEvent e)
100100
switch (e.Type)
101101
{
102102
case RawDragEventType.DragEnter:
103-
e.Effects = DragEnter(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
103+
e.Effects = DragEnter(e.Root, e.Location, e.Data, e.Effects, e.KeyModifiers);
104104
break;
105105
case RawDragEventType.DragOver:
106-
e.Effects = DragOver(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
106+
e.Effects = DragOver(e.Root, e.Location, e.Data, e.Effects, e.KeyModifiers);
107107
break;
108108
case RawDragEventType.DragLeave:
109109
DragLeave(e.Root);
110110
break;
111111
case RawDragEventType.Drop:
112-
e.Effects = Drop(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
112+
e.Effects = Drop(e.Root, e.Location, e.Data, e.Effects, e.KeyModifiers);
113113
break;
114114
}
115115
}

src/Avalonia.Input/DragEventArgs.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public class DragEventArgs : RoutedEventArgs
1313

1414
public IDataObject Data { get; private set; }
1515

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

19+
public KeyModifiers KeyModifiers { get; private set; }
20+
1821
public Point GetPosition(IVisual relativeTo)
1922
{
2023
var point = new Point(0, 0);
@@ -32,13 +35,25 @@ public Point GetPosition(IVisual relativeTo)
3235
return point;
3336
}
3437

38+
[Obsolete("Use constructor taking KeyModifiers")]
3539
public DragEventArgs(RoutedEvent<DragEventArgs> routedEvent, IDataObject data, Interactive target, Point targetLocation, InputModifiers modifiers)
3640
: base(routedEvent)
3741
{
38-
this.Data = data;
39-
this._target = target;
40-
this._targetLocation = targetLocation;
41-
this.Modifiers = modifiers;
42+
Data = data;
43+
_target = target;
44+
_targetLocation = targetLocation;
45+
Modifiers = modifiers;
46+
KeyModifiers = (KeyModifiers)(((int)modifiers) & 0xF);
47+
}
48+
49+
public DragEventArgs(RoutedEvent<DragEventArgs> routedEvent, IDataObject data, Interactive target, Point targetLocation, KeyModifiers keyModifiers)
50+
: base(routedEvent)
51+
{
52+
Data = data;
53+
_target = target;
54+
_targetLocation = targetLocation;
55+
Modifiers = (InputModifiers)keyModifiers;
56+
KeyModifiers = keyModifiers;
4257
}
4358

4459
}

src/Avalonia.Input/Raw/RawDragEvent.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
namespace Avalonia.Input.Raw
1+
using System;
2+
3+
namespace Avalonia.Input.Raw
24
{
35
public class RawDragEvent : RawInputEventArgs
46
{
57
public Point Location { get; set; }
68
public IDataObject Data { get; }
79
public DragDropEffects Effects { get; set; }
810
public RawDragEventType Type { get; }
11+
[Obsolete("Use KeyModifiers")]
912
public InputModifiers Modifiers { get; }
13+
public KeyModifiers KeyModifiers { get; }
1014

1115
public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type,
1216
IInputRoot root, Point location, IDataObject data, DragDropEffects effects, RawInputModifiers modifiers)
@@ -17,6 +21,7 @@ public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type,
1721
Data = data;
1822
Effects = effects;
1923
Modifiers = (InputModifiers)modifiers;
24+
KeyModifiers = KeyModifiersUtils.ConvertToKey(modifiers);
2025
}
2126
}
2227
}

0 commit comments

Comments
 (0)