| 198 | } |
| 199 | |
| 200 | void Clipboard::setString( const std::string &str ) |
| 201 | { |
| 202 | #if defined( CINDER_MAC ) |
| 203 | [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner:nil]; |
| 204 | [[NSPasteboard generalPasteboard] setString:[NSString stringWithUTF8String:str.c_str()] forType: NSStringPboardType]; |
| 205 | #elif defined( CINDER_COCOA_TOUCH ) |
| 206 | UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; |
| 207 | pasteboard.string = [NSString stringWithUTF8String:str.c_str()]; |
| 208 | #elif defined( CINDER_MSW ) |
| 209 | if( ! ::OpenClipboard( NULL ) ) { |
| 210 | CI_LOG_E( "Failed to open clipboard" ); |
| 211 | return; |
| 212 | } |
| 213 | ::EmptyClipboard(); |
| 214 | std::u16string wstr = toUtf16( str ); |
| 215 | HANDLE hglbCopy = ::GlobalAlloc( GMEM_MOVEABLE, sizeof(uint16_t) * (wstr.length()+1) ); |
| 216 | // Lock the handle and copy the text to the buffer. |
| 217 | void *lptstrCopy = ::GlobalLock( hglbCopy ); |
| 218 | memcpy( lptstrCopy, &wstr[0], sizeof(uint16_t) * (wstr.length()+1) ); |
| 219 | ::GlobalUnlock( hglbCopy ); |
| 220 | ::SetClipboardData( CF_UNICODETEXT, hglbCopy ); |
| 221 | ::CloseClipboard(); |
| 222 | #elif defined( CINDER_LINUX ) |
| 223 | glfwSetClipboardString( (GLFWwindow*)app::getWindow()->getNative(), str.c_str() ); |
| 224 | #endif |
| 225 | } |
| 226 | |
| 227 | void Clipboard::setImage( ImageSourceRef imageSource, ImageTarget::Options options ) |
| 228 | { |