| 115 | } |
| 116 | |
| 117 | std::string Clipboard::getString() |
| 118 | { |
| 119 | #if defined( CINDER_MAC ) |
| 120 | NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
| 121 | NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; |
| 122 | NSDictionary *options = [NSDictionary dictionary]; |
| 123 | |
| 124 | if( [pasteboard canReadObjectForClasses:classArray options:options] ) { |
| 125 | NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options]; |
| 126 | NSString *text = [objectsToPaste firstObject]; |
| 127 | if( ! text ) |
| 128 | return std::string(); |
| 129 | else |
| 130 | return cocoa::convertNsString( text ); |
| 131 | } |
| 132 | else { |
| 133 | return std::string(); |
| 134 | } |
| 135 | #elif defined( CINDER_COCOA_TOUCH ) |
| 136 | UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; |
| 137 | NSString *str = pasteboard.string; |
| 138 | if( str ) |
| 139 | return cocoa::convertNsString( str ); |
| 140 | else |
| 141 | return std::string(); |
| 142 | #elif defined( CINDER_MSW ) |
| 143 | std::string result; |
| 144 | if( ! ::OpenClipboard( NULL ) ) |
| 145 | return result; |
| 146 | HANDLE dataH = ::GetClipboardData( CF_UNICODETEXT ); |
| 147 | if( dataH ) { |
| 148 | wchar_t *pstr = reinterpret_cast<wchar_t*>( ::GlobalLock( dataH ) ); |
| 149 | if( pstr ) { |
| 150 | std::wstring wstr( pstr ); |
| 151 | result = toUtf8( (char16_t*)wstr.c_str() ); |
| 152 | ::GlobalUnlock( dataH ); |
| 153 | } |
| 154 | } |
| 155 | ::CloseClipboard(); |
| 156 | return result; |
| 157 | #elif defined( CINDER_LINUX ) |
| 158 | return std::string( glfwGetClipboardString( (GLFWwindow*)app::getWindow()->getNative() ) ); |
| 159 | #endif |
| 160 | } |
| 161 | |
| 162 | ImageSourceRef Clipboard::getImage() |
| 163 | { |
no test coverage detected