Skip to content

Commit 97378a2

Browse files
committed
chore: Adjustments for logic
1 parent b5e891f commit 97378a2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Uno.UI.Runtime.Skia.Win32/ApplicationMode/DataTransfer/DragDrop/Win32DragDropExtension.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ unsafe HRESULT IDropTarget.Interface.Drop(IDataObject* dataObject, MODIFIERKEYS_
209209

210210
private static unsafe DragUI? CreateDragUIForExternalDrag(IDataObject* dataObject, FORMATETC[] formatEtcList)
211211
{
212-
var dragUI = new DragUI(PointerDeviceType.Mouse);
212+
var dragUI = new DragUI();
213213

214214
// Check if we have a DIB (Device Independent Bitmap) format
215-
var dibFormat = formatEtcList.FirstOrDefault(f => f.cfFormat == (int)CLIPBOARD_FORMAT.CF_DIB);
216-
if (dibFormat.cfFormat != 0)
215+
var dibFormatIndex = Array.FindIndex(formatEtcList, f => f.cfFormat == (int)CLIPBOARD_FORMAT.CF_DIB);
216+
if (dibFormatIndex >= 0)
217217
{
218+
var dibFormat = formatEtcList[dibFormatIndex];
218219
// Try to get the DIB data directly
219220
var hResult = dataObject->GetData(dibFormat, out STGMEDIUM dibMedium);
220221
if (hResult.Succeeded && dibMedium.u.hGlobal != IntPtr.Zero)
@@ -228,6 +229,15 @@ unsafe HRESULT IDropTarget.Interface.Drop(IDataObject* dataObject, MODIFIERKEYS_
228229
return dragUI;
229230
}
230231
}
232+
catch (Exception ex)
233+
{
234+
// If we can't load the image, continue without visual feedback
235+
var logger = typeof(Win32DragDropExtension).Log();
236+
if (logger.IsEnabled(LogLevel.Debug))
237+
{
238+
logger.LogDebug($"Failed to load image thumbnail for drag operation: {ex.Message}");
239+
}
240+
}
231241
finally
232242
{
233243
PInvoke.ReleaseStgMedium(&dibMedium);
@@ -236,9 +246,10 @@ unsafe HRESULT IDropTarget.Interface.Drop(IDataObject* dataObject, MODIFIERKEYS_
236246
}
237247

238248
// Check if we have file drop format
239-
var hdropFormat = formatEtcList.FirstOrDefault(f => f.cfFormat == (int)CLIPBOARD_FORMAT.CF_HDROP);
240-
if (hdropFormat.cfFormat != 0)
249+
var hdropFormatIndex = Array.FindIndex(formatEtcList, f => f.cfFormat == (int)CLIPBOARD_FORMAT.CF_HDROP);
250+
if (hdropFormatIndex >= 0)
241251
{
252+
var hdropFormat = formatEtcList[hdropFormatIndex];
242253
// Try to get the HDROP data directly
243254
var hResult = dataObject->GetData(hdropFormat, out STGMEDIUM hdropMedium);
244255
if (hResult.Succeeded && hdropMedium.u.hGlobal != IntPtr.Zero)

src/Uno.UI/UI/Xaml/DragDrop/DragUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal DragUI(PointerDeviceType pointerDeviceType)
1818
PointerDeviceType = pointerDeviceType;
1919
}
2020

21-
internal PointerDeviceType PointerDeviceType { get; }
21+
internal PointerDeviceType? PointerDeviceType { get; }
2222

2323
internal ImageSource? Content { get; set; }
2424

0 commit comments

Comments
 (0)