public override void ProvideDataForType (NSPasteboard pasteboard, NSPasteboardItem item, string type) { // Take action based on the type switch (type) { case "public.text": // Encode the data to string item.SetStringForType(string.Format("{0}.{1}", Name, ImageType),type); break; } }
public static NSPasteboardReadingOptions GetReadingOptionsForType (string type, NSPasteboard pasteboard) { // Take action based on the requested type switch (type) { case "com.xamarin.image-info": return NSPasteboardReadingOptions.AsKeyedArchive; case "public.text": return NSPasteboardReadingOptions.AsString; } // Default to property list return NSPasteboardReadingOptions.AsPropertyList; }
public override bool WriteRows(NSTableView tableView, MonoMac.Foundation.NSIndexSet rowIndexes, NSPasteboard pboard) { return(false); }
public override bool WriteRows(NSTableView tableView, NSIndexSet rowIndexes, NSPasteboard pboard) { var h = Handler; if (h == null) { return(false); } if (h.IsMouseDragging) { h.DragInfo = null; // give MouseMove event a chance to start the drag h.DragPasteboard = pboard; // check if the dragged rows are different than the selection so we can fire a changed event var dragRows = rowIndexes.Select(r => (int)r).ToList(); bool isDifferentSelection = (nint)dragRows.Count != h.Control.SelectedRowCount; if (!isDifferentSelection) { // same count, ensure they're not different rows // typically only tests one entry here, as there's no way to drag more than a single non-selected item. var selectedRows = h.Control.SelectedRows.ToArray(); for (var i = 0; i < selectedRows.Length; i++) { if (!dragRows.Contains((int)selectedRows[i])) { isDifferentSelection = true; break; } } } if (isDifferentSelection) { h.CustomSelectedRows = dragRows; h.Callback.OnSelectionChanged(h.Widget, EventArgs.Empty); } var args = MacConversions.GetMouseEvent(h, NSApplication.SharedApplication.CurrentEvent, false); h.Callback.OnMouseMove(h.Widget, args); h.DragPasteboard = null; return(h.DragInfo != null); } return(false); }
public static string[] GetReadableTypesForPasteboard(NSPasteboard pasteboard) { string[] readableTypes = { "com.xamarin.image-info", "public.text" }; return(readableTypes); }
public bool ReadFromPasteboard(NSPasteboard pb) { string pbString = pb.GetStringForType(pboardTypes[0]); if (pbString != null) { // Read the string from the pasteboard // Our view can only handle one letter Letter = pbString.GetFirstLetter(); return true; } return false; }
public virtual void WriteSelection(NSObject[] types, NSPasteboard pasteboard);
public override void UIWillPerformDragSource(WebView webView, WebDragSourceAction action, PointF sourcePoint, NSPasteboard pasteboard);
public override void FinishedWithDataProvider(NSPasteboard pasteboard) { }
public override NSPasteboardReadingOptions GetReadingOptionsForType (string type, NSPasteboard pasteboard) { if (type == _pasteboardItemName) return NSPasteboardReadingOptions.AsKeyedArchive; else return 0; }
public override string[] GetReadableTypesForPasteboard (NSPasteboard pasteboard) { return new string[] { _pasteboardItemName }; }
public NSPasteboardWritingOptions GetWritingOptionsForType (string type, NSPasteboard pasteboard) { return 0; }
public string[] GetWritableTypesForPasteboard (NSPasteboard pasteboard) { return new string[] { _pasteboardItemName }; }
public DraggableData(NSPasteboard aPasteboard) { iPasteboard = aPasteboard; }
/// <summary> /// Reads the selection from pasteboard. /// </summary> /// <returns><c>true</c>, if the selection was read from the pasteboard, <c>false</c> otherwise.</returns> /// <param name="pboard">The pasteboard being read.</param> /// <param name="type">The type of data being read from the pasteboard.</param> /// <remarks>This method is overridden to update the formatting after the user pastes text /// into the view.</remarks> public override bool ReadSelectionFromPasteboard (NSPasteboard pboard, string type) { // Console.WriteLine ("Read selection from pasteboard also"); var result = base.ReadSelectionFromPasteboard (pboard, type); if (Formatter !=null) Formatter.Reformat (); return result; }
public override bool OutlineViewwriteItemstoPasteboard(NSOutlineView outlineView, NSArray items, NSPasteboard pboard) { return(false); }
private static DataPackageView GetFromNative(NSPasteboard pasteboard) { if (pasteboard is null) { throw new ArgumentException(nameof(pasteboard)); } var dataPackage = new DataPackage(); // Extract all the standard data format information from the pasteboard items. // Each format can only be used once; therefore, generally the last occurrence of the format will be the one used. foreach (NSPasteboardItem item in pasteboard.PasteboardItems) { if (item.Types.Contains(NSPasteboard.NSPasteboardTypeTIFF) || item.Types.Contains(NSPasteboard.NSPasteboardTypePNG)) { // Images may be very large, we never want to load them until they are needed. // Therefore, create a data provider used to asynchronously fetch the image. dataPackage.SetDataProvider( StandardDataFormats.Bitmap, async cancellationToken => { NSImage?image = null; /* Some apps, including Photos, don't appear to put image data in the pasteboard. * Instead, the image URL is provided although the type indicates it is an image. * * To get around this an image is read as follows: * (1) If the pasteboard contains an image type then: * (2) Attempt to read the image as an object (NSImage). * This may fail as some tested apps provide a URL although declare an image (Photos). * With other apps (such as web browsers) an image will be read correctly here. * (3) If reading as an NSImage object fails, attempt to read the image from a file URL (local images) * (4) If reading from a file URL fails, attempt to read the image from a URL (remote images) * * Reading as an NSImage object follows the docs here: * https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/copy-paste#add-an-nsdocument */ var classArray = new Class[] { new Class("NSImage") }; if (pasteboard.CanReadObjectForClasses(classArray, null)) { NSObject[] objects = pasteboard.ReadObjectsForClasses(classArray, null); if (objects.Length > 0) { // Only use the first image found image = objects[0] as NSImage; } } // In order to get here the pasteboard must have declared it had image types. // However, if image is null, no objects were found and the image is likely a URL instead. if (image == null && item.Types.Contains(NSPasteboard.NSPasteboardTypeFileUrl)) { var url = item.GetStringForType(NSPasteboard.NSPasteboardTypeFileUrl); image = new NSImage(new NSUrl(url)); } if (image == null && item.Types.Contains(NSPasteboard.NSPasteboardTypeUrl)) { var url = item.GetStringForType(NSPasteboard.NSPasteboardTypeUrl); image = new NSImage(new NSUrl(url)); } if (image != null) { // Thanks to: https://stackoverflow.com/questions/13305028/monomac-best-way-to-convert-bitmap-to-nsimage/13355747 using (var imageData = image.AsTiff()) { var imgRep = NSBitmapImageRep.ImageRepFromData(imageData !) as NSBitmapImageRep; var data = imgRep !.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png, null); return(new RandomAccessStreamReference(async ct => { return data.AsStream().AsRandomAccessStream().TrySetContentType("image/png"); })); } } else { // Return an empty image return(new RandomAccessStreamReference(async ct => { var stream = new MemoryStream(); stream.Position = 0; return stream.AsRandomAccessStream().TrySetContentType("image/png"); })); } }); } if (item.Types.Contains(NSPasteboard.NSPasteboardTypeHTML)) { var html = item.GetStringForType(NSPasteboard.NSPasteboardTypeHTML); if (html != null) { dataPackage.SetHtmlFormat(html); } } if (item.Types.Contains(NSPasteboard.NSPasteboardTypeRTF)) { var rtf = item.GetStringForType(NSPasteboard.NSPasteboardTypeRTF); if (rtf != null) { dataPackage.SetRtf(rtf); } } if (item.Types.Contains(NSPasteboard.NSPasteboardTypeFileUrl)) { // Drag and drop will use temporary URLs similar to: file:///.file/id=1234567.1234567 var tempFileUrl = item.GetStringForType(NSPasteboard.NSPasteboardTypeFileUrl); // Files may be very large, we never want to load them until they are needed. // Therefore, create a data provider used to asynchronously fetch the file. dataPackage.SetDataProvider( StandardDataFormats.StorageItems, async cancellationToken => { // Convert from a temp Url (see above example) into an absolute file path var fileUrl = new NSUrl(tempFileUrl); var file = await StorageFile.GetFileFromPathAsync(fileUrl.FilePathUrl.AbsoluteString); var storageItems = new List <IStorageItem>(); storageItems.Add(file); return(storageItems.AsReadOnly()); }); } if (item.Types.Contains(NSPasteboard.NSPasteboardTypeString)) { var text = item.GetStringForType(NSPasteboard.NSPasteboardTypeString); if (text != null) { dataPackage.SetText(text); } } if (item.Types.Contains(NSPasteboard.NSPasteboardTypeUrl)) { var url = item.GetStringForType(NSPasteboard.NSPasteboardTypeUrl); if (url != null) { DataPackage.SeparateUri( url, out string?webLink, out string?applicationLink); if (webLink != null) { dataPackage.SetWebLink(new Uri(webLink)); } if (applicationLink != null) { dataPackage.SetApplicationLink(new Uri(applicationLink)); } // Deprecated but still added for compatibility dataPackage.SetUri(new Uri(url)); } } } return(dataPackage.GetView()); }
/// <summary> /// Gets the clipboard. /// </summary> /// <returns>The clipboard.</returns> public static string GetClipboard() { NSPasteboard pasteBoard = NSPasteboard.GeneralPasteboard; return(pasteBoard.PasteboardItems [0].GetStringForType("public.utf8-plain-text")); }
public static string UrlTitleFromPasteboard(NSPasteboard pasteboard);
partial void Copy(Foundation.NSObject sender) { NSPasteboard pb = NSPasteboard.GeneralPasteboard; WriteToPasteBoard(pb); }
internal Bitmap GetBitmap(NSPasteboard pboard) { return(new NSImage(pboard).ToBitmap()); }
public abstract void Apply(NSPasteboard pasteboard, string type);
public override string[] GetWritableTypesForPasteboard(NSPasteboard pasteboard) { return(new string [] {}); }
public override void Apply(NSPasteboard pasteboard, string type) => pasteboard.SetDataForType(Value, type);
public virtual string[] GetWritableTypesForPasteboard(NSPasteboard pasteboard) { string[] writableTypes = { "com.xamarin.image-info", "public.text" }; return(writableTypes); }
public override void Apply(NSPasteboard pasteboard, string type) => pasteboard.SetPropertyListForType(Value, type);
public static NSPasteboardReadingOptions GetReadingOptionsForType(string type, NSPasteboard pasteboard) { // Take action based on the requested type switch (type) { case "com.xamarin.image-info": return(NSPasteboardReadingOptions.AsKeyedArchive); case "public.text": return(NSPasteboardReadingOptions.AsString); } // Default to property list return(NSPasteboardReadingOptions.AsPropertyList); }
public bool TableViewWriteRowsWithIndexesToPasteboard(NSTableView aTableView, NSIndexSet rowIndexes, NSPasteboard pboard) { throw new NotImplementedException (); }
public static void WriteObject(this NSPasteboard pboard, INSPasteboardWriting pasteboardWriting) { pboard.WriteObjects(new INSPasteboardWriting[] { pasteboardWriting }); }
public static DataObject ToEto(this NSPasteboard pasteboard) => new DataObject(new DataObjectHandler(pasteboard));
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 override void FinishedWithDataProvider (NSPasteboard pasteboard) { }
private static async Task SetToNativeAsync(DataPackage content, NSPasteboard pasteboard) { if (pasteboard is null) { throw new ArgumentException(nameof(pasteboard)); } var data = content?.GetView(); var declaredTypes = new List <string>(); string?uri = null; /* Note that order is somewhat important here. * * According to the docs: * "types should be ordered according to the preference of the source application, * with the most preferred type coming first" * https://developer.apple.com/documentation/appkit/nspasteboard/1533561-declaretypes?language=objc * * This means we want to process certain types like HTML/RTF before general plain text * as they are more specific. * * Types are also declared before setting */ // Declare types if (data?.Contains(StandardDataFormats.Html) ?? false) { declaredTypes.Add(NSPasteboard.NSPasteboardTypeHTML); } if (data?.Contains(StandardDataFormats.Rtf) ?? false) { // Use `NSPasteboardTypeRTF` instead of `NSPasteboardTypeRTFD` for max compatibility declaredTypes.Add(NSPasteboard.NSPasteboardTypeRTF); } if (data?.Contains(StandardDataFormats.Text) ?? false) { declaredTypes.Add(NSPasteboard.NSPasteboardTypeString); } if (data != null) { uri = DataPackage.CombineUri( data.Contains(StandardDataFormats.WebLink) ? (await data.GetWebLinkAsync()).ToString() : null, data.Contains(StandardDataFormats.ApplicationLink) ? (await data.GetApplicationLinkAsync()).ToString() : null, data.Contains(StandardDataFormats.Uri) ? (await data.GetUriAsync()).ToString() : null); if (string.IsNullOrEmpty(uri) == false) { declaredTypes.Add(NSPasteboard.NSPasteboardTypeUrl); } } pasteboard.DeclareTypes(declaredTypes.ToArray(), null); // Set content if (data?.Contains(StandardDataFormats.Html) ?? false) { var html = await data.GetHtmlFormatAsync(); pasteboard.SetStringForType(html ?? string.Empty, NSPasteboard.NSPasteboardTypeHTML); } if (data?.Contains(StandardDataFormats.Rtf) ?? false) { var rtf = await data.GetRtfAsync(); pasteboard.SetStringForType(rtf ?? string.Empty, NSPasteboard.NSPasteboardTypeRTF); } if (data?.Contains(StandardDataFormats.Text) ?? false) { var text = await data.GetTextAsync(); pasteboard.SetStringForType(text ?? string.Empty, NSPasteboard.NSPasteboardTypeString); } if (string.IsNullOrEmpty(uri) == false) { pasteboard.SetStringForType(uri !.ToString(), NSPasteboard.NSPasteboardTypeUrl); } return; }
public virtual void WriteToPasteboard(NSPasteboard pasteBoard) { //NSData colorData = [NSArchiver archivedDataWithRootObject: self]; //if (colorData != null) // [pasteBoard setData: colorData forType: NSColorPboardType]; }
public void PasteboardProvideDataForType(NSPasteboard sender, NSString type) { // Sender has accepted the drag and now we need to send the data for the type we promised if (type.Compare(NSPasteboard.NSTIFFPboardType) == NSComparisonResult.NSOrderedSame) { sender.SetDataForType(this.Image.TIFFRepresentation, NSPasteboard.NSTIFFPboardType); } else if (type.Compare(NSPasteboard.NSPDFPboardType) == NSComparisonResult.NSOrderedSame) { sender.SetDataForType(this.DataWithPDFInsideRect(this.Bounds), NSPasteboard.NSPDFPboardType); } }
public virtual string[] GetWritableTypesForPasteboard (NSPasteboard pasteboard) { string[] writableTypes = {"com.xamarin.image-info", "public.text"}; return writableTypes; }
public static NSUrl UrlFromPasteboard(NSPasteboard pasteboard);
public static string[] GetReadableTypesForPasteboard (NSPasteboard pasteboard) { string[] readableTypes = {"com.xamarin.image-info", "public.text"}; return readableTypes; }
public virtual void WriteElement(NSDictionary element, NSObject[] pasteboardTypes, NSPasteboard toPasteboard);
static string[] GetItemsForType(NSPasteboard pboard, NSString type) { var items = NSArray.FromArray<NSString>(((NSArray)pboard.GetPropertyListForType(type.ToString()))); return items.Select(i => i.ToString()).ToArray(); }
public override NSPasteboardWritingOptions GetWritingOptionsForType(string type, NSPasteboard pasteboard) { return(NSPasteboardWritingOptions.WritingPromised); }
internal void FinishedWithDataProvider(NSPasteboard pasteboard) { //dndFileProvider = null; //dndFilenames = null; }
public DataObjectPasteboard(NSPasteboard pboard) { this.pboard = pboard; }
public override void FinishedWithDataProvider(NSPasteboard pasteboard) { //Console.WriteLine("FileProvider.FinishedWithDataProvider"); driver.FinishedWithDataProvider(pasteboard); }
public void WriteToPasteBoard(NSPasteboard pb) { // Copy data to the pasteboard pb.ClearContents(); pb.DeclareTypes(pboardTypes, null); pb.SetStringForType(mLetter, pboardTypes[0]); CGRect r = this.Bounds; NSData data = this.DataWithPdfInsideRect(r); pb.SetDataForType(data, pboardTypes[1]); }
public override void ProvideDataForType(NSPasteboard pasteboard, NSPasteboardItem item, string type) { driver.ProvideDataForType(pasteboard, item, type); driver.dndCurrentFileIndex += 1; }
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 bool WriteRowsWithIndexesToPasteboard(NSTableView tableView, NSIndexSet rowIndexes, NSPasteboard pboard) { //Console.WriteLine(">>> WriteRowsWithIndexesToPasteboard"); string dataType = string.Empty; if (tableView == tableSegments) dataType = "Segment"; else if (tableView == tableMarkers) dataType = "Marker"; pboard.DeclareTypes(new string[1] { dataType }, this); byte index = (byte)rowIndexes.Last(); var data = NSData.FromArray(new byte[1] { index }); pboard.SetDataForType(data, dataType); return true; }