- XWT expects immediate return from drag and drop, so we'll move the
   synchronous WPF call to the dispatcher
 - Need to raise the OnDragFinished event
 - Move DataObject stuff to DataConverter for possible reuse in clipboard
This commit is contained in:
ermau 2012-04-05 13:50:24 -04:00
Родитель 53bd1da23d
Коммит da8ee83ab7
2 изменённых файлов: 32 добавлений и 20 удалений

Просмотреть файл

@ -29,6 +29,7 @@
// THE SOFTWARE.
using System;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
@ -429,5 +430,24 @@ namespace Xwt.WPFBackend
throw new NotSupportedException ();
}
}
public static DataObject ToDataObject (this TransferDataSource data)
{
var retval = new DataObject ();
foreach (var type in data.DataTypes) {
var value = data.GetValue (type);
if (type == TransferDataType.Text)
retval.SetText ((string)value);
else if (type == TransferDataType.Uri) {
var uris = new StringCollection ();
uris.Add (((Uri)value).LocalPath);
retval.SetFileDropList (uris);
} else
retval.SetData (type.Id, TransferDataSource.SerializeValue (value));
}
return retval;
}
}
}

Просмотреть файл

@ -653,27 +653,12 @@ namespace Xwt.WPFBackend
if (data.Data == null)
throw new ArgumentNullException ("data");
var dataObj = CreateDataObject (data.Data);
DragDrop.DoDragDrop (Widget, dataObj, data.DragAction.ToWpfDropEffect ());
}
DataObject dataObj = data.Data.ToDataObject();
static DataObject CreateDataObject (TransferDataSource data)
{
var retval = new DataObject ();
foreach (var type in data.DataTypes) {
var value = data.GetValue (type);
if (type == TransferDataType.Text)
retval.SetText ((string)value);
else if (type == TransferDataType.Uri) {
var uris = new StringCollection ();
uris.Add (((Uri)value).LocalPath);
retval.SetFileDropList (uris);
} else
retval.SetData (type.Id, TransferDataSource.SerializeValue (value));
}
return retval;
Widget.Dispatcher.BeginInvoke (
(Func<DependencyObject, object, DragDropEffects, DragDropEffects>)DragDrop.DoDragDrop,
Widget, dataObj, data.DragAction.ToWpfDropEffect ()
);
}
public void SetDragTarget (TransferDataType [] types, DragDropAction dragAction)
@ -816,12 +801,16 @@ namespace Xwt.WPFBackend
bool res = Toolkit.Invoke (delegate {
eventSink.OnDragDropCheck (checkArgs);
});
if (checkArgs.Result == DragDropResult.Canceled || !res) {
e.Effects = DragDropEffects.None;
eventSink.OnDragFinished (new DragFinishedEventArgs (false));
return;
}
}
bool deleteSource = false;
if ((enabledEvents & WidgetEvent.DragDrop) > 0) {
var store = new TransferDataStore ();
FillDataStore (store, e.Data, DragDropInfo.TargetTypes);
@ -831,11 +820,14 @@ namespace Xwt.WPFBackend
eventSink.OnDragDrop (args);
});
deleteSource = args.Success;
e.Effects = args.Success ? actualEffect : DragDropEffects.None;
}
// No DrapDropCheck/DragDrop event enabled.
e.Effects = DragDropEffects.None;
this.eventSink.OnDragFinished (new DragFinishedEventArgs (deleteSource));
}
void WidgetDragLeaveHandler (object sender, System.Windows.DragEventArgs e)