Index: source/blender/src/drawtext.c =================================================================== --- source/blender/src/drawtext.c (revision 13438) +++ source/blender/src/drawtext.c (working copy) @@ -39,6 +39,17 @@ #include #endif +/* Include Pasteboard from carbon +* Carbon Pastboard supports cocoa +* OS X 10.3 and later +*/ + +#ifdef __APPLE__ + +#include +#include +#endif + #ifndef _WIN32 #include #else @@ -101,6 +112,10 @@ static int check_builtinfuncs(char *string); static int check_specialvars(char *string); +#ifdef __APPLE__ +void pasteboard_Check_Error(OSStatus err); +#endif + static void *last_txt_find_string= NULL; static BMF_Font *spacetext_get_font(SpaceText *st) { @@ -1315,6 +1330,7 @@ *p2= 0; return(output); } +#endif static char *winNewLine(char *buffer) { @@ -1335,9 +1351,7 @@ return(output); } -#endif - void txt_paste_clipboard(Text *text) { #ifdef _WIN32 char * buffer = NULL; @@ -1354,6 +1368,47 @@ MEM_freeN(buffer); } #endif +#ifdef __APPLE__ + PasteboardRef inPasteboard; + PasteboardItemID itemID; + CFDataRef flavorData; + OSStatus err = noErr; + char * buffer = NULL; + char * temp_buff = NULL; + CFRange range; + + err = PasteboardCreate(kPasteboardClipboard, &inPasteboard); + pasteboard_Check_Error(err); + + err = PasteboardSynchronize( inPasteboard ); + pasteboard_Check_Error(err); + + err = PasteboardGetItemIdentifier( inPasteboard, 1, &itemID ); + pasteboard_Check_Error(err); + + err = PasteboardCopyItemFlavorData( inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData); + pasteboard_Check_Error(err); + + range = CFRangeMake(0, CFDataGetLength(flavorData)); + + temp_buff = MEM_mallocN(range.length, "PasteBoard Data"); + + CFDataGetBytes(flavorData, range, (UInt8*)temp_buff); + + temp_buff[range.length] = '\0'; + + buffer = winNewLine(temp_buff); + + txt_insert_buf(text, buffer); + + if(buffer) { + MEM_freeN(buffer); + } + if(temp_buff) { + MEM_freeN(temp_buff); + } + CFRelease(flavorData); +#endif } void txt_copy_clipboard(Text *text) { @@ -1384,8 +1439,69 @@ copybuffer= NULL; } #endif +#ifdef __APPLE__ + PasteboardRef inPasteboard; + CFDataRef textData = NULL; + OSStatus err = noErr; /*For error checking*/ + + txt_copy_selectbuffer(text); + + err = PasteboardCreate(kPasteboardClipboard, &inPasteboard); + + pasteboard_Check_Error(err); + + err = PasteboardSynchronize( inPasteboard ); + + pasteboard_Check_Error(err); + + err = PasteboardClear( inPasteboard ); + + pasteboard_Check_Error(err); + + textData = CFDataCreate(kCFAllocatorDefault, (UInt8*)copybuffer, strlen(copybuffer)); + + if (textData) { + err = PasteboardPutItemFlavor( inPasteboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), textData, 0); + pasteboard_Check_Error(err); + } + + if(copybuffer) { + MEM_freeN(copybuffer); + copybuffer = NULL; + } + CFRelease(textData); +#endif } +#ifdef __APPLE__ +void pasteboard_Check_Error(OSStatus err) +{ + switch(err) { + case badPasteboardSyncErr: + printf("The pasteboard has been modified and must be synchronized before use.\n"); + break; + case badPasteboardIndexErr: + printf("The specified pasteboard item index does not exist.\n"); + break; + case badPasteboardItemErr: + printf("The item reference does not exist.\n"); + break; + case badPasteboardFlavorErr: + printf("The item flavor does not exist.\n"); + break; + case duplicatePasteboardFlavorErr: + printf("The item flavor already exists.\n"); + break; + case notPasteboardOwnerErr: + printf("The application did not clear the pasteboard before attempting to add flavor data.\n"); + break; + case noPasteboardPromiseKeeperErr: + printf("The application attempted to add promised data without previously registering a promise keeper callback.\n"); + break; + } +} +#endif + /* * again==0 show find panel or find * again==1 find text again */ Index: source/blender/src/SConscript =================================================================== --- source/blender/src/SConscript (revision 13438) +++ source/blender/src/SConscript (working copy) @@ -28,7 +28,14 @@ incs += ' ../quicktime #/intern/elbeem/extern' incs += ' #/intern/ghost #/intern/opennl/extern' +# If this fails then check the location Apple may have moved it on us +# We can not include the base framework in Draw.txt to use the pasteboard +# If you try you get conflicting types with ID +# This has forced me to only include the header like so +#if(env['OURPLATFORM'] == 'darwin'): +incs += ' /System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers' + incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_SDL_INC'] incs += ' ' + env['BF_OPENGL_INC']