[Mono-osx] NSPasteboardItemDataProvider

Jon Lipsky jon.lipsky at elevenworks.com
Tue Jan 17 17:40:09 UTC 2012

Hi All,

Has anyone been able to successfully use NSPasteboardItemDataProvider within MonoMac?

Here is snippet that shows (a stripped down version) what I'm trying to do:

var item = new NSPasteboardItem();
var provider = new TDMMImageProvider();
item.SetDataProviderForTypes(provider,new string[] { "public.png" });

Here is what TDMMImageProvider looks like (stripped down):

public class TDMMImageProvider : NSPasteboardItemDataProvider
	public override void ProvideDataForType (NSPasteboard pasteboard, NSPasteboardItem item, string type)
		System.Console.WriteLine("TDMMImageProvider.ProvideDataForType(pasteboard:{0}, item:{1}, type:{2})", pasteboard, item, type);
	public override void FinishedWithDataProvider (NSPasteboard pasteboard)
		System.Console.WriteLine("TDMMImageProvider.FinishedWithDataProvider(pasteboard:{0})", pasteboard);

When I execute the above, I see the following output in the console:
2012-01-17 09:25:17.077 TouchDrawForMac[14757:1007] Pasteboard item data provider <Elevenworks.TouchDraw.Clipboard.TDMMImageProvider: 0x1e3b740> must conform to NSPasteboardItemDataProviderProtocol

I have looked at the definition for "NSPasteboardItemDataProvider" in the MonoMac source code and it appears to be mapped correctly, so I'm not sure why I'm getting this message.  I've also tried changing the class above to extend from NSObject, and then added the [Export] annotations myself; however I got the same result.

Also, it appears to me that the "NSPasteboard.WriteObjects" method should be accepting arguments of type "NSObject[]" instead of "NSPasteboardReading[]" so that you can send it instances of "NSPasteboardItem" (which implement the NSPasteboardReading and NSPasteboardWriting protocol in the underlying obj-c classes.)

In the meantime, I'm working around this by using a "Messaging.void_objc_msgSend_intptr" call; however it appears to me this method signature should be changed/updated.

Thanks for any insight anyone can give.

Best Regards,

More information about the Mono-osx mailing list