view dstep/appkit/NSPasteboard.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children b9de51448c6b
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Sep 24, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.appkit.NSPasteboard;

import dstep.appkit.AppKitDefines;
import dstep.appkit.NSFileWrapper;
import dstep.corefoundation.CFBase;
import dstep.foundation.NSArray;
import dstep.foundation.NSData;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSString;
import dstep.foundation.NSURL;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

import bindings = dstep.appkit.NSPasteboard_bindings;

private
{
	NSString NSStringPboardType_;
	NSString NSFilenamesPboardType_;
	NSString NSPostScriptPboardType_;
	NSString NSTIFFPboardType_;
	NSString NSRTFPboardType_;
	NSString NSTabularTextPboardType_;
	NSString NSFontPboardType_;
	NSString NSRulerPboardType_;
	NSString NSFileContentsPboardType_;
	NSString NSColorPboardType_;
	NSString NSRTFDPboardType_;
	NSString NSHTMLPboardType_;
	NSString NSPICTPboardType_;
	NSString NSURLPboardType_;
	NSString NSPDFPboardType_;
	NSString NSVCardPboardType_;
	NSString NSFilesPromisePboardType_;
	NSString NSInkTextPboardType_;
	NSString NSMultipleTextSelectionPboardType_;
	NSString NSGeneralPboard_;
	NSString NSFontPboard_;
	NSString NSRulerPboard_;
	NSString NSFindPboard_;
	NSString NSDragPboard_;
}

NSString NSStringPboardType ()
{
	if (NSStringPboardType_)
		return NSStringPboardType_;

	return NSStringPboardType_ = new NSString(bindings.NSStringPboardType);
}

NSString NSFilenamesPboardType ()
{
	if (NSFilenamesPboardType_)
		return NSFilenamesPboardType_;

	return NSFilenamesPboardType_ = new NSString(bindings.NSFilenamesPboardType);
}

NSString NSPostScriptPboardType ()
{
	if (NSPostScriptPboardType_)
		return NSPostScriptPboardType_;

	return NSPostScriptPboardType_ = new NSString(bindings.NSPostScriptPboardType);
}

NSString NSTIFFPboardType ()
{
	if (NSTIFFPboardType_)
		return NSTIFFPboardType_;

	return NSTIFFPboardType_ = new NSString(bindings.NSTIFFPboardType);
}

NSString NSRTFPboardType ()
{
	if (NSRTFPboardType_)
		return NSRTFPboardType_;

	return NSRTFPboardType_ = new NSString(bindings.NSRTFPboardType);
}

NSString NSTabularTextPboardType ()
{
	if (NSTabularTextPboardType_)
		return NSTabularTextPboardType_;

	return NSTabularTextPboardType_ = new NSString(bindings.NSTabularTextPboardType);
}

NSString NSFontPboardType ()
{
	if (NSFontPboardType_)
		return NSFontPboardType_;

	return NSFontPboardType_ = new NSString(bindings.NSFontPboardType);
}

NSString NSRulerPboardType ()
{
	if (NSRulerPboardType_)
		return NSRulerPboardType_;

	return NSRulerPboardType_ = new NSString(bindings.NSRulerPboardType);
}

NSString NSFileContentsPboardType ()
{
	if (NSFileContentsPboardType_)
		return NSFileContentsPboardType_;

	return NSFileContentsPboardType_ = new NSString(bindings.NSFileContentsPboardType);
}

NSString NSColorPboardType ()
{
	if (NSColorPboardType_)
		return NSColorPboardType_;

	return NSColorPboardType_ = new NSString(bindings.NSColorPboardType);
}

NSString NSRTFDPboardType ()
{
	if (NSRTFDPboardType_)
		return NSRTFDPboardType_;

	return NSRTFDPboardType_ = new NSString(bindings.NSRTFDPboardType);
}

NSString NSHTMLPboardType ()
{
	if (NSHTMLPboardType_)
		return NSHTMLPboardType_;

	return NSHTMLPboardType_ = new NSString(bindings.NSHTMLPboardType);
}

NSString NSPICTPboardType ()
{
	if (NSPICTPboardType_)
		return NSPICTPboardType_;

	return NSPICTPboardType_ = new NSString(bindings.NSPICTPboardType);
}

NSString NSURLPboardType ()
{
	if (NSURLPboardType_)
		return NSURLPboardType_;

	return NSURLPboardType_ = new NSString(bindings.NSURLPboardType);
}

NSString NSPDFPboardType ()
{
	if (NSPDFPboardType_)
		return NSPDFPboardType_;

	return NSPDFPboardType_ = new NSString(bindings.NSPDFPboardType);
}

