Esempio n. 1
0
 // Drag function for automatic sources, called from DragBegin
 public static void Drag(Gtk.Widget source, Gdk.DragContext ctx, WidgetDropCallback dropCallback, string label)
 {
     Gtk.Frame fr = new Gtk.Frame();
     fr.ShadowType = Gtk.ShadowType.Out;
     Gtk.HBox box = new Gtk.HBox();
     box.Spacing     = 3;
     box.BorderWidth = 3;
     box.PackStart(new Gtk.Image(widgetIcon), false, false, 0);
     Gtk.Label lab = new Gtk.Label(label);
     lab.Xalign = 0;
     box.PackStart(lab, true, true, 0);
     fr.Add(box);
     fr.ShowAll();
     Drag(source, ctx, dropCallback, fr);
 }
Esempio n. 2
0
        // Call this from a DragDrop event to receive the dragged widget
        public static void Drop(Gdk.DragContext ctx, uint time, ObjectWrapper targetWrapper, string dropData)
        {
            if (dropCallback == null)
            {
                Gtk.Widget w = Drop(ctx, (Gtk.Widget)targetWrapper.Wrapped, time);
                targetWrapper.DropObject(dropData, w);
                return;
            }

            Cancel();
            Gtk.Drag.Finish(ctx, true, true, time);

            Gtk.Application.Invoke(delegate {
                IProject project = targetWrapper.Project;
                string uid       = targetWrapper.UndoId;
                string tname     = ((Wrapper.Widget)targetWrapper).GetTopLevel().Wrapped.Name;

                // This call may cause the project to be reloaded
                dragWidget = dropCallback();
                if (dragWidget == null)
                {
                    return;
                }

                if (targetWrapper.IsDisposed)
                {
                    // The project has been reloaded. Find the wrapper again.
                    Gtk.Widget twidget = project.GetWidget(tname);
                    ObjectWrapper ow   = ObjectWrapper.Lookup(twidget);
                    if (ow != null)
                    {
                        targetWrapper = ow.FindObjectByUndoId(uid);
                    }
                    else
                    {
                        targetWrapper = null;
                    }

                    if (targetWrapper == null)
                    {
                        // Target wrapper not found. Just ignore the drop.
                        return;
                    }
                }

                targetWrapper.DropObject(dropData, dragWidget);
            });
        }
Esempio n. 3
0
        bool CheckAndDrop(int x, int y, bool drop, Gdk.DragContext ctx)
        {
            Gtk.TreePath             path;
            Gtk.TreeViewDropPosition pos;
            if (!bugsList.GetDestRowAtPos(x, y, out path, out pos))
            {
                return(false);
            }

            Gtk.TreeIter iter;
            if (!bugsStore.GetIter(out iter, path))
            {
                return(false);
            }
            return(pos == TreeViewDropPosition.IntoOrAfter || pos == TreeViewDropPosition.IntoOrBefore);
        }
        protected override bool OnDragMotion(Gdk.DragContext context, int x, int y, uint time)
        {
            bool canDrop = CheckCanDrop != null && CheckCanDrop(context, x, y, time);

            //let default handler handle hover-to-expand, autoscrolling, etc
            base.OnDragMotion(context, x, y, time);

            //if we can't handle it, flag as not droppable and remove the drop marker
            if (!canDrop)
            {
                Gdk.Drag.Status(context, (Gdk.DragAction) 0, time);
                SetDragDestRow(null, 0);
            }

            return(true);
        }
Esempio n. 5
0
        internal bool DoDragDrop(Gdk.DragContext context, int x, int y, uint time)
        {
            DragDropInfo.LastDragPosition = new Point(x, y);
            var cda = ConvertDragAction(context.Action);

            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.Targets), 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);
            }
        }
Esempio n. 6
0
        public static Gtk.Widget Drop(Gdk.DragContext ctx, Gtk.Widget target, uint time)
        {
            if (dropCallback != null)
            {
                dragWidget = dropCallback();
            }

            if (dragWidget == null)
            {
                Gtk.Drag.GetData(target, ctx, GladeUtils.ApplicationXGladeAtom, time);
                return(null);
            }

            Gtk.Widget w = Cancel();
            Gtk.Drag.Finish(ctx, true, true, time);
            return(w);
        }
        protected override bool OnDragMotion(Gdk.DragContext context, int x, int y, uint time)
        {
            if (!IsReorderable)
            {
                StopDragScroll();
                drag_reorder_row_index = -1;
                drag_reorder_motion_y  = -1;
                InvalidateList();
                return(false);
            }

            drag_reorder_motion_y = y;
            DragReorderUpdateRow();

            OnDragScroll(OnDragVScrollTimeout, Allocation.Height * 0.3, Allocation.Height, y);

            return(true);
        }
