Пример #1
0
        internal NSPasteboardItem NewPasteboardItem()
        {
            var item = new NSPasteboardItem();

            item.SetDataForType(new NSData(), IDataObjectPboardType);             // Tells NSMonoView to look for XplatIUCocoa.DraggedData
            return(item);
        }
Пример #2
0
 protected void ProvidePng(NSPasteboard pboard, NSPasteboardItem item, string type)
 {
     if (data.GetData(DataFormats.Bitmap) is Image image)
     {
         item.SetDataForType(image.ToNSData(ImageFormat.Png), Pasteboard.NSPasteboardTypePNG);
     }
 }
Пример #3
0
        protected void ProvideWebArchive(NSPasteboard pboard, NSPasteboardItem item, string type)
        {
            // This method does not seem to work any more. Disabled by not returning appropriate type in Types getter.
            var s = GetHtmlWithoutMetadata();

            if (s == null)
            {
                return;
            }

            var mainRsrc = new NSDictionary
            {
                ["WebResourceData"]             = NSData.FromString(s, NSStringEncoding.UTF8),
                ["WebResourceFrameName"]        = (NSString)"",
                ["WebResourceMIMEType"]         = (NSString)"text/html",
                ["WebResourceTextEncodingName"] = (NSString)"UTF-8",
                ["WebResourceURL"] = (NSString)"about:blank"
            };

            var container = new NSDictionary
            {
                ["WebMainResource"] = mainRsrc
            };

            var nsdata  = NSPropertyListSerialization.DataWithPropertyList(container, NSPropertyListFormat.Xml, out NSError error);
            var archive = NSString.FromData(nsdata, NSStringEncoding.UTF8);

            item.SetDataForType(nsdata, Pasteboard.NSPasteboardTypeWebArchive);
        }
            public override bool WriteRows(NSTableView tableView, NSIndexSet rowIndexes, NSPasteboard pboard)
            {
                var item = new NSPasteboardItem();

                item.SetDataForType(NSKeyedArchiver.ArchivedDataWithRootObject(rowIndexes), DataTypeName);
                pboard.WriteObjects(new[] { item });
                return(true);
            }
Пример #5
0
        protected void ProvideRtf(NSPasteboard pboard, NSPasteboardItem item, string type)
        {
            var s = GetHtmlWithoutMetadata();

            if (s == null)
            {
                return;
            }

            var nsdata  = NSData.FromString(s, NSStringEncoding.UTF8);
            var options = new NSMutableDictionary
            {
                [Pasteboard.NSDocumentTypeDocumentAttribute]      = (NSString)Pasteboard.NSHTMLTextDocumentType,
                [Pasteboard.NSCharacterEncodingDocumentAttribute] = new NSNumber((ulong)NSStringEncoding.UTF8)
            };
            var rtf = new NSAttributedString(nsdata, options, out NSDictionary attributes, out NSError error);

            options[Pasteboard.NSDocumentTypeDocumentAttribute] = (NSString)Pasteboard.NSRTFTextDocumentType;
            nsdata = rtf.GetData(new NSRange(0, rtf.Length), options, out error);
            item.SetDataForType(nsdata, Pasteboard.NSPasteboardTypeRTF);
        }
Пример #6
0
        private NSDraggingItem CreateDraggingItem(string format, object data)
        {
            var    pasteboardItem = new NSPasteboardItem();
            NSData nsData;

            if (data is string s)
            {
                if (format == DataFormats.FileNames)
                {
                    s = new Uri(s).AbsoluteUri; // Ensure file uris...
                }
                nsData = NSData.FromString(s);
            }
            else if (data is Stream strm)
            {
                nsData = NSData.FromStream(strm);
            }
            else if (data is byte[] bytes)
            {
                nsData = NSData.FromArray(bytes);
            }
            else
            {
                BinaryFormatter bf = new BinaryFormatter();
                using (var ms = new MemoryStream())
                {
                    bf.Serialize(ms, data);
                    ms.Position = 0;
                    nsData      = NSData.FromStream(ms);
                }
            }
            pasteboardItem.SetDataForType(nsData, DataFormatToUTI(format));

            NSPasteboardWriting writing = new NSPasteboardWriting(pasteboardItem.Handle);

            return(new NSDraggingItem(writing));
        }
Пример #7
0
 public override void Apply(NSPasteboardItem item, string type) => item.SetDataForType(Value, type);