NSString NSVCardPboardType ()
{
	if (NSVCardPboardType_)
		return NSVCardPboardType_;

	return NSVCardPboardType_ = new NSString(bindings.NSVCardPboardType);
}

NSString NSFilesPromisePboardType ()
{
	if (NSFilesPromisePboardType_)
		return NSFilesPromisePboardType_;

	return NSFilesPromisePboardType_ = new NSString(bindings.NSFilesPromisePboardType);
}

NSString NSInkTextPboardType ()
{
	if (NSInkTextPboardType_)
		return NSInkTextPboardType_;

	return NSInkTextPboardType_ = new NSString(bindings.NSInkTextPboardType);
}

NSString NSMultipleTextSelectionPboardType ()
{
	if (NSMultipleTextSelectionPboardType_)
		return NSMultipleTextSelectionPboardType_;

	return NSMultipleTextSelectionPboardType_ = new NSString(bindings.NSMultipleTextSelectionPboardType);
}

NSString NSGeneralPboard ()
{
	if (NSGeneralPboard_)
		return NSGeneralPboard_;

	return NSGeneralPboard_ = new NSString(bindings.NSGeneralPboard);
}

NSString NSFontPboard ()
{
	if (NSFontPboard_)
		return NSFontPboard_;

	return NSFontPboard_ = new NSString(bindings.NSFontPboard);
}

NSString NSRulerPboard ()
{
	if (NSRulerPboard_)
		return NSRulerPboard_;

	return NSRulerPboard_ = new NSString(bindings.NSRulerPboard);
}

NSString NSFindPboard ()
{
	if (NSFindPboard_)
		return NSFindPboard_;

	return NSFindPboard_ = new NSString(bindings.NSFindPboard);
}

NSString NSDragPboard ()
{
	if (NSDragPboard_)
		return NSDragPboard_;

	return NSDragPboard_ = new NSString(bindings.NSDragPboard);
}

const TNSFileContents = `

	bool writeFileContents (NSString filename)
	{
		return invokeObjcSelf!(bool, "writeFileContents:", NSString)(filename);
	}

	NSString readFileContentsType (NSString type, NSString filename)
	{
		return invokeObjcSelf!(NSString, "readFileContentsType:toFile:", NSString, NSString)(type, filename);
	}

	bool writeFileWrapper (NSFileWrapper wrapper)
	{
		return invokeObjcSelf!(bool, "writeFileWrapper:", NSFileWrapper)(wrapper);
	}

	NSFileWrapper readFileWrapper ()
	{
		return invokeObjcSelf!(NSFileWrapper, "readFileWrapper");
	}

	//mixin ObjcBindMethod!(writeFileContents, "writeFileContents:");
	//mixin ObjcBindMethod!(readFileContentsType, "readFileContentsType:toFile:");
	//mixin ObjcBindMethod!(writeFileWrapper, "writeFileWrapper:");
	//mixin ObjcBindMethod!(readFileWrapper, "readFileWrapper");

`;

const TNSPasteboardSupport = `

	static NSURL URLFromPasteboard (NSPasteboard pasteBoard)
	{
		return invokeObjcSelfClass!(NSURL, "URLFromPasteboard:", NSPasteboard)(pasteBoard);
	}

	void writeToPasteboard (NSPasteboard pasteBoard)
	{
		return invokeObjcSelf!(void, "writeToPasteboard:", NSPasteboard)(pasteBoard);
	}

	//mixin ObjcBindClassMethod!(URLFromPasteboard, "URLFromPasteboard:");
	//mixin ObjcBindMethod!(writeToPasteboard, "writeToPasteboard:");

`;

const TNSPasteboardOwner = `

	void pasteboard (NSPasteboard sender, NSString type)
	{
		return invokeObjcSelf!(void, "pasteboard:provideDataForType:", NSPasteboard, NSString)(sender, type);
	}

	void pasteboardChangedOwner (NSPasteboard sender)
	{
		return invokeObjcSelf!(void, "pasteboardChangedOwner:", NSPasteboard)(sender);
	}

	//mixin ObjcBindMethod!(pasteboard, "pasteboard:provideDataForType:");
	//mixin ObjcBindMethod!(pasteboardChangedOwner, "pasteboardChangedOwner:");

`;

class NSPasteboard : NSObject
{
	mixin (ObjcWrap);

	static NSPasteboard generalPasteboard ()
	{
		return invokeObjcSelfClass!(NSPasteboard, "generalPasteboard");
	}

