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)); } }
public static DataObject ToDataObject(this TransferDataSource data) { var retval = new DataObject(); foreach (var type in data.DataTypes) { var value = data.GetValue(type); if (type == TransferDataType.Text) { retval.SetText((string)value); } else if (type == TransferDataType.Uri) { var uris = new StringCollection(); uris.Add(((Uri)value).LocalPath); retval.SetFileDropList(uris); } else { retval.SetData(type.Id, TransferDataSource.SerializeValue(value)); } } return(retval); }
public void ProvideData(NSPasteboard pboard, NSString type) { NSData data; var obj = DataSource(); if (obj is Xwt.Drawing.Image) { var bmp = ((Xwt.Drawing.Image)obj).ToBitmap(); data = ((NSImage)Toolkit.GetBackend(bmp)).AsTiff(); } else if (obj is NSImage) { data = ((NSImage)obj).AsTiff(); } else if (obj is Uri) { data = NSData.FromUrl((NSUrl)((Uri)obj)); } else if (obj is string) { data = NSData.FromString((string)obj); } else { data = NSData.FromArray(TransferDataSource.SerializeValue(obj)); } pboard.SetDataForType(data, type); }
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)); } }
public void ProvideData(NSPasteboard pboard, NSString type) { NSData data; var obj = DataSource(); if (obj is NSImage) { data = ((NSImage)obj).AsTiff(); } else if (obj is Uri) { data = NSData.FromUrl((NSUrl)((Uri)obj)); } else if (obj is string) { data = NSData.FromString((string)obj); } else { data = NSData.FromArray(TransferDataSource.SerializeValue(obj)); } pboard.SetDataForType(data, type); }
public static void SetDragData(TransferDataSource data, Gtk.DragDataGetArgs args) { foreach (var t in data.DataTypes) { object val = data.GetValue(t); if (val == null) { continue; } if (val is string) { args.SelectionData.Text = (string)data.GetValue(t); } else if (val is Xwt.Drawing.Image) { args.SelectionData.SetPixbuf((Gdk.Pixbuf)WidgetRegistry.GetBackend(val)); } else { var at = Gdk.Atom.Intern(t, false); args.SelectionData.Set(at, 0, TransferDataSource.SerializeValue(val)); } } }