Пример #1
0
        public static bool SetRowDragData(Gtk.SelectionData selection_data, Gtk.ITreeModel tree_model, Gtk.TreePath path)
        {
            bool raw_ret = gtk_tree_set_row_drag_data(selection_data == null ? IntPtr.Zero : selection_data.Handle, tree_model == null ? IntPtr.Zero : ((tree_model is GLib.Object) ? (tree_model as GLib.Object).Handle : (tree_model as Gtk.TreeModelAdapter).Handle), path == null ? IntPtr.Zero : path.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Пример #2
0
        public bool DragDataReceived(Gtk.TreePath dest, Gtk.SelectionData selection_data)
        {
            bool raw_ret = gtk_tree_drag_dest_drag_data_received(Handle, dest == null ? IntPtr.Zero : dest.Handle, selection_data == null ? IntPtr.Zero : selection_data.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Пример #3
0
 public static void SetSelectionData(Gtk.SelectionData data, string atomType, object val)
 {
     if (val == null)
     {
         return;
     }
     if (val is string)
     {
         data.Text = (string)val;
     }
     else if (val is Xwt.Drawing.Image)
     {
         var bmp = ((Image)val).ToBitmap();
         data.SetPixbuf(((GtkImage)Toolkit.GetBackend(bmp)).Frames[0].Pixbuf);
     }
     else if (val is Uri)
     {
         data.SetUris(new string[] { ((Uri)val).AbsolutePath });
     }
     else
     {
         var at = Gdk.Atom.Intern(atomType, false);
         data.Set(at, 0, TransferDataSource.SerializeValue(val));
     }
 }
Пример #4
0
        public static bool GetSelectionData(ApplicationContext context, Gtk.SelectionData data, TransferDataStore target)
        {
            TransferDataType type = Util.AtomToType(data.Target.Name);

            if (type == null || data.Length <= 0)
            {
                return(false);
            }

            if (type == TransferDataType.Text)
            {
                target.AddText(data.Text);
            }
            else if (data.TargetsIncludeImage(false))
            {
                target.AddImage(context.Toolkit.WrapImage(data.Pixbuf));
            }
            else if (type == TransferDataType.Uri)
            {
                target.AddUris(data.GetUris().Where(u => !string.IsNullOrEmpty(u)).Select(u => new Uri(u)).ToArray());
            }
            else
            {
                target.AddValue(type, data.Data);
            }
            return(true);
        }
Пример #5
0
        public static bool GetSelectionData(Gtk.SelectionData data, TransferDataStore target)
        {
            TransferDataType type = Util.AtomToType(data.Target.Name);

            if (type == null || data.Length <= 0)
            {
                return(false);
            }

            if (type == TransferDataType.Text)
            {
                target.AddText(data.Text);
            }
            else if (data.TargetsIncludeImage(false))
            {
                target.AddImage(WidgetRegistry.CreateFrontend <Xwt.Drawing.Image> (data.Pixbuf));
            }
            else if (type == TransferDataType.Uri)
            {
                var uris = System.Text.Encoding.UTF8.GetString(data.Data).Split('\n').Where(u => !string.IsNullOrEmpty(u)).Select(u => new Uri(u)).ToArray();
                target.AddUris(uris);
            }
            else
            {
                target.AddValue(type, data.Data);
            }
            return(true);
        }
Пример #6
0
 public void GetData(Gtk.SelectionData selection_data)
 {
     if (GetClipboardData != null)
     {
         GetClipboardData(this, selection_data);
     }
 }
Пример #7
0
        public Gtk.SelectionData Copy()
        {
            IntPtr raw_ret = gtk_selection_data_copy(Handle);

            Gtk.SelectionData ret = raw_ret == IntPtr.Zero ? null : (Gtk.SelectionData)GLib.Opaque.GetOpaque(raw_ret, typeof(Gtk.SelectionData), true);
            return(ret);
        }
Пример #8
0
        public Gtk.Widget GetDragItem(Gtk.SelectionData selection)
        {
            IntPtr raw_ret = gtk_tool_palette_get_drag_item(Handle, selection == null ? IntPtr.Zero : selection.Handle);

            Gtk.Widget ret = GLib.Object.GetObject(raw_ret) as Gtk.Widget;
            return(ret);
        }
Пример #9
0
        public bool RowDropPossible(Gtk.TreePath dest_path, Gtk.SelectionData selection_data)
        {
            bool raw_ret = gtk_tree_drag_dest_row_drop_possible(Handle, dest_path == null ? IntPtr.Zero : dest_path.Handle, selection_data == null ? IntPtr.Zero : selection_data.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Пример #10
0
        public bool DragDataGet(Gtk.TreePath path, Gtk.SelectionData selection_data)
        {
            bool raw_ret = gtk_tree_drag_source_drag_data_get(Handle, path == null ? IntPtr.Zero : path.Handle, selection_data == null ? IntPtr.Zero : selection_data.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Пример #11
0
        /// <summary>
        /// Set selected uris.  Exists in newer versions of Gtk2, but not older versions so we do our own thing
        /// </summary>
        public static bool SetSelectedUris2(this Gtk.SelectionData data, string[] uris)
        {
            int length = uris?.Length ?? 0;
            var ptr    = GLib.Marshaller.StringArrayToNullTermPointer(uris);

            return(NativeMethods.gtk_selection_data_set_uris(data.Handle, ptr));
        }
Пример #12
0
        public Gtk.SelectionData WaitForContents(Gdk.Atom target)
        {
            IntPtr raw_ret = gtk_clipboard_wait_for_contents(Handle, target == null ? IntPtr.Zero : target.Handle);

            Gtk.SelectionData ret = raw_ret == IntPtr.Zero ? null : (Gtk.SelectionData)GLib.Opaque.GetOpaque(raw_ret, typeof(Gtk.SelectionData), true);
            return(ret);
        }
Пример #13
0
 public UriList(Gtk.SelectionData selection)
 {
     // FIXME this should check the atom etc.
     if (selection.Length > 0)
     {
         LoadFromString(Encoding.UTF8.GetString(selection.Data));
     }
 }
Пример #14
0
        protected override void OnDragDataReceived(Gdk.DragContext context,
                                                   int x, int y,
                                                   Gtk.SelectionData selectionData,
                                                   uint info, uint time_)
        {
            UriList uriList = new UriList(selectionData);

            if (uriList.Count == 0)
            {
                Gtk.Drag.Finish(context, false, false, time_);
                return;
            }

            Gtk.TreePath             path;
            Gtk.TreeViewDropPosition pos;
            if (GetDestRowAtPos(x, y, out path, out pos) == false)
            {
                Gtk.Drag.Finish(context, false, false, time_);
                return;
            }

            Gtk.TreeIter iter;
            if (Model.GetIter(out iter, path) == false)
            {
                Gtk.Drag.Finish(context, false, false, time_);
                return;
            }

            Notebook destNotebook = Model.GetValue(iter, 0) as Notebook;

            if (destNotebook is AllNotesNotebook)
            {
                Gtk.Drag.Finish(context, false, false, time_);
                return;
            }

            foreach (Uri uri in uriList)
            {
                Note note = noteManager.FindByUri(uri.ToString());
                if (note == null)
                {
                    continue;
                }

                Logger.Debug("Dropped into notebook: {0}", note.Title);

                // TODO: If we ever support selecting multiple notes,
                // we may want to double-check to see if there will be
                // any notes are already inside of a notebook.  Do we
                // want to prompt the user to confirm this choice?
                NotebookManager.MoveNoteToNotebook(note, destNotebook);
            }

            Gtk.Drag.Finish(context, true, false, time_);
        }
Пример #15
0
        public static bool GetRowDragData(Gtk.SelectionData selection_data, out Gtk.ITreeModel tree_model, out Gtk.TreePath path)
        {
            IntPtr native_tree_model;
            IntPtr native_path;
            bool   raw_ret = gtk_tree_get_row_drag_data(selection_data == null ? IntPtr.Zero : selection_data.Handle, out native_tree_model, out native_path);
            bool   ret     = raw_ret;

            tree_model = Gtk.TreeModelAdapter.GetObject(native_tree_model, false);
            path       = native_path == IntPtr.Zero ? null : (Gtk.TreePath)GLib.Opaque.GetOpaque(native_path, typeof(Gtk.TreePath), true);
            return(ret);
        }
Пример #16
0
 public void Apply(Gtk.SelectionData data)
 {
     foreach (var item in Control.Values)
     {
         if (item.Target.Target == data.Target.Name)
         {
             item.GetData(data);
             return;
         }
     }
 }
Пример #17
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);
            }
        }
Пример #18
0
        public static void Copy(Gtk.Widget widget, Gtk.SelectionData seldata, bool copyAsText)
        {
            XmlElement elem = ExportWidget(widget);

            if (elem == null)
            {
                return;
            }

            if (copyAsText)
            {
                seldata.Text = elem.OuterXml;
            }
            else
            {
                seldata.Set(ApplicationXSteticAtom, 8, System.Text.Encoding.UTF8.GetBytes(elem.OuterXml));
            }
        }
Пример #19
0
        public static void Copy(Gtk.Widget widget, Gtk.SelectionData seldata, bool copyAsText)
        {
            XmlDocument doc = Export(widget);

            if (doc == null)
            {
                return;
            }

            if (copyAsText)
            {
                seldata.Text = doc.OuterXml;
            }
            else
            {
                seldata.Set(ApplicationXGladeAtom, 8, System.Text.Encoding.UTF8.GetBytes(doc.OuterXml));
            }
        }
Пример #20
0
        /// <summary>
        /// Set selected uris.  Exists in newer versions of Gtk2, but not older versions so we do our own thing
        /// </summary>
        public static bool SetSelectedUris2(this Gtk.SelectionData data, string[] uris)
        {
            int length = uris?.Length ?? 0;

            IntPtr[] array = new IntPtr[length + 1];
            for (int i = 0; i < length; i++)
            {
                array[i] = GLib.Marshaller.StringToPtrGStrdup(uris[i]);
            }
            array[length] = IntPtr.Zero;
            var result = NativeMethods.gtk_selection_data_set_uris(data.Handle, array);

            for (int i = 0; i < length; i++)
            {
                GLib.Marshaller.Free(array[i]);
            }
            return(result);
        }
Пример #21
0
        public static Stetic.Wrapper.Widget Paste(IProject project, Gtk.SelectionData seldata)
        {
            if (seldata.Type != ApplicationXGladeAtom)
            {
                return(null);
            }
            string data = System.Text.Encoding.UTF8.GetString(seldata.Data);

            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;
            try {
                doc.LoadXml(data);
            } catch {
                return(null);
            }

            return(Import(project, doc));
        }
Пример #22
0
        public static Stetic.Wrapper.Widget Paste(IProject project, Gtk.SelectionData seldata)
        {
            if (seldata == null || seldata.Type == null || seldata.Type.Name != ApplicationXSteticAtom.Name)
            {
                return(null);
            }

            string      data = System.Text.Encoding.UTF8.GetString(seldata.Data);
            XmlDocument doc  = new XmlDocument();

            doc.PreserveWhitespace = true;
            try {
                doc.LoadXml(data);
            } catch {
                return(null);
            }

            Gtk.Widget w = ImportWidget(project, doc.DocumentElement);
            return(Wrapper.Widget.Lookup(w));
        }
Пример #23
0
 public static void SetSelectionData(Gtk.SelectionData data, string atomType, object val)
 {
     if (val == null)
     {
         return;
     }
     if (val is string)
     {
         data.Text = (string)val;
     }
     else if (val is Xwt.Drawing.Image)
     {
         data.SetPixbuf((Gdk.Pixbuf)WidgetRegistry.GetBackend(val));
     }
     else
     {
         var at = Gdk.Atom.Intern(atomType, false);
         data.Set(at, 0, TransferDataSource.SerializeValue(val));
     }
 }
Пример #24
0
        void DataReceived(Gtk.Clipboard cb, Gtk.SelectionData data)
        {
            TransferDataStore store = new TransferDataStore();

            if (Util.GetSelectionData(data, store))
            {
                Result = ((ITransferData)store).GetValue(type);
                SetComplete();
            }
            else
            {
                if (++index < atoms.Length)
                {
                    RequestData();
                }
                else
                {
                    SetComplete();
                }
            }
        }
        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;
        }
Пример #26
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);
            }
        }
Пример #27
0
 public static Gdk.Atom[] ListTargets(this Gtk.SelectionData data) => data.Targets;
Пример #28
0
        public static string[] GetSelectedUris(this Gtk.SelectionData data)
        {
            IntPtr ptr = NativeMethods.gtk_selection_data_get_uris(data.Handle);

            return(GLib.Marshaller.NullTermPtrToStringArray(ptr, true));
        }
Пример #29
0
        //
        // DND Drop handling
        //
        protected override void OnDragDataReceived(Gdk.DragContext context,
                                                   int x,
                                                   int y,
                                                   Gtk.SelectionData selection_data,
                                                   uint info,
                                                   uint time)
        {
            bool has_url = false;

            foreach (Gdk.Atom target in context.Targets)
            {
                if (target.Name == "text/uri-list" ||
                    target.Name == "_NETSCAPE_URL")
                {
                    has_url = true;
                    break;
                }
            }

            if (has_url)
            {
                UriList uri_list      = new UriList(selection_data);
                bool    more_than_one = false;

                // Place the cursor in the position where the uri was
                // dropped, adjusting x,y by the TextView's VisibleRect.
                Gdk.Rectangle rect      = VisibleRect;
                int           adjustedX = x + rect.X;
                int           adjustedY = y + rect.Y;
                Gtk.TextIter  cursor    = GetIterAtLocation(adjustedX, adjustedY);
                Buffer.PlaceCursor(cursor);

                Gtk.TextTag link_tag = Buffer.TagTable.Lookup("link:url");

                foreach (Uri uri in uri_list)
                {
                    Logger.Debug("Got Dropped URI: {0}", uri);
                    string insert;
                    if (uri.IsFile)
                    {
                        // URL-escape the path in case
                        // there are spaces (bug #303902)
                        insert = System.Uri.EscapeUriString(uri.LocalPath);
                    }
                    else
                    {
                        insert = uri.ToString();
                    }

                    if (insert == null || insert.Trim() == String.Empty)
                    {
                        continue;
                    }

                    if (more_than_one)
                    {
                        cursor = Buffer.GetIterAtMark(Buffer.InsertMark);

                        // FIXME: The space here is a hack
                        // around a bug in the URL Regex which
                        // matches across newlines.
                        if (cursor.LineOffset == 0)
                        {
                            Buffer.Insert(ref cursor, " \n");
                        }
                        else
                        {
                            Buffer.Insert(ref cursor, ", ");
                        }
                    }

                    Buffer.InsertWithTags(ref cursor, insert, link_tag);
                    more_than_one = true;
                }

                Gtk.Drag.Finish(context, more_than_one, false, time);
            }
            else
            {
                base.OnDragDataReceived(context, x, y, selection_data, info, time);
            }
        }
Пример #30
0
 void InvokeNative(Gtk.Clipboard clipboard, Gtk.SelectionData selection_data, uint info)
 {
     native_cb(clipboard == null ? IntPtr.Zero : clipboard.Handle, selection_data == null ? IntPtr.Zero : selection_data.Handle, info, __data);
 }