internal bool DoDragDrop(Gdk.DragContext context, int x, int y, uint time) { DragDropInfo.LastDragPosition = new Point(x, y); var cda = ConvertDragAction(context.GetSelectedAction()); DragDropResult res; if ((enabledEvents & WidgetEvent.DragDropCheck) == 0) { if ((enabledEvents & WidgetEvent.DragDrop) != 0) { res = DragDropResult.None; } else { res = DragDropResult.Canceled; } } else { DragCheckEventArgs da = new DragCheckEventArgs(new Point(x, y), Util.GetDragTypes(context.ListTargets()), cda); ApplicationContext.InvokeUserCode(delegate { EventSink.OnDragDropCheck(da); }); res = da.Result; if ((enabledEvents & WidgetEvent.DragDrop) == 0 && res == DragDropResult.None) { res = DragDropResult.Canceled; } } if (res == DragDropResult.Canceled) { Gtk.Drag.Finish(context, false, false, time); return(true); } else if (res == DragDropResult.Success) { Gtk.Drag.Finish(context, true, cda == DragDropAction.Move, time); return(true); } else { // Undefined, we need more data QueryDragData(context, time, false); return(true); } }
internal bool DoDragDataReceived(Gdk.DragContext context, int x, int y, Gtk.SelectionData selectionData, uint info, uint time) { if (DragDropInfo.DragDataRequests == 0) { // Got the data without requesting it. Create the datastore here DragDropInfo.DragData = new TransferDataStore(); DragDropInfo.LastDragPosition = new Point(x, y); DragDropInfo.DragDataRequests = 1; } DragDropInfo.DragDataRequests--; // If multiple drag/drop data types are supported, we need to iterate through them all and // append the data. If one of the supported data types is not found, there's no need to // bail out. We must raise the event Util.GetSelectionData(ApplicationContext, selectionData, DragDropInfo.DragData); if (DragDropInfo.DragDataRequests == 0) { if (DragDropInfo.DragDataForMotion) { // If no specific action is set, it means that no key has been pressed. // In that case, use Move or Copy or Link as default (when allowed, in this order). var cact = ConvertDragAction(context.Actions); if (cact != DragDropAction.Copy && cact != DragDropAction.Move && cact != DragDropAction.Link) { if (cact.HasFlag(DragDropAction.Move)) { cact = DragDropAction.Move; } else if (cact.HasFlag(DragDropAction.Copy)) { cact = DragDropAction.Copy; } else if (cact.HasFlag(DragDropAction.Link)) { cact = DragDropAction.Link; } else { cact = DragDropAction.None; } } DragOverEventArgs da = new DragOverEventArgs(DragDropInfo.LastDragPosition, DragDropInfo.DragData, cact); ApplicationContext.InvokeUserCode(delegate { EventSink.OnDragOver(da); }); OnSetDragStatus(context, (int)DragDropInfo.LastDragPosition.X, (int)DragDropInfo.LastDragPosition.Y, time, ConvertDragAction(da.AllowedAction)); return(true); } else { // Use Context.Action here since that's the action selected in DragOver var cda = ConvertDragAction(context.GetSelectedAction()); DragEventArgs da = new DragEventArgs(DragDropInfo.LastDragPosition, DragDropInfo.DragData, cda); ApplicationContext.InvokeUserCode(delegate { EventSink.OnDragDrop(da); }); Gtk.Drag.Finish(context, da.Success, cda == DragDropAction.Move, time); return(true); } } else { return(false); } }