Esempio n. 8
0
            protected override DragEventArgs GetDragEventArgs(Gdk.DragContext context, PointF?location, uint time = 0, object controlObject = null)
            {
                var t = Handler?.Tree;
                GridViewDragInfo dragInfo = _dragInfo;

                if (dragInfo == null && location != null)
                {
                    if (t.GetDestRowAtPos((int)location.Value.X, (int)location.Value.Y, out var path, out var pos))
                    {
                        var item     = Handler.model.GetItemAtPath(path);
                        var indecies = path.Indices;
                        var index    = indecies[indecies.Length - 1];
                        dragInfo = new GridViewDragInfo(Handler.Widget, item, index, pos.ToEto());
                    }
                }

                return(base.GetDragEventArgs(context, location, time, dragInfo));
            }
 protected override void OnDragDataGet(Gdk.DragContext context, SelectionData selection_data, uint info, uint time)
 {
     if (info == Banshee.Gui.DragDrop.DragDropTarget.UriList.Info)
     {
         ITrackModelSource track_source = ServiceManager.SourceManager.ActiveSource as ITrackModelSource;
         if (track_source != null)
         {
             System.Text.StringBuilder sb = new System.Text.StringBuilder();
             foreach (TrackInfo track in track_source.TrackModel.SelectedItems)
             {
                 sb.Append(track.Uri);
                 sb.Append("\r\n");
             }
             byte [] data = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
             selection_data.Set(context.Targets[0], 8, data, data.Length);
         }
     }
 }
Esempio n. 10
0
        public void DragSelectedItem(Gtk.Widget source, Gdk.DragContext ctx)
        {
            if ((CurrentConsumer == null) || (selectedItem == null))
            {
                return;
            }

            try {
                CurrentConsumer.DragItem(selectedItem, source, ctx);
                OnToolboxUsed(CurrentConsumer, selectedItem);
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError("Error dragging toolbox item.", ex);
                //run this dialog on a timeout so it doesn't block the drag completing
                GLib.Timeout.Add(100, delegate {
                    MessageService.ShowException(ex, "Error dragging toolbox item.");
                    return(false);
                });
            }
        }
Esempio n. 11
0
            protected virtual DragEventArgs GetDragEventArgs(Gdk.DragContext context, PointF?location, uint time = 0, object controlObject = null)
            {
                var widget = Gtk.Drag.GetSourceWidget(context);
                var source = widget?.Data[GtkControl.DropSource_Key] as Eto.Forms.Control;

#if GTK2
                var action = context.Action;
#else
                var action = context.SelectedAction;
#endif

                var data = new DataObject(new DataObjectHandler(Handler.DragControl, context, time));
                if (location == null)
                {
                    location = Handler.PointFromScreen(Mouse.Position);
                }

                return(new DragEventArgs(source, data, action.ToEto(), location.Value, Keyboard.Modifiers, Mouse.Buttons, controlObject));
            }
Esempio n. 12
0
 protected override bool OnDragDrop(Gdk.DragContext drg, int x, int y, uint time)
 {
     Gtk.Widget w = Gtk.Drag.GetSourceWidget(drg);
     if (w is CS_TrackListView)
     {
         CS_TrackListView v     = (CS_TrackListView)w;
         CS_PlayListModel model = (CS_PlayListModel)this.Model;
         CS_PlayList      pls   = model.PlayList;
         if (pls != null)
         {
             List <CueSheetEntry> l = v.DragData;
             foreach (CueSheetEntry e in l)
             {
                 pls.Add(e);
             }
             model.Reload();
             pls.Save();
         }
     }
     return(false);
 }
