mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 10:49:53 +02:00
Fix Mac OSX readUserPreferences missing off last char of pref data, add clipboard implementations for Mac OS X
This commit is contained in:
34
SDLMain.m
34
SDLMain.m
@@ -360,11 +360,13 @@ char * readUserPreferences() {
|
|||||||
prefData = "";
|
prefData = "";
|
||||||
|
|
||||||
char *prefDataCopy = calloc([prefDataNSString length]+1, 1);
|
char *prefDataCopy = calloc([prefDataNSString length]+1, 1);
|
||||||
SDL_strlcpy(prefDataCopy, prefData, [prefDataNSString length]);
|
SDL_strlcpy(prefDataCopy, prefData, [prefDataNSString length]+1);
|
||||||
|
|
||||||
[prefDataNSString release];
|
[prefDataNSString release];
|
||||||
[prefs release];
|
[prefs release];
|
||||||
|
|
||||||
|
puts(prefDataCopy);
|
||||||
|
|
||||||
return prefDataCopy;
|
return prefDataCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +381,36 @@ void writeUserPreferences(const char * prefData) {
|
|||||||
[prefs release];
|
[prefs release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char * readClipboard() {
|
||||||
|
NSPasteboard *clipboard = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
|
NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil];
|
||||||
|
NSDictionary *options = [NSDictionary dictionary];
|
||||||
|
NSArray *clipboardItems = [clipboard readObjectsForClasses:classes options:options];
|
||||||
|
|
||||||
|
if(clipboardItems == nil || [clipboardItems count] == 0) return NULL;
|
||||||
|
|
||||||
|
NSString *newString = [clipboardItems objectAtIndex:0];
|
||||||
|
const char * clipboardData = [newString UTF8String];
|
||||||
|
if(clipboardData == NULL)
|
||||||
|
clipboardData = "";
|
||||||
|
|
||||||
|
char *clipboardDataCopy = calloc([newString length]+1, 1);
|
||||||
|
SDL_strlcpy(clipboardDataCopy, clipboardData, [newString length]+1);
|
||||||
|
|
||||||
|
return clipboardDataCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeClipboard(const char * clipboardData) {
|
||||||
|
NSPasteboard *clipboard = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
|
NSString *newString = [NSString stringWithUTF8String: clipboardData];
|
||||||
|
|
||||||
|
[clipboard clearContents];
|
||||||
|
[clipboard setString:newString forType:NSStringPboardType];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef main
|
#ifdef main
|
||||||
# undef main
|
# undef main
|
||||||
|
@@ -24,6 +24,10 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
extern "C" {
|
||||||
|
char * readClipboard();
|
||||||
|
void writeClipboard(const char * clipboardData);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
@@ -69,14 +73,7 @@ void ClipboardPush(char * text)
|
|||||||
}
|
}
|
||||||
clipboardText = mystrdup(text);
|
clipboardText = mystrdup(text);
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
PasteboardRef newclipboard;
|
writeClipboard(text);
|
||||||
|
|
||||||
if (PasteboardCreate(kPasteboardClipboard, &newclipboard)!=noErr) return;
|
|
||||||
if (PasteboardClear(newclipboard)!=noErr) return;
|
|
||||||
PasteboardSynchronize(newclipboard);
|
|
||||||
|
|
||||||
CFDataRef data = CFDataCreate(kCFAllocatorDefault, (const UInt8*)text, strlen(text));
|
|
||||||
PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0);
|
|
||||||
#elif defined(WIN)
|
#elif defined(WIN)
|
||||||
if (OpenClipboard(NULL))
|
if (OpenClipboard(NULL))
|
||||||
{
|
{
|
||||||
@@ -109,7 +106,9 @@ void EventProcess(SDL_Event event);
|
|||||||
char * ClipboardPull()
|
char * ClipboardPull()
|
||||||
{
|
{
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
printf("Not implemented: get text from clipboard\n");
|
char * data = readClipboard();
|
||||||
|
if(!data) return mystrdup("");
|
||||||
|
return mystrdup(data);
|
||||||
#elif defined(WIN)
|
#elif defined(WIN)
|
||||||
if (OpenClipboard(NULL))
|
if (OpenClipboard(NULL))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user