Implemented the OSX clipboard using the AppKit API

The X11 dependency is no longer needed on OSX, and has been removed
master
MBlanc 2014-12-09 14:50:06 +01:00
parent f30592bf56
commit 7bb12511d9
4 changed files with 29 additions and 6 deletions

View File

@ -256,12 +256,8 @@ include("${colobot_SOURCE_DIR}/cmake/msys.cmake")
##
# Clipboard support needs X11 libraries
##
if(PLATFORM_GNU OR PLATFORM_MACOSX)
if(PLATFORM_GNU)
find_package(X11 REQUIRED)
if(PLATFORM_MACOSX)
# Add the includes for X11
include_directories("/opt/X11/include")
endif()
endif()

View File

@ -7,6 +7,9 @@ add_definitions(-DLIB_COMPILE=1)
if(PLATFORM_WINDOWS)
set(CLIPBOARD_SRC src/clipboardWin32.c)
elseif(PLATFORM_MACOSX)
set(CMAKE_CXX_FLAGS "-fobjc-arc")
set(CLIPBOARD_SRC src/clipboardOSX.m)
else()
set(CLIPBOARD_SRC src/clipboardX11.c)
endif()

View File

@ -0,0 +1,24 @@
#include <stdbool.h>
#include <string.h>
#include <AppKit/AppKit.h>
char *widgetGetClipboardText()
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSString *myString = [pasteboard stringForType:NSPasteboardTypeString];
if (myString == nil || [myString length] == 0) return NULL;
return strdup([myString UTF8String]);
}
bool widgetSetClipboardText(const char *text)
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
NSString *stringFromUTFString = [[NSString alloc] initWithUTF8String:text];
return [pasteboard setString:stringFromUTFString forType:NSStringPboardType];
}

View File

@ -35,7 +35,7 @@ elseif(PLATFORM_LINUX)
set(PLATFORM_LIBS "-lrt -lX11")
elseif(PLATFORM_MACOSX)
find_library(LIBINTL_LIBRARY NAMES intl libintl )
set(PLATFORM_LIBS ${LIBINTL_LIBRARY} ${X11_X11_LIB})
set(PLATFORM_LIBS ${LIBINTL_LIBRARY})
endif()