Esempio n. 13
0
        protected override void OnSetDragStatus(Gdk.DragContext context, int x, int y, uint time, Gdk.DragAction action)
        {
            base.OnSetDragStatus(context, x, y, time, action);

            // We are overriding the TreeView methods for handling drag & drop, so we need
            // to manually highlight the selected row

            Gtk.TreeViewDropPosition tpos;
            Gtk.TreePath             path;
            if (!Widget.GetDestRowAtPos(x, y, out path, out tpos))
            {
                path = null;
            }

            if (expandTimer == 0 || !object.Equals(autoExpandPath, path))
            {
                if (expandTimer != 0)
                {
                    GLib.Source.Remove(expandTimer);
                }
                if (path != null)
                {
                    expandTimer = GLib.Timeout.Add(600, delegate {
                        expandTimer = 0;
                        Widget.ExpandRow(path, false);
                        return(false);
                    });
                }
                autoExpandPath = path;
            }

            if (path != null && action != 0)
            {
                Widget.SetDragDestRow(path, tpos);
            }
            else
            {
                Widget.SetDragDestRow(null, 0);
            }
        }
        protected override bool OnDragDrop(Gdk.DragContext context, int x, int y, uint time_)
        {
            TreeIter             srcIter, dstIter;
            TreeViewDropPosition srcPos, dstPos;

            var srcVm    = GetTimelineAtPosition((int)dragStart.X, (int)dragStart.Y, out srcIter, out srcPos);
            var dstVm    = GetTimelineAtPosition(x, y, out dstIter, out dstPos);
            int dstIndex = ViewModel.EventTypesTimeline.ViewModels.IndexOf(dstVm);
            int srcIndex = ViewModel.EventTypesTimeline.ViewModels.IndexOf(srcVm);

            if (dstPos == TreeViewDropPosition.Before)
            {
                store.MoveBefore(srcIter, dstIter);
            }
            else
            {
                store.MoveAfter(srcIter, dstIter);
            }
            ViewModel.EventTypesTimeline.ViewModels.Move(srcIndex, dstIndex);
            Project.Model.EventTypes.Move(srcIndex, dstIndex);
            return(true);
        }
Esempio n. 15
0
        private void DoDragBegin(Gtk.Widget child, Gdk.DragContext context)
        {
            Gdk.Pixbuf icon;

            Plotting.Graph graph = (Plotting.Graph)child;

            d_dragRenderer  = null;
            d_unmerged      = null;
            d_dragHighlight = null;

            // Check if this is going to drag a label
            if (graph.Canvas.Graph.LabelHitTest(new Point(d_lastPress), out d_dragRenderer))
            {
                icon = PixbufForRenderer(graph.Canvas.Graph, d_dragRenderer);
            }
            else
            {
                icon = graph.CreateDragIcon();
            }

            if (icon != null)
            {
                Gtk.Drag.SetIconPixbuf(context, icon, icon.Width / 2, icon.Height / 2);
            }

            d_dragging = graph;

            IndexOf(child, out d_dragRow, out d_dragColumn);

            Gdk.EventMotion evnt = Utils.GetCurrentEvent() as Gdk.EventMotion;

            d_dragmerge = (evnt != null && (evnt.State & Gdk.ModifierType.ShiftMask) != 0);

            IndexOf(child, out d_dragRow, out d_dragColumn);

            QueueDraw();
        }
        protected override void OnDragDataGet(Gdk.DragContext context, Gtk.SelectionData selection_data, uint info, uint time_)
        {
            Console.WriteLine("getting data?");
            //TrackListModel model=_view.GetSource().TrackModel;
            CS_TrackListModel model = (CS_TrackListModel)this.Model;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            List <CueSheetEntry>      l  = new List <CueSheetEntry>();

            foreach (TrackInfo track in model.SelectedItems)
            {
                CueSheetEntry e = (CueSheetEntry)track;
                l.Add(e);
                Console.WriteLine("id=" + e.id());
                //string id=e.id ();
                //sb.Append (id);
                //sb.Append ("#@#");
            }
            byte [] data = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
            selection_data.Set(context.Targets[0], 8, data, data.Length);
            Console.WriteLine(sb.ToString());
            //context.Data.Add ("tracks",sb.ToString ());
            DragData = l;
        }
Esempio n. 17
0
 public static void DropDone(Gdk.DragContext context, bool success)
 {
     gdk_drag_drop_done(context == null ? IntPtr.Zero : context.Handle, success);
 }
Esempio n. 18
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);
            }
        }
Esempio n. 19
0
 protected virtual void OnSetDragStatus(Gdk.DragContext context, int x, int y, uint time, Gdk.DragAction action)
 {
     Gdk.Drag.Status(context, action, time);
 }
