Changeset 83634 in vbox for trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
- Timestamp:
- Apr 9, 2020 12:30:32 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
r83633 r83634 39 39 * Defined Constants And Macros * 40 40 *********************************************************************************************************************************/ 41 /*#define WITH_HTML_H2G*/ 41 #define WITH_HTML_H2G 1 42 #define WITH_HTML_G2H 1 42 43 43 44 /* For debugging */ … … 533 534 OSStatus orc; 534 535 CFDataRef hData; 535 Log(("writeToPasteboard: fFormat = %02X\n", fFormat));536 Log(("writeToPasteboard: fFormat=%#x\n", fFormat)); 536 537 537 538 /* Make sure all is in sync */ … … 541 542 * Handle the unicode text 542 543 */ 543 /** @todo Figure out the format of kUTTypeHTML. Seems it is neiter UTF-8 or 544 * UTF-16. */ 545 if (fFormat & (VBOX_SHCL_FMT_UNICODETEXT /*| VBOX_SHCL_FMT_HTML*/)) 544 if (fFormat & VBOX_SHCL_FMT_UNICODETEXT) 546 545 { 547 546 PCRTUTF16 const pwszSrc = (PCRTUTF16)pv; … … 575 574 * Create an immutable CFData object that we can place on the clipboard. 576 575 */ 577 rc = VINF_SUCCESS; 578 //if (fFormat & (VBOX_SHCL_FMT_UNICODETEXT | VBOX_SHCL_FMT_HTML)) 579 { 580 hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pwszDst, cwcDst * sizeof(RTUTF16)); 581 if (hData) 582 { 583 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, 584 fFormat & VBOX_SHCL_FMT_UNICODETEXT ? kUTTypeUTF16PlainText : kUTTypeHTML, 585 hData, kPasteboardFlavorNoFlags); 586 if (orc != 0) 587 { 588 Log(("writeToPasteboard: PasteboardPutItemFlavor/%s failed: %d (%#x)\n", 589 fFormat & VBOX_SHCL_FMT_UNICODETEXT ? "kUTTypeUTF16PlainText" : "kUTTypeHTML", orc, orc)); 590 rc = VERR_GENERAL_FAILURE; 591 } 592 CFRelease(hData); 593 } 594 else 595 { 596 Log(("writeToPasteboard: CFDataCreate/UTF16 failed!\n")); 597 rc = VERR_NO_MEMORY; 598 } 576 hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pwszDst, cwcDst * sizeof(RTUTF16)); 577 if (hData) 578 { 579 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, 580 kUTTypeUTF16PlainText, hData, kPasteboardFlavorNoFlags); 581 if (orc == 0) 582 rc = VINF_SUCCESS; 583 else 584 { 585 Log(("writeToPasteboard: PasteboardPutItemFlavor/kUTTypeUTF16PlainText failed: %d (%#x)\n", orc, orc)); 586 rc = VERR_GENERAL_FAILURE; 587 } 588 CFRelease(hData); 589 } 590 else 591 { 592 Log(("writeToPasteboard: CFDataCreate/UTF16 failed!\n")); 593 rc = VERR_NO_MEMORY; 599 594 } 600 595 … … 602 597 * Now for the UTF-8 version. 603 598 */ 604 //if (fFormat & VBOX_SHCL_FMT_UNICODETEXT) 605 { 606 char *pszDst; 607 int rc2 = RTUtf16ToUtf8(pwszDst, &pszDst); 608 if (RT_SUCCESS(rc2)) 609 { 610 hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pszDst, strlen(pszDst)); 611 if (hData) 612 { 613 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, 614 fFormat & VBOX_SHCL_FMT_UNICODETEXT ? kUTTypeUTF8PlainText : kUTTypeHTML, 615 hData, kPasteboardFlavorNoFlags); 616 if (orc != 0) 617 { 618 Log(("writeToPasteboard: PasteboardPutItemFlavor/%s failed: %d (%#x)\n", 619 fFormat & VBOX_SHCL_FMT_UNICODETEXT ? "kUTTypeUTF8PlainText" : "kUTTypeHTML", orc, orc)); 620 rc = VERR_GENERAL_FAILURE; 621 } 622 CFRelease(hData); 623 } 624 else 625 { 626 Log(("writeToPasteboard: CFDataCreate/UTF8 failed!\n")); 627 rc = VERR_NO_MEMORY; 628 } 629 RTStrFree(pszDst); 630 } 631 else 632 rc = rc2; 633 } 599 char *pszDst; 600 int rc2 = RTUtf16ToUtf8(pwszDst, &pszDst); 601 if (RT_SUCCESS(rc2)) 602 { 603 hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pszDst, strlen(pszDst)); 604 if (hData) 605 { 606 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, 607 kUTTypeUTF8PlainText, hData, kPasteboardFlavorNoFlags); 608 if (orc != 0) 609 { 610 Log(("writeToPasteboard: PasteboardPutItemFlavor/kUTTypeUTF8PlainText failed: %d (%#x)\n", orc, orc)); 611 rc = VERR_GENERAL_FAILURE; 612 } 613 CFRelease(hData); 614 } 615 else 616 { 617 Log(("writeToPasteboard: CFDataCreate/UTF8 failed!\n")); 618 rc = VERR_NO_MEMORY; 619 } 620 RTStrFree(pszDst); 621 } 622 else 623 rc = rc2; 634 624 } 635 625 else … … 670 660 } 671 661 } 662 #ifdef WITH_HTML_G2H 663 /* 664 * Handle HTML. Expect UTF-8, ignore line endings and just put it 665 * straigh up on the pasteboard for now. 666 */ 667 else if (fFormat & VBOX_SHCL_FMT_HTML) 668 { 669 const char *pszSrc = (const char *)pv; 670 size_t const cchSrc = RTStrNLen(pszSrc, cb); 671 rc = RTStrValidateEncodingEx(pszSrc, cchSrc, 0); 672 if (RT_SUCCESS(rc)) 673 { 674 hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pszSrc, cchSrc); 675 if (hData) 676 { 677 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, kUTTypeHTML, 678 hData, kPasteboardFlavorNoFlags); 679 if (orc == 0) 680 rc = VINF_SUCCESS; 681 else 682 { 683 Log(("writeToPasteboard: PasteboardPutItemFlavor/kUTTypeHTML failed: %d (%#x)\n", orc, orc)); 684 rc = VERR_GENERAL_FAILURE; 685 } 686 CFRelease(hData); 687 } 688 else 689 { 690 Log(("writeToPasteboard: CFDataCreate/HTML failed!\n")); 691 rc = VERR_NO_MEMORY; 692 } 693 } 694 else 695 Log(("writeToPasteboard: HTML: Invalid UTF-8 encoding: %Rrc\n", rc)); 696 } 697 #endif 672 698 else 673 699 rc = VERR_NOT_IMPLEMENTED;
Note:
See TracChangeset
for help on using the changeset viewer.