Commit ed763437 authored by mercury233's avatar mercury233

fix mac copy&paste

parent 65663132
.DS_Store
/source/Irrlicht/MacOSX/build
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
extern "C" { extern "C" {
#endif #endif
void OSXCopyToClipboard(const char *text); void OSXCopyToClipboard(const wchar_t *text);
char* OSXCopyFromClipboard(); wchar_t* OSXCopyFromClipboard();
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -3,34 +3,35 @@ ...@@ -3,34 +3,35 @@
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h // For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "irrString.h"
#include "OSXClipboard.h" #include "OSXClipboard.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
void OSXCopyToClipboard(const char *text) void OSXCopyToClipboard(const wchar_t *text)
{ {
NSString *str; NSString *str;
NSPasteboard *board; NSPasteboard *board;
if ((text != NULL) && (strlen(text) > 0)) if ((text != NULL) && (wcslen(text) > 0))
{ {
str = [NSString stringWithCString:text encoding:NSWindowsCP1252StringEncoding]; str = [[NSString alloc] initWithBytes:text length:wcslen(text)*sizeof(*text) encoding:NSUTF32LittleEndianStringEncoding];
board = [NSPasteboard generalPasteboard]; board = [NSPasteboard generalPasteboard];
[board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp]; [board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp];
[board setString:str forType:NSStringPboardType]; [board setString:str forType:NSStringPboardType];
} }
} }
char* OSXCopyFromClipboard() wchar_t* OSXCopyFromClipboard()
{ {
NSString* str; NSString* str;
NSPasteboard* board; NSPasteboard* board;
char* result; wchar_t* result;
result = NULL; result = NULL;
board = [NSPasteboard generalPasteboard]; board = [NSPasteboard generalPasteboard];
str = [board stringForType:NSStringPboardType]; str = [board stringForType:NSStringPboardType];
if (str != nil) if (str != nil)
result = (char*)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding]; result = (wchar_t*)[str cStringUsingEncoding:NSUTF32LittleEndianStringEncoding];
return (result); return (result);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment