public static void SetDragData(TransferDataSource data, Gtk.DragDataGetArgs args) { foreach (var t in data.DataTypes) { object val = data.GetValue (t); SetSelectionData (args.SelectionData, t.Id, val); } }
// remove this, just for debug: protected virtual TransferDataSource DragDataSource() { var result = new TransferDataSource(); result.AddValue <string>("hello drag"); return(result); }
public override object GetData(TransferDataType type) { if (type == TransferDataType.Uri) { return((Uri)NSUrl.FromPasteboard(NSPasteboard.GeneralPasteboard)); } var data = NSPasteboard.GeneralPasteboard.GetDataForType(type.ToUTI()); if (data == null) { return(null); } if (type == TransferDataType.Text) { return(data.ToString()); } if (type == TransferDataType.Image) { return(new NSImage(data)); } unsafe { var bytes = new byte [data.Length]; using (var stream = new UnmanagedMemoryStream((byte *)data.Bytes, bytes.Length)) stream.Read(bytes, 0, bytes.Length); return(TransferDataSource.DeserializeValue(bytes)); } }
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) { 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 static void SetDragData(TransferDataSource data, Gtk.DragDataGetArgs args) { foreach (var t in data.DataTypes) { object val = data.GetValue(t); SetSelectionData(args.SelectionData, t.Id, val); } }
internal DragStartData(TransferDataSource data, DragDropAction action, object imageBackend, double hotX, double hotY) { Data = data; DragAction = action; ImageBackend = imageBackend; HotX = hotX; HotY = hotY; }
public void DragStart(TransferDataSource data, DragDropAction dragAction, object imageBackend, double hotX, double hotY) { Gdk.DragAction action = ConvertDragAction(dragAction); currentDragData = data; Widget.DragBegin += HandleDragBegin; IconInitializer.Init(Widget, (Gdk.Pixbuf)imageBackend, hotX, hotY); Gtk.Drag.Begin(Widget, Util.BuildTargetTable(data.DataTypes), action, 1, Gtk.Global.CurrentEvent); }
public virtual TransferDataSource TransferDataOfVisual(IGraph <IVisual, IVisualEdge> graph, IVisual visual) { if (graph == null || visual == null) { return(null); } var result = new TransferDataSource(); result.AddValue <string> (visual.Data.ToString()); return(result); }
void InitPasteboard(NSPasteboard pb, TransferDataSource data) { pb.ClearContents(); foreach (var t in data.DataTypes) { if (t == TransferDataType.Text) { pb.AddTypes(new string[] { NSPasteboard.NSStringType }, null); pb.SetStringForType((string)data.GetValue(t), NSPasteboard.NSStringType); } } }
public void AddValue(TransferDataType type, byte[] value) { Type t = Type.GetType(type.Id); if (t != null) { data [type] = TransferDataSource.DeserializeValue(value); } else { data [type] = value; } }
T ITransferData.GetValue <T> () { object ob = GetValue(TransferDataType.FromType(typeof(T))); if (ob == null || ob.GetType() == typeof(Type)) { return((T)ob); } if (ob is byte[]) { T val = (T)TransferDataSource.DeserializeValue((byte[])ob); data[TransferDataType.FromType(typeof(T))] = val; return(val); } return((T)ob); }
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)); } } }
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 static TransferDataSource ToXwt(this SWF.DataObject data) { var result = new TransferDataSource(); result.DataRequestCallback = dt => data.GetData(dt.ToSwf()); foreach (var item in data.GetFormats()) { var format = ToXwtTransferType(item); if (format == TransferDataType.Uri) { result.DataRequestCallback = dt => { var value = data.GetData(TransferDataType.Uri.ToSwf()); var uris = ((string[])value).Select(f => new Uri(f)).ToArray(); return(uris); }; } result.AddType(format); } return(result); }
public void DragStart(TransferDataSource data, DragDropAction dragAction, object image, double xhot, double yhot) { var lo = RootWidget.ConvertPointToBase(new PointF(Widget.Bounds.X, Widget.Bounds.Y)); lo = RootWidget.Window.ConvertBaseToScreen(lo); var ml = NSEvent.CurrentMouseLocation; var pb = NSPasteboard.FromName(NSPasteboard.NSDragPasteboardName); if (pb == null) { throw new InvalidOperationException("Could not get pasteboard"); } if (data == null) { throw new ArgumentNullException("data"); } InitPasteboard(pb, data); var img = (NSImage)image; var pos = new PointF(ml.X - lo.X - (float)xhot, lo.Y - ml.Y - (float)yhot + img.Size.Height); Widget.DragImage(img, pos, new SizeF(0, 0), NSApplication.SharedApplication.CurrentEvent, pb, Widget, true); }
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)); } } }
public void DragStart(TransferDataSource data, DragDropAction dragAction, object dragImage, double xhot, double yhot) { throw new NotImplementedException(); }
public virtual IVisual VisualOfTransferData(IGraph <IVisual, IVisualEdge> graph, ITransferData data) { var value = data.GetValue(TransferDataType.FromType(typeof(IVisual))); var bytes = value as byte []; if (bytes != null) { return(TransferDataSource.DeserializeValue(bytes) as IVisual); } #if TRACE var dt = ""; data.DataTypes.ForEach(d => dt += d.Id + " | "); Trace.WriteLine($"{nameof(DragDropViz)}.{nameof (VisualOfTransferData)}\t{dt}"); #endif Stream stream = null; Content <Stream> content = null; string desc = null; string source = null; Func <ContentInfo, Stream, Content <Stream> > fillContent = (i, s) => { bool newContent = content == null || s != content.Data; var content1 = new Content <Stream> (content) { Data = newContent ? s : content.Data, ContentType = newContent ? i.ContentType : content.ContentType, Compression = newContent ? i.Compression : content.Compression, }; content1 = ContentDiggPool.Use(content1); desc = desc ?? content1?.Description?.ToString(); source = source ?? content1?.Source?.ToString(); return(content1); }; if (data.Uris.Length > 0) { //TODO: handle more then one file foreach (var uri in data.Uris.OrderBy(n => n.ToString())) { IContentIo <Stream> sink = null; string uridesc = null; if (uri.IsFile) { var fileName = IoUtils.UriToFileName(uri); if (File.Exists(fileName)) // TODO: check if filename is directory { stream = File.OpenRead(fileName); sink = DataManager.SinkOf(Path.GetExtension(fileName).TrimStart('.').ToLower()); uridesc = Path.GetFileNameWithoutExtension(fileName); } } else if (uri.HostNameType == UriHostNameType.Dns) { try { using (var cli = new WebClient()) { bytes = cli.DownloadData(uri); stream = new MemoryStream(bytes); } uridesc = uri.ToString(); } catch (Exception webEx) { Registry.Pooled <IMessageBoxShow> ().Show("Download failed", $"The uri \n{uri.ToString ()}\ncould not be loaded: {webEx.Message}", MessageBoxButtons.Ok); } } if (stream != null) { ContentInfo info = null; if (sink == null) { sink = DataManager.SinkOf(stream); } if (sink != null) { info = sink.Use(stream); } if (sink == null) { info = new ContentInfo("Unknown", ContentTypes.Unknown, "*", null, CompressionType.neverCompress); } content = fillContent(info, stream); if (content.Description == null) { content.Description = uridesc; } content.Source = uridesc; if (data.Uris.Length > 1) { Registry.Pooled <IMessageBoxShow> ().Show("DragDrop multiple files", string.Format("Only one file {0} will be stored currently", uri.AbsolutePath), MessageBoxButtons.Ok); } break; } } } else { var dataTypes = data.DataTypes.ToArray(); if (data.Text != null) { using (var dr = new StringReader(data.Text)) desc = dr.ReadLine(); } foreach (var s in DataManager.SinksOf(dataTypes).ToArray()) { var transferType = s.Item1; value = data.GetValue(transferType); var sink = s.Item2; stream = value as Stream; bytes = value as byte []; if (bytes != null) { stream = new MemoryStream(bytes); } var text = value as string; if (text != null) { stream = text.AsUnicodeStream(); } if (stream != null) { var info = sink.Use(stream); var contentSpec = sink.Detector; if (info == null && contentSpec != null) { info = contentSpec.FindMime(s.Item1.Id); } if (info == null) { info = DataManager.InfoOf(sink, dataTypes).FirstOrDefault(); } if (info != null && content == null || content.Data == null) { content = fillContent(info, stream); // TODO: find a better handling of preferences; maybe MimeFingerPrints does the job? if (content.Data == null || desc == null || source == null) { continue; } } else if (info != null) { fillContent(info, stream); if (desc == null || source == null) { continue; } } if (content != null) { if (content.Description == null) { content.Description = desc; } if (content.Source == null) { content.Source = source; } } } } } if (content != null) { #if TRACE Trace.WriteLine($"{nameof (VisualOfTransferData)}\tDragged:\t{content.ContentType.MimeType ()}"); #endif var result = VisualContentViz.VisualOfContent(graph, content); if (stream is FileStream) { stream.Close(); } return(result); } return(null); }
public void DragStart(TransferDataSource data, DragDropAction dragAction, object dragImage, double xhot, double yhot) { throw new NotImplementedException (); }
public void DragStart(TransferDataSource data, DragDropAction dragAction, object imageBackend, double hotX, double hotY) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="Xwt.Backends.DragStartData"/> class. /// </summary> /// <param name="data">The collection of data to be transferred through drag operation.</param> /// <param name="action">The type of the drag action.</param> /// <param name="imageBackend">The image backend of the drag image.</param> /// <param name="hotX">The image hotspot X coordinate.</param> /// <param name="hotY">The image hotspot Y coordinate.</param> internal DragStartData (TransferDataSource data, DragDropAction action, object imageBackend, double hotX, double hotY) { Data = data; DragAction = action; ImageBackend = imageBackend; HotX = hotX; HotY = hotY; }
public void DragStart(TransferDataSource data, DragDropAction dragAction, object imageBackend, double hotX, double hotY) { throw new NotImplementedException (); }