From 5106a12702fcd5a480ef167d4a2236620a34a702 Mon Sep 17 00:00:00 2001 From: sfb Date: Wed, 7 Dec 2011 07:20:05 -0600 Subject: [PATCH] Fixed: #1359 Applied patch from GelluleX adding cut/paste functionality to Ryzom for OSX. --- .../driver/opengl/mac/cocoa_event_emitter.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp b/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp index 95c713021..15bb40d28 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp @@ -149,14 +149,28 @@ static NLMISC::TKey virtualKeycodeToNelKey(unsigned short keycode) bool CCocoaEventEmitter::pasteTextFromClipboard(ucstring &text) { -#warning "OpenGL Driver: Missing Mac Implementation for pasteTextFromClipboard" + 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 *nstext = [objectsToPaste objectAtIndex:0]; + text.fromUtf8([nstext UTF8String]); + return true; + } return false; } bool CCocoaEventEmitter::copyTextToClipboard(const ucstring &text) { -#warning "OpenGL Driver: Missing Mac Implementation for copyTextToClipboard" - return false; + NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; + [pasteboard clearContents]; + NSArray *copiedObjects = [NSArray arrayWithObject:[NSString stringWithUTF8String:text.toUtf8().c_str()]]; + [pasteboard writeObjects:copiedObjects]; + return true; } /// convert modifier key state to nel internal modifier key state