First working attempt at accessing the MacOS pasteboard/clipboard for cut and paste operations...
// pasteboard the mac version of clipboard - aim same interface different OS!
#include <AppKit/AppKit.h>
#include <AppKit/NSPasteboard.h>
#include <brl.mod/blitz.mod/blitz.h>
BBString* bbStringFromNSString(NSString *s)
{
BBString *bbstring;
int n;
n=[s length];
unsigned short *buff;
buff=malloc(n*2);
[s getCharacters:buff];
bbstring=bbStringFromShorts(buff,n);
free(buff);
return bbstring;
}
BBString* readText(void)
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
NSString *text = [pasteBoard stringForType:NSStringPboardType];
BBString *bbText = bbStringFromNSString(text);
return bbText;
}
BOOL writeText(BBString* newString)
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
[pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
return [pasteBoard setString:[NSString stringWithCString:bbStringToCString(newString)] forType:NSStringPboardType];
} pasteboard.m
Rem
Simple test app to get the copy and paste function to work on the mac
End Rem
SuperStrict
?MacOS
Import "-framework WebKit"
Import "../Include/pasteboard.m"
?
Extern
Function readText:String()
Function writeText(text:String)
End Extern
Graphics 600, 400
Global clipboardString:String = "Hello World"
Global getCounter:Int = 0
Global setCounter:Int = 0
Global value:Int = 0
Global cliptext:String = "Testing..."
Global text:String[] = ["Alpha","Bravo","Charlie","Delta"]
While Not AppTerminate()
Cls
If MouseHit(2) Then
clipboardString = getClipboardText()
DebugLog "ClipboardString:"+ clipboardString
EndIf
DrawText "Clipbaord Test App: "+ clipboardString, 10, 10
DrawText "Left Click to copy text to clipboard", 10, 100
DrawText "Right Click to paste text from clipboard", 10, 120
If MouseHit(1) Then
clipboardString = cliptext+text[value]
setClipboardText(clipboardString)
DebugLog "ClipboardString:"+ clipboardString
value:+1
EndIf
If value > 3 Then
value = 0
EndIf
Flip
Wend
Function getClipboardText:String()
Local text:String = readText()
Print "getClipboardText:"+text
Return text
End Function
Function SetClipboardText:Int(txt:String)
Return writeText(txt)
End Function pasteboardText.bmx
EDIT 2 - It work's well kind of the paste gets the last clipping from the clipboard not the current!
|