Skip to content
Snippets Groups Projects
Commit 598dfba9 authored by deuce's avatar deuce
Browse files

Add OS X copy/paste support (10.6+ apparently) to the SDL console.

Thanks to Larry Lagomorph for the use of his Mac for this effort!
parent 8fe244a4
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ endif
ifdef WITH_SDL_AUDIO
OBJS += $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)pasteboard$(OFILE)
NEED_BITMAP := 1
else
ifdef WITH_SDL
......@@ -29,6 +30,7 @@ else
OBJS += $(MTOBJODIR)$(DIRSEP)sdlfuncs$(OFILE)
ifeq ($(os),darwin)
OBJS += $(MTOBJODIR)$(DIRSEP)SDLMain$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)pasteboard$(OFILE)
endif
endif
endif
......@@ -57,6 +59,10 @@ ifeq ($(os),darwin)
$(MTOBJODIR)$(DIRSEP)SDLMain$(OFILE): SDLMain.m
@echo $(COMPILE_MSG) $<
$(QUIET)$(CC) $(CFLAGS) $(CCFLAGS) -o $@ -c $<
$(MTOBJODIR)$(DIRSEP)pasteboard$(OFILE): pasteboard.m
@echo $(COMPILE_MSG) $<
$(QUIET)$(CC) $(CFLAGS) $(CCFLAGS) -o $@ -c $<
endif
ifeq ($(os),win32)
......
#ifndef _PASTEBOARD_H_
#define _PASTEBOARD_H_
void OSX_copytext(const char *text);
char *OSX_getcliptext(void);
#endif
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include <stddef.h>
void OSX_copytext(const char *text)
{
NSString *cp = [NSString stringWithCString:text encoding:NSUTF8StringEncoding];
if (cp != nil) {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
NSArray *copiedObjects = [NSArray arrayWithObject:cp];
[pasteboard writeObjects:copiedObjects];
}
}
char *OSX_getcliptext(void)
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
if (ok) {
NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
NSString *ct = [objectsToPaste objectAtIndex:0];
if (ct != nil) {
const char *ptr = [ct cStringUsingEncoding:NSASCIIStringEncoding];
if (ptr)
return strdup(ptr);
}
}
return NULL;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment