AtomToType() static private method

static private AtomToType ( string targetName ) : TransferDataType
targetName string
return TransferDataType
Example #1
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);
        }
Example #2
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);
        }
Example #3
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));
                    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);
                }
            }
        }
Example #4
0
 public void SetData(TransferDataType type, Func <object> dataSource)
 {
     clipboard.SetWithData((Gtk.TargetEntry[])Util.BuildTargetTable(new TransferDataType[] { type }),
                           delegate(Gtk.Clipboard cb, Gtk.SelectionData data, uint id) {
         TransferDataType ttype = Util.AtomToType(data.Target.Name);
         if (ttype == type)
         {
             Util.SetSelectionData(data, data.Target.Name, dataSource());
         }
     },
                           delegate {
     });
 }