VirtualBox

Ignore:
Timestamp:
Apr 8, 2020 6:49:21 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137067
Message:

SharedClipboard: Trying to make the darwin approach work better. The problems reported in bugref:9620 is kind of addressed here, but there is more stuff to clean up here. Lots more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp

    r83621 r83628  
    284284
    285285/**
     286 * Takes the ownership of the pasteboard.
     287 *
     288 * This is called when the other end reports available formats.
     289 *
     290 * @returns VBox status code.
     291 * @param   hPasteboard         The pastboard handle (reference).
     292 * @param   idOwnership         The ownership ID to use now.
     293 * @param   pszOwnershipFlavor  The ownership indicator flavor
     294 * @param   pszOwnershipValue   The ownership value (stringified format mask).
     295 *
     296 * @todo    Add fFormats so we can make promises about available formats at once
     297 *          without needing to request any data first.  That might help on
     298 *          flavor priority.
     299 */
     300int takePasteboardOwnership(PasteboardRef hPasteboard, uint64_t idOwnership,
     301                            const char *pszOwnershipFlavor, const char *pszOwnershipValue)
     302{
     303    /*
     304     * Clear the pasteboard and take ownership over it.
     305     */
     306    OSStatus orc = PasteboardClear(hPasteboard);
     307    if (orc == 0)
     308    {
     309        /* For good measure. */
     310        PasteboardSynchronize(hPasteboard);
     311
     312        /*
     313         * Put the ownership flavor and value onto the clipboard.
     314         */
     315        CFDataRef hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pszOwnershipValue, strlen(pszOwnershipValue));
     316        if (hData)
     317        {
     318            CFStringRef hFlavor = CFStringCreateWithCString(kCFAllocatorDefault, pszOwnershipFlavor, kCFStringEncodingUTF8);
     319            if (hFlavor)
     320            {
     321                orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership,
     322                                              hFlavor, hData, kPasteboardFlavorNoFlags);
     323                if (orc == 0)
     324                    Log(("takePasteboardOwnership: idOwnership=%RX64 flavor=%s value=%s\n",
     325                         idOwnership, pszOwnershipFlavor, pszOwnershipValue));
     326                else
     327                    Log(("takePasteboardOwnership: PasteboardPutItemFlavor -> %d (%#x)!\n", orc, orc));
     328                CFRelease(hFlavor);
     329            }
     330            else
     331                Log(("takePasteboardOwnership: CFStringCreateWithCString failed!\n"));
     332            CFRelease(hData);
     333        }
     334        else
     335            Log(("takePasteboardOwnership: CFDataCreate failed!\n"));
     336    }
     337    else
     338        Log(("takePasteboardOwnership: PasteboardClear failed -> %d (%#x)\n", orc, orc));
     339    return orc == 0 ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
     340}
     341
     342/**
    286343 * Write clipboard content to the host clipboard from the internal clipboard
    287344 * structure.
    288345 *
    289346 * @param   pPasteboard    Reference to the global pasteboard.
     347 * @param   idOwnership    The ownership ID.
    290348 * @param   pv             The source buffer.
    291349 * @param   cb             The size of the source buffer.
     
    294352 * @returns IPRT status code.
    295353 */
    296 int writeToPasteboard(PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat)
     354int writeToPasteboard(PasteboardRef pPasteboard, uint64_t idOwnership, void *pv, uint32_t cb, uint32_t fFormat)
    297355{
    298356    Log(("writeToPasteboard: fFormat = %02X\n", fFormat));
    299 
    300     /* Clear the pasteboard */
    301     if (PasteboardClear(pPasteboard))
    302         return VERR_NOT_SUPPORTED;
    303357
    304358    /* Make sure all is in sync */
     
    342396
    343397        CFDataRef textData = NULL;
    344         /* Item id is 1. Nothing special here. */
    345         PasteboardItemID itemId = (PasteboardItemID)1;
    346398        /* Create a CData object which we could pass to the pasteboard */
    347399        if ((textData = CFDataCreate(kCFAllocatorDefault,
     
    349401        {
    350402            /* Put the Utf-16 version to the pasteboard */
    351             PasteboardPutItemFlavor(pPasteboard, itemId,
    352                                     kUTTypeUTF16PlainText,
    353                                     textData, 0);
     403            PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeUTF16PlainText, textData, 0);
    354404        }
    355405        /* Create a Utf-8 version */
     
    363413            {
    364414                /* Put the Utf-8 version to the pasteboard */
    365                 PasteboardPutItemFlavor(pPasteboard, itemId,
    366                                         kUTTypeUTF8PlainText,
    367                                         textData, 0);
     415                PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeUTF8PlainText, textData, 0);
    368416            }
    369417            RTStrFree(pszDestText);
     
    380428        size_t cbBmpSize;
    381429        CFDataRef bmpData = NULL;
    382         /* Item id is 1. Nothing special here. */
    383         PasteboardItemID itemId = (PasteboardItemID)1;
    384430
    385431        rc = ShClDibToBmp(pv, cb, &pBmp, &cbBmpSize);
     
    391437            {
    392438                /* Put the Utf-8 version to the pasteboard */
    393                 PasteboardPutItemFlavor(pPasteboard, itemId,
    394                                         kUTTypeBMP,
    395                                         bmpData, 0);
     439                PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeBMP, bmpData, 0);
    396440            }
    397441            RTMemFree(pBmp);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette