Beispiel #1
0
 void HandleB2DragDrop(object sender, DragEventArgs e)
 {
     Console.WriteLine ("Dropped! " + e.Action);
     Console.WriteLine ("Text: " + e.Data.GetValue (TransferDataType.Text));
     Console.WriteLine ("Uris:");
     foreach (var u in e.Data.Uris)
         Console.WriteLine ("u:" + u);
     e.Success = true;
     b2.Label = "Dropped!";
 }
Beispiel #2
0
        void HandleWidgetDragDataReceived(object o, Gtk.DragDataReceivedArgs args)
        {
            dragDataRequests--;

            if (!Util.GetSelectionData (args.SelectionData, dragData)) {
                args.RetVal = false;
                return;
            }

            if (dragDataRequests == 0) {
                if (dragDataForMotion) {
                    DragOverEventArgs da = new DragOverEventArgs (lastDragPosition, dragData, ConvertDragAction (args.Context.Actions));
                    Toolkit.Invoke (delegate {
                        EventSink.OnDragOver (da);
                    });
                    Gdk.Drag.Status (args.Context, ConvertDragAction (da.AllowedAction), args.Time);
                }
                else {
                    // Use Context.Action here since that's the action selected in DragOver
                    var cda = ConvertDragAction (args.Context.Action);
                    DragEventArgs da = new DragEventArgs (lastDragPosition, dragData, cda);
                    Toolkit.Invoke (delegate {
                        EventSink.OnDragDrop (da);
                    });
                    Gtk.Drag.Finish (args.Context, da.Success, cda == DragDropAction.Move, args.Time);
                }
            }
        }
Beispiel #3
0
        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 (!Util.GetSelectionData (ApplicationContext, selectionData, DragDropInfo.DragData)) {
                return false;
            }

            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.Action);
                    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;
        }
Beispiel #4
0
 /// <summary>
 /// Raises the DragDrop event.
 /// </summary>
 /// <param name='args'>
 /// Arguments.
 /// </param>
 protected internal virtual void OnDragDrop(DragEventArgs args)
 {
     if (dragDrop != null)
         dragDrop (this, args);
 }
Beispiel #5
0
 public void OnDragDrop(DragEventArgs args)
 {
     Parent.OnDragDrop (args);
 }
Beispiel #6
0
        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 (!Util.GetSelectionData (selectionData, DragDropInfo.DragData)) {
                return false;
            }

            if (DragDropInfo.DragDataRequests == 0) {
                if (DragDropInfo.DragDataForMotion) {
                    // This is a workaround to what seems to be a mac gtk bug.
                    // Suggested action is set to all when no control key is pressed
                    var cact = ConvertDragAction (context.Actions);
                    if (cact == DragDropAction.All)
                        cact = DragDropAction.Move;

                    DragOverEventArgs da = new DragOverEventArgs (DragDropInfo.LastDragPosition, DragDropInfo.DragData, cact);
                    Toolkit.Invoke (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.Action);
                    DragEventArgs da = new DragEventArgs (DragDropInfo.LastDragPosition, DragDropInfo.DragData, cda);
                    Toolkit.Invoke (delegate {
                        EventSink.OnDragDrop (da);
                    });
                    Gtk.Drag.Finish (context, da.Success, cda == DragDropAction.Move, time);
                    return true;
                }
            } else
                return false;
        }
Beispiel #7
0
        protected override void OnDragDrop(DragEventArgs args)
        {
            Point position = args.Position;
            position.X /= scaleFactor;
            position.Y /= scaleFactor;

            args.Success = true;
            try {
                string algoType = args.Data.GetValue(TransferDataType.Text).ToString();

                PipelineNode node =
                    new PipelineNode(project, this, algoType, new Rectangle(position, PipelineNode.AbsMinNodeSize));
                node.QueueRedraw += QueueRedraw;

                SetNodePosition(node);
                nodes.Add(node);
                Log.Add(LogLevel.Verbose, this.GetType().Name, "New node added \"" + node + "\".");

                EmitDataChanged();
                this.QueueDraw();

            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
                args.Success = false;

                Log.Add(LogLevel.Error, this.GetType().Name, "Failed to add new node.");
            }
        }
Beispiel #8
0
        void HandleWidgetDragDataReceived(object o, Gtk.DragDataReceivedArgs args)
        {
            dragDataRequests--;

            string type = Util.AtomToType (args.SelectionData.Target.Name);
            if (type == null) {
                args.RetVal = false;
                return;
            }

            if (args.SelectionData.Length > 0) {
                if (type == TransferDataType.Text)
                    dragData.AddText (args.SelectionData.Text);
                else if (args.SelectionData.TargetsIncludeImage (false))
                    dragData.AddImage (WidgetRegistry.CreateFrontend<Xwt.Drawing.Image> (args.SelectionData.Pixbuf));
                else if (type == TransferDataType.Uri) {
                    var uris = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data).Split ('\n').Where (u => !string.IsNullOrEmpty(u)).Select (u => new Uri (u)).ToArray ();
                    dragData.AddUris (uris);
                }
                else
                    dragData.AddValue (type, args.SelectionData.Data);
            }
            if (dragDataRequests == 0) {
                if (dragDataForMotion) {
                    DragOverEventArgs da = new DragOverEventArgs (lastDragPosition, dragData, ConvertDragAction (args.Context.Actions));
                    EventSink.OnDragOver (da);
                    Gdk.Drag.Status (args.Context, ConvertDragAction (da.AllowedAction), args.Time);
                }
                else {
                    // Use Context.Action here since that's the action selected in DragOver
                    var cda = ConvertDragAction (args.Context.Action);
                    DragEventArgs da = new DragEventArgs (lastDragPosition, dragData, cda);
                    EventSink.OnDragDrop (da);
                    Gtk.Drag.Finish (args.Context, da.Success, cda == DragDropAction.Move, args.Time);
                }
            }
        }