Esempio n. 20
0
        internal void BeginComponentDrag(ProjectBackend project, string desc, string className, ObjectWrapper wrapper, Gtk.Widget source, Gdk.DragContext ctx, ComponentDropCallback callback)
        {
            if (wrapper != null)
            {
                Stetic.Wrapper.ActionPaletteItem it = new Stetic.Wrapper.ActionPaletteItem(Gtk.UIManagerItemType.Menuitem, null, (Wrapper.Action)wrapper);
                DND.Drag(source, ctx, it);
            }
            else if (callback != null)
            {
                DND.Drag(source, ctx, delegate() {
                    callback();

                    // If the class name has an assembly name, remove it now
                    int i = className.IndexOf(',');
                    if (i != -1)
                    {
                        className = className.Substring(0, i);
                    }

                    ClassDescriptor cls = Registry.LookupClassByName(className);
                    if (cls != null)
                    {
                        return(cls.NewInstance(project) as Gtk.Widget);
                    }
                    else
                    {
                        // Class not found, show an error
                        string msg            = string.Format("The widget '{0}' could not be found.", className);
                        Gtk.MessageDialog dlg = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Close, msg);
                        dlg.Run();
                        dlg.Destroy();
                        return(null);
                    }
                },
                         (desc != null && desc.Length > 0) ? desc : className
                         );
            }
            else
            {
                ClassDescriptor cls = Registry.LookupClassByName(className);
                DND.Drag(source, ctx, cls.NewInstance(project) as Gtk.Widget);
            }
        }
Esempio n. 21
0
 private void DoDragEnd(Gtk.Widget child, Gdk.DragContext context)
 {
     d_dragging = null;
     QueueDraw();
 }
Esempio n. 22
0
 public static Gdk.DragAction GetSelectedAction(this Gdk.DragContext context)
 {
     return(context.SelectedAction);
 }
Esempio n. 23
0
        protected override bool OnDragMotion(Gdk.DragContext context, int x, int y, uint time_)
        {
            base.OnDragMotion(context, x, y, time_);

            if (d_dragging == null)
            {
                Gdk.Drag.Status(context, 0, time_);
                UnsetDragHighlight();

                return(false);
            }
            else if (d_dragmerge)
            {
                int r;
                int c;

                if (CellAtPixel(x, y, out r, out c) && d_children[r, c] != null)
                {
                    if (d_dragHighlight != d_children[r, c])
                    {
                        UnsetDragHighlight();
                    }

                    if (d_children[r, c] != null && d_dragging.IsTime != d_children[r, c].IsTime)
                    {
                        Gdk.Drag.Status(context, 0, time_);
                    }
                    else
                    {
                        if (d_dragging != d_children[r, c])
                        {
                            d_dragHighlight = d_children[r, c];
                            Gtk.Drag.Highlight(d_dragHighlight);
                        }

                        Gdk.Drag.Status(context, Gdk.DragAction.Move, time_);
                    }
                }
                else
                {
                    UnsetDragHighlight();
                    Gdk.Drag.Status(context, 0, time_);
                }

                return(true);
            }
            else
            {
                if (DoUpdateDragging(x, y))
                {
                    UnsetDragHighlight();
                    Gdk.Drag.Status(context, Gdk.DragAction.Move, time_);
                }
                else
                {
                    if (d_dragHighlight != null)
                    {
                        Gtk.Drag.Unhighlight(d_dragHighlight);
                        d_dragHighlight = null;
                    }

                    Gdk.Drag.Status(context, 0, time_);
                }
                return(true);
            }
        }
Esempio n. 24
0
 // Drag function for automatic sources, called from DragBegin
 public static void Drag(Gtk.Widget source, Gdk.DragContext ctx, Gtk.Widget dragWidget)
 {
     Drag(source, ctx, null, dragWidget);
 }
Esempio n. 25
0
 public void DragItem(ItemToolboxNode item, Widget source, Gdk.DragContext ctx)
 {
 }
Esempio n. 26
0
 public static void Status(Gdk.DragContext context, Gdk.DragAction action, uint time_)
 {
     gdk_drag_status(context == null ? IntPtr.Zero : context.Handle, (int)action, time_);
 }
Esempio n. 27
0
 public static void Drop(Gdk.DragContext context, uint time_)
 {
     gdk_drag_drop(context == null ? IntPtr.Zero : context.Handle, time_);
 }
Esempio n. 28
0
 public static void Reply(Gdk.DragContext context, bool accepted, uint time_)
 {
     gdk_drop_reply(context == null ? IntPtr.Zero : context.Handle, accepted, time_);
 }
Esempio n. 29
0
 public static void Finish(Gdk.DragContext context, bool success, uint time_)
 {
     gdk_drop_finish(context == null ? IntPtr.Zero : context.Handle, success, time_);
 }
Esempio n. 30
0
 public static Gdk.Atom[] ListTargets(this Gdk.DragContext context) => context.Targets;