diff options
| author | Alan Third | 2021-11-23 20:56:44 +0000 |
|---|---|---|
| committer | Alan Third | 2021-11-24 10:41:25 +0000 |
| commit | 7e3c2b553fede9feeeb755dfeba875fece0c2f63 (patch) | |
| tree | 06202467d734ad6a0de2eb4251969cb5f389db1b /src | |
| parent | e754973d4ddf6925b0289ce1f2cbbf415310a5da (diff) | |
| download | emacs-7e3c2b553fede9feeeb755dfeba875fece0c2f63.tar.gz emacs-7e3c2b553fede9feeeb755dfeba875fece0c2f63.zip | |
Allow NS to handle non-text clipboard contents
* src/nsselect.m (ns_get_foreign_selection): Handle non-plain text
clipboard entries.
(ns_string_from_pasteboard): Remove EOL conversion.
(syms_of_nsselect): Define QTARGETS.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsselect.m | 80 |
1 files changed, 77 insertions, 3 deletions
diff --git a/src/nsselect.m b/src/nsselect.m index 5ab3ef77fec..e999835014d 100644 --- a/src/nsselect.m +++ b/src/nsselect.m | |||
| @@ -215,9 +215,74 @@ ns_get_local_selection (Lisp_Object selection_name, | |||
| 215 | static Lisp_Object | 215 | static Lisp_Object |
| 216 | ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) | 216 | ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) |
| 217 | { | 217 | { |
| 218 | NSDictionary<NSString *, NSString *> *typeLookup; | ||
| 218 | id pb; | 219 | id pb; |
| 219 | pb = ns_symbol_to_pb (symbol); | 220 | pb = ns_symbol_to_pb (symbol); |
| 220 | return pb != nil ? ns_string_from_pasteboard (pb) : Qnil; | 221 | |
| 222 | /* Dictionary for looking up NS types from MIME types, and vice versa. */ | ||
| 223 | typeLookup | ||
| 224 | = [NSDictionary | ||
| 225 | dictionaryWithObjectsAndKeys: | ||
| 226 | @"text/plain", NSPasteboardTypeURL, | ||
| 227 | #if NS_USE_NSPasteboardTypeFileURL | ||
| 228 | @"text/plain", NSPasteboardTypeFileURL, | ||
| 229 | #else | ||
| 230 | @"text/plain", NSFilenamesPboardType, | ||
| 231 | #endif | ||
| 232 | @"text/html", NSPasteboardTypeHTML, | ||
| 233 | @"text/plain", NSPasteboardTypeMultipleTextSelection, | ||
| 234 | @"application/pdf", NSPasteboardTypePDF, | ||
| 235 | @"image/png", NSPasteboardTypePNG, | ||
| 236 | @"application/rtf", NSPasteboardTypeRTF, | ||
| 237 | @"application/rtfd", NSPasteboardTypeRTFD, | ||
| 238 | @"STRING", NSPasteboardTypeString, | ||
| 239 | @"text/plain", NSPasteboardTypeTabularText, | ||
| 240 | @"image/tiff", NSPasteboardTypeTIFF, | ||
| 241 | nil]; | ||
| 242 | |||
| 243 | if (EQ (target, QTARGETS)) | ||
| 244 | { | ||
| 245 | NSMutableArray *types = [NSMutableArray arrayWithCapacity:3]; | ||
| 246 | |||
| 247 | NSString *type; | ||
| 248 | NSEnumerator *e = [[pb types] objectEnumerator]; | ||
| 249 | while (type = [e nextObject]) | ||
| 250 | { | ||
| 251 | NSString *val = [typeLookup valueForKey:type]; | ||
| 252 | if (val && ! [types containsObject:val]) | ||
| 253 | [types addObject:val]; | ||
| 254 | } | ||
| 255 | |||
| 256 | Lisp_Object v = Fmake_vector (make_fixnum ([types count]+1), Qnil); | ||
| 257 | ASET (v, 0, QTARGETS); | ||
| 258 | |||
| 259 | for (int i = 0 ; i < [types count] ; i++) | ||
| 260 | ASET (v, i+1, intern ([[types objectAtIndex:i] UTF8String])); | ||
| 261 | |||
| 262 | return v; | ||
| 263 | } | ||
| 264 | else | ||
| 265 | { | ||
| 266 | NSData *d; | ||
| 267 | NSArray *availableTypes; | ||
| 268 | NSString *result, *t; | ||
| 269 | |||
| 270 | if (!NILP (target)) | ||
| 271 | availableTypes | ||
| 272 | = [typeLookup allKeysForObject: | ||
| 273 | [NSString stringWithLispString:SYMBOL_NAME (target)]]; | ||
| 274 | else | ||
| 275 | availableTypes = @[NSPasteboardTypeString]; | ||
| 276 | |||
| 277 | t = [pb availableTypeFromArray:availableTypes]; | ||
| 278 | |||
| 279 | result = [pb stringForType:t]; | ||
| 280 | if (result) | ||
| 281 | return [result lispString]; | ||
| 282 | |||
| 283 | d = [pb dataForType:t]; | ||
| 284 | return make_string ([d bytes], [d length]); | ||
| 285 | } | ||
| 221 | } | 286 | } |
| 222 | 287 | ||
| 223 | 288 | ||
| @@ -234,8 +299,6 @@ Lisp_Object | |||
| 234 | ns_string_from_pasteboard (id pb) | 299 | ns_string_from_pasteboard (id pb) |
| 235 | { | 300 | { |
| 236 | NSString *type, *str; | 301 | NSString *type, *str; |
| 237 | const char *utfStr; | ||
| 238 | int length; | ||
| 239 | 302 | ||
| 240 | type = [pb availableTypeFromArray: ns_return_types]; | 303 | type = [pb availableTypeFromArray: ns_return_types]; |
| 241 | if (type == nil) | 304 | if (type == nil) |
| @@ -260,6 +323,14 @@ ns_string_from_pasteboard (id pb) | |||
| 260 | } | 323 | } |
| 261 | } | 324 | } |
| 262 | 325 | ||
| 326 | /* FIXME: Is the below EOL conversion even needed? I've removed it | ||
| 327 | for now so we can see if it causes problems. */ | ||
| 328 | return [str lispString]; | ||
| 329 | |||
| 330 | #if 0 | ||
| 331 | const char *utfStr; | ||
| 332 | int length; | ||
| 333 | |||
| 263 | /* assume UTF8 */ | 334 | /* assume UTF8 */ |
| 264 | NS_DURING | 335 | NS_DURING |
| 265 | { | 336 | { |
| @@ -294,6 +365,7 @@ ns_string_from_pasteboard (id pb) | |||
| 294 | NS_ENDHANDLER | 365 | NS_ENDHANDLER |
| 295 | 366 | ||
| 296 | return make_string (utfStr, length); | 367 | return make_string (utfStr, length); |
| 368 | #endif | ||
| 297 | } | 369 | } |
| 298 | 370 | ||
| 299 | 371 | ||
| @@ -491,6 +563,8 @@ syms_of_nsselect (void) | |||
| 491 | DEFSYM (QTEXT, "TEXT"); | 563 | DEFSYM (QTEXT, "TEXT"); |
| 492 | DEFSYM (QFILE_NAME, "FILE_NAME"); | 564 | DEFSYM (QFILE_NAME, "FILE_NAME"); |
| 493 | 565 | ||
| 566 | DEFSYM (QTARGETS, "TARGETS"); | ||
| 567 | |||
| 494 | defsubr (&Sns_disown_selection_internal); | 568 | defsubr (&Sns_disown_selection_internal); |
| 495 | defsubr (&Sns_get_selection); | 569 | defsubr (&Sns_get_selection); |
| 496 | defsubr (&Sns_own_selection_internal); | 570 | defsubr (&Sns_own_selection_internal); |