	static NSPasteboard pasteboardWithName (NSString name)
	{
		return invokeObjcSelfClass!(NSPasteboard, "pasteboardWithName:", NSString)(name);
	}

	static NSPasteboard pasteboardWithUniqueName ()
	{
		return invokeObjcSelfClass!(NSPasteboard, "pasteboardWithUniqueName");
	}

	static NSArray typesFilterableTo (NSString type)
	{
		return invokeObjcSelfClass!(NSArray, "typesFilterableTo:", NSString)(type);
	}

	static NSPasteboard pasteboardByFilteringFile (NSString filename)
	{
		return invokeObjcSelfClass!(NSPasteboard, "pasteboardByFilteringFile:", NSString)(filename);
	}

	static NSPasteboard pasteboardByFilteringData (NSData data, NSString type)
	{
		return invokeObjcSelfClass!(NSPasteboard, "pasteboardByFilteringData:ofType:", NSData, NSString)(data, type);
	}

	static NSPasteboard pasteboardByFilteringTypesInPasteboard (NSPasteboard pboard)
	{
		return invokeObjcSelfClass!(NSPasteboard, "pasteboardByFilteringTypesInPasteboard:", NSPasteboard)(pboard);
	}

	NSString name ()
	{
		return invokeObjcSelf!(NSString, "name");
	}

	void releaseGlobally ()
	{
		return invokeObjcSelf!(void, "releaseGlobally");
	}

	NSInteger declareTypes (NSArray newTypes, Object newOwner)
	{
		return invokeObjcSelf!(NSInteger, "declareTypes:owner:", NSArray, Object)(newTypes, newOwner);
	}

	NSInteger addTypes (NSArray newTypes, Object newOwner)
	{
		return invokeObjcSelf!(NSInteger, "addTypes:owner:", NSArray, Object)(newTypes, newOwner);
	}

	NSInteger changeCount ()
	{
		return invokeObjcSelf!(NSInteger, "changeCount");
	}

	NSArray types ()
	{
		return invokeObjcSelf!(NSArray, "types");
	}

	NSString availableTypeFromArray (NSArray types)
	{
		return invokeObjcSelf!(NSString, "availableTypeFromArray:", NSArray)(types);
	}

	bool setData (NSData data, NSString dataType)
	{
		return invokeObjcSelf!(bool, "setData:forType:", NSData, NSString)(data, dataType);
	}

	NSData dataForType (NSString dataType)
	{
		return invokeObjcSelf!(NSData, "dataForType:", NSString)(dataType);
	}

	bool setPropertyList (Object plist, NSString dataType)
	{
		return invokeObjcSelf!(bool, "setPropertyList:forType:", Object, NSString)(plist, dataType);
	}

	Object propertyListForType (NSString dataType)
	{
		return invokeObjcSelf!(Object, "propertyListForType:", NSString)(dataType);
	}

	bool setString (NSString string, NSString dataType)
	{
		return invokeObjcSelf!(bool, "setString:forType:", NSString, NSString)(string, dataType);
	}

	NSString stringForType (NSString dataType)
	{
		return invokeObjcSelf!(NSString, "stringForType:", NSString)(dataType);
	}
	
	// NSFileContents
	bool writeFileContents (NSString filename)
	{
		return invokeObjcSelf!(bool, "writeFileContents:", NSString)(filename);
	}

	NSString readFileContentsType (NSString type, NSString filename)
	{
		return invokeObjcSelf!(NSString, "readFileContentsType:toFile:", NSString, NSString)(type, filename);
	}

	bool writeFileWrapper (NSFileWrapper wrapper)
	{
		return invokeObjcSelf!(bool, "writeFileWrapper:", NSFileWrapper)(wrapper);
	}

	NSFileWrapper readFileWrapper ()
	{
		return invokeObjcSelf!(NSFileWrapper, "readFileWrapper");
	}
}

NSString NSCreateFilenamePboardType (NSString fileType)
{
	return Bridge.invokeObjcFunction!(NSString, bindings.NSCreateFilenamePboardType, NSString)(fileType);
}

NSString NSCreateFileContentsPboardType (NSString fileType)
{
	return Bridge.invokeObjcFunction!(NSString, bindings.NSCreateFileContentsPboardType, NSString)(fileType);
}

NSString NSGetFileType (NSString pboardType)
{
	return Bridge.invokeObjcFunction!(NSString, bindings.NSGetFileType, NSString)(pboardType);
}

NSArray NSGetFileTypes (NSArray pboardTypes)
{
	return Bridge.invokeObjcFunction!(NSArray, bindings.NSGetFileTypes, NSArray)(pboardTypes);
}