Skip to content

Commit

Permalink
Tweak the drop description icon names.
Browse files Browse the repository at this point in the history
  • Loading branch information
willibrandon committed Feb 19, 2022
1 parent 33827ef commit 1ce2618
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 61 deletions.
4 changes: 2 additions & 2 deletions src/System.Windows.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ System.Windows.Forms.DragEventArgs.Message.get -> string!
System.Windows.Forms.DragEventArgs.Message.set -> void
System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Copy = 1 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Invalid = -1 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Default = -1 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Label = 6 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Link = 4 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Move = 2 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.NoImage = 8 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.NoDropIcon = 8 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.None = 0 -> System.Windows.Forms.DropIconType
System.Windows.Forms.DropIconType.Warning = 7 -> System.Windows.Forms.DropIconType
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static bool GetDropDescriptionPresent(IComDataObject dataObject)
/// </summary>
public static unsafe bool GetDropDescription(IComDataObject dataObject, out DropIconType dropIcon, out string message, out string insert)
{
dropIcon = DropIconType.Invalid;
dropIcon = DropIconType.Default;
message = string.Empty;
insert = string.Empty;

Expand Down Expand Up @@ -303,7 +303,7 @@ public static unsafe bool GetDropDescription(IComDataObject dataObject, out Drop
public static unsafe void SetDropDescription(IComDataObject dataObject, DropIconType dropIcon, string message, string insert)
{
if (dataObject is null
|| (dropIcon is < DropIconType.Invalid or > DropIconType.NoImage)
|| (dropIcon is < DropIconType.Default or > DropIconType.NoDropIcon)
|| (message is not null && message.Length >= Kernel32.MAX_PATH)
|| (insert is not null && insert.Length >= Kernel32.MAX_PATH))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DragEventArgs(
Y = y;
AllowedEffect = allowedEffect;
Effect = effect;
DropIcon = DropIconType.Invalid;
DropIcon = DropIconType.Default;
Message = string.Empty;
Insert = string.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum DropIconType
/// <summary>
/// No drop icon preference; use the default icon.
/// </summary>
Invalid = -1,
Default = -1,

/// <summary>
/// A red bisected circle such as that found on a "no smoking" sign.
Expand Down Expand Up @@ -45,8 +45,8 @@ public enum DropIconType
Warning = 7,

/// <summary>
/// Windows 7 and later. Use no drop image.
/// Windows 7 and later. Use no drop icon.
/// </summary>
NoImage = 8
NoDropIcon = 8
}
}
25 changes: 9 additions & 16 deletions src/System.Windows.Forms/src/System/Windows/Forms/DropTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class DropTarget : Ole32.IDropTarget
{
private IDataObject? _lastDataObject;
private DragDropEffects _lastEffect = DragDropEffects.None;
private DropIconType _lastDropIcon = DropIconType.Invalid;
private DropIconType _lastDropIcon = DropIconType.Default;
private readonly IDropTarget _owner;

public DropTarget(IDropTarget owner)
Expand Down Expand Up @@ -73,17 +73,11 @@ HRESULT Ole32.IDropTarget.DragEnter(object pDataObj, uint grfKeyState, Point pt,
_lastEffect = drgevent.Effect;
_lastDropIcon = drgevent.DropIcon;

if (drgevent.DropIcon is > DropIconType.Invalid
&& _owner is Control control
&& drgevent.Data is not null
&& drgevent.Data is IComDataObject comDataObject)
if (drgevent.DropIcon is > DropIconType.Default
&& drgevent.Data is IComDataObject comDataObject
&& _owner is Control control)
{
DragDropHelper.SetDropDescription(
comDataObject,
drgevent.DropIcon,
drgevent.Message,
drgevent.Insert);

DragDropHelper.SetDropDescription(comDataObject, drgevent.DropIcon, drgevent.Message, drgevent.Insert);
DragDropHelper.DragEnter(control.Handle, comDataObject, ref pt, pdwEffect);
}
}
Expand All @@ -106,7 +100,7 @@ HRESULT Ole32.IDropTarget.DragOver(uint grfKeyState, Point pt, ref uint pdwEffec
pdwEffect = (uint)drgevent.Effect;
_lastEffect = drgevent.Effect;

if (_lastDropIcon is > DropIconType.Invalid)
if (_lastDropIcon is > DropIconType.Default)
{
DragDropHelper.DragOver(ref pt, pdwEffect);
}
Expand All @@ -124,7 +118,7 @@ HRESULT Ole32.IDropTarget.DragLeave()
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragLeave received");
_owner.OnDragLeave(EventArgs.Empty);

if (_lastDropIcon is > DropIconType.Invalid)
if (_lastDropIcon is > DropIconType.Default)
{
DragDropHelper.DragLeave();
}
Expand All @@ -143,8 +137,7 @@ HRESULT Ole32.IDropTarget.Drop(object pDataObj, uint grfKeyState, Point pt, ref
_owner.OnDragDrop(drgevent);
pdwEffect = (uint)drgevent.Effect;

if (_lastDropIcon is > DropIconType.Invalid
&& drgevent.Data is not null
if (_lastDropIcon is > DropIconType.Default
&& drgevent.Data is IComDataObject comDataObject)
{
DragDropHelper.Drop(comDataObject, ref pt, pdwEffect);
Expand All @@ -155,7 +148,7 @@ HRESULT Ole32.IDropTarget.Drop(object pDataObj, uint grfKeyState, Point pt, ref
pdwEffect = (uint)DragDropEffects.None;
}

_lastDropIcon = DropIconType.Invalid;
_lastDropIcon = DropIconType.Default;
_lastEffect = DragDropEffects.None;
_lastDataObject = null;
return HRESULT.S_OK;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public DragDrop()
pictureBox5
};

AllowDrop = true;
DragEnter += DragDrop_DragEnter;

pictureBox1.AllowDrop = true;
Expand All @@ -52,22 +51,27 @@ public DragDrop()
pictureBox5.DragDrop += PictureBox_DragDrop;

buttonOpenCats.Click += new EventHandler(ButtonOpenCats_Click);
buttonClearCats.Click += new EventHandler(ButtonClearCats_Click);
buttonClear.Click += new EventHandler(ButtonClear_Click);
}

private void ButtonClearCats_Click(object? sender, EventArgs e)
=> ClearCats();
private void ButtonClear_Click(object? sender, EventArgs e)
{
ClearCats();
richTextBox1.Clear();
textBox1.Clear();
}

private void ButtonOpenCats_Click(object? sender, EventArgs e)
=> OpenCats();

private void DragDrop_DragEnter(object? sender, DragEventArgs e)
=> e.Effect = e.AllowedEffect;

private void PictureBox_DragEnter(object? sender, DragEventArgs e)
{
e.DropIcon = DropIconType.None;
e.Effect = DragDropEffects.None;
}

private void PictureBox_DragEnter(object? sender, DragEventArgs e)
{
if (sender is PictureBox pb
&& e.Data is not null
&& e.Data.GetDataPresent(DataFormats.FileDrop)
Expand All @@ -76,33 +80,33 @@ private void PictureBox_DragEnter(object? sender, DragEventArgs e)
{
if (files.All(file => file.Contains("NyanCat") && file.EndsWith(".bmp")))
{
// Set the drop icon to a plus sign (+).
// Set the target drop icon to a plus sign (+).
e.DropIcon = DropIconType.Copy;

// Set the drop description text.
// Set the target drop text.
e.Message = $"{e.DropIcon} %1 from Explorer";
e.Insert = $"{(files.Length > 1 ? "cats" : "Cat")}";
e.Insert = $"{(files.Length > 1 ? "Cats" : "Cat")}";

// Set the target drop effect.
e.Effect = DragDropEffects.Copy;
}
else if (files.Length == 1 && files.Any(file => file.Contains("DragAccept") && file.EndsWith(".rtf")))
{
// Set the drop icon to a red bisected circle.
// Set the target drop icon to a red bisected circle.
e.DropIcon = DropIconType.None;

// Set the drop description text.
// Set the target drop text.
e.Message = $"{Path.GetFileNameWithoutExtension(files[0])}%1";
e.Insert = Path.GetExtension(files[0]);

// Set the target drop effect.
e.Effect = DragDropEffects.None;
}
}
}

private void PictureBox_DragDrop(object? sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;

if (sender is PictureBox pb
&& e.Data is not null
&& e.Data.GetDataPresent(DataFormats.FileDrop)
Expand All @@ -111,7 +115,6 @@ private void PictureBox_DragDrop(object? sender, DragEventArgs e)
&& files.All(file => file.Contains("NyanCat") && file.EndsWith(".bmp")))
{
LoadCats(pb, files);
e.Effect = DragDropEffects.Copy;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
<NoWarn>$(NoWarn),WFDEV001</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Remove="Data\DragDrop\DragAccept.rtf" />
<None Remove="Data\DragDrop\nyancat1.bmp" />
<None Remove="Data\DragDrop\nyancat2.bmp" />
<None Remove="Data\DragDrop\nyancat3.bmp" />
<None Remove="Data\DragDrop\nyancat4.bmp" />
<None Remove="Data\DragDrop\nyancat5.bmp" />
<None Remove="Data\DragDrop\nyancatascii_width_301.bmp" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\System.Design\src\System.Design.Facade.csproj" />
<ProjectReference Include="..\..\..\..\System.Windows.Forms.Design\src\System.Windows.Forms.Design.csproj" />
Expand Down

0 comments on commit 1ce2618

Please sign in to comment.