VirtualBox

Changeset 41183 in vbox


Ignore:
Timestamp:
May 7, 2012 1:09:44 PM (13 years ago)
Author:
vboxsync
Message:

SharedClipboard/darwin-pasteboard.cpp: use official constants instead of type strings (thanks to François Revol for the contribution), whitespace cleanup

File:
1 edited

Legend:

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

    r41083 r41183  
    55
    66/*
    7  * Copyright (C) 2008 Oracle Corporation
     7 * Copyright (C) 2008-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3737 * @returns IPRT status code.
    3838 */
    39 int initPasteboard (PasteboardRef *pPasteboardRef)
     39int initPasteboard(PasteboardRef *pPasteboardRef)
    4040{
    4141    int rc = VINF_SUCCESS;
    4242
    43     if (PasteboardCreate (kPasteboardClipboard, pPasteboardRef))
     43    if (PasteboardCreate(kPasteboardClipboard, pPasteboardRef))
    4444        rc = VERR_NOT_SUPPORTED;
    4545
     
    5252 * @param pPasteboardRef Reference to the global pasteboard.
    5353 */
    54 void destroyPasteboard (PasteboardRef *pPasteboardRef)
    55 {
    56     CFRelease (*pPasteboardRef);
     54void destroyPasteboard(PasteboardRef *pPasteboardRef)
     55{
     56    CFRelease(*pPasteboardRef);
    5757    *pPasteboardRef = NULL;
    5858}
     
    7070 * @returns IPRT status code. (Always VINF_SUCCESS atm.)
    7171 */
    72 int queryNewPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged)
    73 {
    74     Log (("queryNewPasteboardFormats\n"));
     72int queryNewPasteboardFormats(PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged)
     73{
     74    Log(("queryNewPasteboardFormats\n"));
    7575
    7676    OSStatus err = noErr;
     
    7979    PasteboardSyncFlags syncFlags;
    8080    /* Make sure all is in sync */
    81     syncFlags = PasteboardSynchronize (pPasteboard);
     81    syncFlags = PasteboardSynchronize(pPasteboard);
    8282    /* If nothing changed return */
    8383    if (!(syncFlags & kPasteboardModified))
     
    8989    /* Are some items in the pasteboard? */
    9090    ItemCount itemCount;
    91     err = PasteboardGetItemCount (pPasteboard, &itemCount);
     91    err = PasteboardGetItemCount(pPasteboard, &itemCount);
    9292    if (itemCount < 1)
    9393        return VINF_SUCCESS;
     
    9696    int rc = VINF_SUCCESS;
    9797    PasteboardItemID itemID;
    98     if (!(err = PasteboardGetItemIdentifier (pPasteboard, 1, &itemID)))
     98    if (!(err = PasteboardGetItemIdentifier(pPasteboard, 1, &itemID)))
    9999    {
    100100        /* Retrieve all flavors in the pasteboard, maybe there
    101101         * is something we can use. */
    102102        CFArrayRef flavorTypeArray;
    103         if (!(err = PasteboardCopyItemFlavors (pPasteboard, itemID, &flavorTypeArray)))
     103        if (!(err = PasteboardCopyItemFlavors(pPasteboard, itemID, &flavorTypeArray)))
    104104        {
    105105            CFIndex flavorCount;
    106             flavorCount = CFArrayGetCount (flavorTypeArray);
     106            flavorCount = CFArrayGetCount(flavorTypeArray);
    107107            for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
    108108            {
    109109                CFStringRef flavorType;
    110                 flavorType = static_cast <CFStringRef> (CFArrayGetValueAtIndex (flavorTypeArray,
    111                                                                                 flavorIndex));
     110                flavorType = static_cast <CFStringRef>(CFArrayGetValueAtIndex(flavorTypeArray,
     111                                                                               flavorIndex));
    112112                /* Currently only unicode supported */
    113                 if (UTTypeConformsTo (flavorType, CFSTR ("public.utf8-plain-text")) ||
    114                     UTTypeConformsTo (flavorType, CFSTR ("public.utf16-plain-text")))
    115                 {
    116                     Log (("Unicode flavor detected.\n"));
     113                if (UTTypeConformsTo(flavorType, kUTTypeUTF8PlainText) ||
     114                    UTTypeConformsTo(flavorType, kUTTypeUTF16PlainText))
     115                {
     116                    Log(("Unicode flavor detected.\n"));
    117117                    *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
    118118                }
    119                 else if (UTTypeConformsTo (flavorType, kUTTypeBMP))
    120                 {
    121                     Log (("BMP flavor detected.\n"));
     119                else if (UTTypeConformsTo(flavorType, kUTTypeBMP))
     120                {
     121                    Log(("BMP flavor detected.\n"));
    122122                    *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_BITMAP;
    123123                }
    124124            }
    125             CFRelease (flavorTypeArray);
    126         }
    127     }
    128 
    129     Log (("queryNewPasteboardFormats: rc = %02X\n", rc));
     125            CFRelease(flavorTypeArray);
     126        }
     127    }
     128
     129    Log(("queryNewPasteboardFormats: rc = %02X\n", rc));
    130130    return rc;
    131131}
     
    143143 * @returns IPRT status code.
    144144 */
    145 int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual)
    146 {
    147     Log (("readFromPasteboard: fFormat = %02X\n", fFormat));
     145int readFromPasteboard(PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual)
     146{
     147    Log(("readFromPasteboard: fFormat = %02X\n", fFormat));
    148148
    149149    OSStatus err = noErr;
    150150
    151151    /* Make sure all is in sync */
    152     PasteboardSynchronize (pPasteboard);
     152    PasteboardSynchronize(pPasteboard);
    153153
    154154    /* Are some items in the pasteboard? */
    155155    ItemCount itemCount;
    156     err = PasteboardGetItemCount (pPasteboard, &itemCount);
     156    err = PasteboardGetItemCount(pPasteboard, &itemCount);
    157157    if (itemCount < 1)
    158158        return VINF_SUCCESS;
     
    161161    int rc = VERR_NOT_SUPPORTED;
    162162    PasteboardItemID itemID;
    163     if (!(err = PasteboardGetItemIdentifier (pPasteboard, 1, &itemID)))
     163    if (!(err = PasteboardGetItemIdentifier(pPasteboard, 1, &itemID)))
    164164    {
    165165        /* The guest request unicode */
     
    169169            PRTUTF16 pwszTmp = NULL;
    170170            /* Try utf-16 first */
    171             if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf16-plain-text"), &outData)))
    172             {
    173                 Log (("Clipboard content is utf-16\n"));
    174                 rc = RTUtf16DupEx (&pwszTmp, (PRTUTF16)CFDataGetBytePtr (outData), 0);
     171            if (!(err = PasteboardCopyItemFlavorData(pPasteboard, itemID, kUTTypeUTF16PlainText, &outData)))
     172            {
     173                Log(("Clipboard content is utf-16\n"));
     174                rc = RTUtf16DupEx(&pwszTmp, (PRTUTF16)CFDataGetBytePtr(outData), 0);
    175175            }
    176176            /* Second try is utf-8 */
    177177            else
    178                 if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf8-plain-text"), &outData)))
    179                 {
    180                     Log (("readFromPasteboard: clipboard content is utf-8\n"));
    181                     rc = RTStrToUtf16 ((const char*)CFDataGetBytePtr (outData), &pwszTmp);
     178                if (!(err = PasteboardCopyItemFlavorData(pPasteboard, itemID, kUTTypeUTF8PlainText, &outData)))
     179                {
     180                    Log(("readFromPasteboard: clipboard content is utf-8\n"));
     181                    rc = RTStrToUtf16((const char*)CFDataGetBytePtr(outData), &pwszTmp);
    182182                }
    183183            if (pwszTmp)
    184184            {
    185185                /* Check how much longer will the converted text will be. */
    186                 size_t cwSrc = RTUtf16Len (pwszTmp);
     186                size_t cwSrc = RTUtf16Len(pwszTmp);
    187187                size_t cwDest;
    188                 rc = vboxClipboardUtf16GetWinSize (pwszTmp, cwSrc, &cwDest);
    189                 if (RT_FAILURE (rc))
    190                 {
    191                     RTUtf16Free (pwszTmp);
    192                     Log (("readFromPasteboard: clipboard conversion failed.  vboxClipboardUtf16GetWinSize returned %Rrc.  Abandoning.\n", rc));
    193                     AssertRCReturn (rc, rc);
     188                rc = vboxClipboardUtf16GetWinSize(pwszTmp, cwSrc, &cwDest);
     189                if (RT_FAILURE(rc))
     190                {
     191                    RTUtf16Free(pwszTmp);
     192                    Log(("readFromPasteboard: clipboard conversion failed.  vboxClipboardUtf16GetWinSize returned %Rrc.  Abandoning.\n", rc));
     193                    AssertRCReturn(rc, rc);
    194194                }
    195195                /* Set the actually needed data size */
     
    200200                if (*pcbActual <= cb)
    201201                {
    202                     rc = vboxClipboardUtf16LinToWin (pwszTmp, RTUtf16Len (pwszTmp), static_cast <PRTUTF16> (pv), cb / 2);
    203                     if (RT_FAILURE (rc))
     202                    rc = vboxClipboardUtf16LinToWin(pwszTmp, RTUtf16Len(pwszTmp), static_cast <PRTUTF16>(pv), cb / 2);
     203                    if (RT_FAILURE(rc))
    204204                    {
    205                         RTUtf16Free (pwszTmp);
    206                         Log (("readFromPasteboard: clipboard conversion failed.  vboxClipboardUtf16LinToWin() returned %Rrc.  Abandoning.\n", rc));
    207                         AssertRCReturn (rc, rc);
     205                        RTUtf16Free(pwszTmp);
     206                        Log(("readFromPasteboard: clipboard conversion failed.  vboxClipboardUtf16LinToWin() returned %Rrc.  Abandoning.\n", rc));
     207                        AssertRCReturn(rc, rc);
    208208                    }
    209209#ifdef SHOW_CLIPBOARD_CONTENT
    210                     Log (("readFromPasteboard: clipboard content: %ls\n", static_cast <PRTUTF16> (pv)));
     210                    Log(("readFromPasteboard: clipboard content: %ls\n", static_cast <PRTUTF16>(pv)));
    211211#endif
    212212                }
    213213                /* Free the temp string */
    214                 RTUtf16Free (pwszTmp);
     214                RTUtf16Free(pwszTmp);
    215215            }
    216216        }
     
    222222            size_t cbTmpSize;
    223223            /* Get the data from the pasteboard */
    224             if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, kUTTypeBMP, &outData)))
    225             {
    226                 Log (("Clipboard content is BMP\n"));
    227                 pTmp = CFDataGetBytePtr (outData);
    228                 cbTmpSize = CFDataGetLength (outData);
     224            if (!(err = PasteboardCopyItemFlavorData(pPasteboard, itemID, kUTTypeBMP, &outData)))
     225            {
     226                Log(("Clipboard content is BMP\n"));
     227                pTmp = CFDataGetBytePtr(outData);
     228                cbTmpSize = CFDataGetLength(outData);
    229229            }
    230230            if (pTmp)
     
    232232                const void *pDib;
    233233                size_t cbDibSize;
    234                 rc = vboxClipboardBmpGetDib (pTmp, cbTmpSize, &pDib, &cbDibSize);
    235                 if (RT_FAILURE (rc))
     234                rc = vboxClipboardBmpGetDib(pTmp, cbTmpSize, &pDib, &cbDibSize);
     235                if (RT_FAILURE(rc))
    236236                {
    237237                    rc = VERR_NOT_SUPPORTED;
    238                     Log (("readFromPasteboard: unknown bitmap format. vboxClipboardBmpGetDib returned %Rrc.  Abandoning.\n", rc));
    239                     AssertRCReturn (rc, rc);
     238                    Log(("readFromPasteboard: unknown bitmap format. vboxClipboardBmpGetDib returned %Rrc.  Abandoning.\n", rc));
     239                    AssertRCReturn(rc, rc);
    240240                }
    241241
     
    246246                if (*pcbActual <= cb)
    247247                {
    248                     memcpy (pv, pDib, cbDibSize);
     248                    memcpy(pv, pDib, cbDibSize);
    249249#ifdef SHOW_CLIPBOARD_CONTENT
    250                     Log (("readFromPasteboard: clipboard content bitmap %d bytes\n", cbDibSize));
     250                    Log(("readFromPasteboard: clipboard content bitmap %d bytes\n", cbDibSize));
    251251#endif
    252252                }
     
    255255    }
    256256
    257     Log (("readFromPasteboard: rc = %02X\n", rc));
     257    Log(("readFromPasteboard: rc = %02X\n", rc));
    258258    return rc;
    259259}
     
    270270 * @returns IPRT status code.
    271271 */
    272 int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat)
    273 {
    274     Log (("writeToPasteboard: fFormat = %02X\n", fFormat));
     272int writeToPasteboard(PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat)
     273{
     274    Log(("writeToPasteboard: fFormat = %02X\n", fFormat));
    275275
    276276    /* Clear the pasteboard */
    277     if (PasteboardClear (pPasteboard))
     277    if (PasteboardClear(pPasteboard))
    278278        return VERR_NOT_SUPPORTED;
    279279
    280280    /* Make sure all is in sync */
    281     PasteboardSynchronize (pPasteboard);
     281    PasteboardSynchronize(pPasteboard);
    282282
    283283    int rc = VERR_NOT_SUPPORTED;
     
    285285    if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    286286    {
    287         PRTUTF16 pwszSrcText = static_cast <PRTUTF16> (pv);
     287        PRTUTF16 pwszSrcText = static_cast <PRTUTF16>(pv);
    288288        size_t cwSrc = cb / 2;
    289289        size_t cwDest = 0;
    290290        /* How long will the converted text be? */
    291         rc = vboxClipboardUtf16GetLinSize (pwszSrcText, cwSrc, &cwDest);
    292         if (RT_FAILURE (rc))
    293         {
    294             Log (("writeToPasteboard: clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
    295             AssertRCReturn (rc, rc);
     291        rc = vboxClipboardUtf16GetLinSize(pwszSrcText, cwSrc, &cwDest);
     292        if (RT_FAILURE(rc))
     293        {
     294            Log(("writeToPasteboard: clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
     295            AssertRCReturn(rc, rc);
    296296        }
    297297        /* Empty clipboard? Not critical */
    298298        if (cwDest == 0)
    299299        {
    300             Log (("writeToPasteboard: received empty clipboard data from the guest, returning false.\n"));
     300            Log(("writeToPasteboard: received empty clipboard data from the guest, returning false.\n"));
    301301            return VINF_SUCCESS;
    302302        }
    303303        /* Allocate the necessary memory */
    304         PRTUTF16 pwszDestText = static_cast <PRTUTF16> (RTMemAlloc (cwDest * 2));
     304        PRTUTF16 pwszDestText = static_cast <PRTUTF16>(RTMemAlloc(cwDest * 2));
    305305        if (pwszDestText == NULL)
    306306        {
    307             Log (("writeToPasteboard: failed to allocate %d bytes\n", cwDest * 2));
     307            Log(("writeToPasteboard: failed to allocate %d bytes\n", cwDest * 2));
    308308            return VERR_NO_MEMORY;
    309309        }
    310310        /* Convert the EOL */
    311         rc = vboxClipboardUtf16WinToLin (pwszSrcText, cwSrc, pwszDestText, cwDest);
    312         if (RT_FAILURE (rc))
    313         {
    314             Log (("writeToPasteboard: clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
    315             RTMemFree (pwszDestText);
    316             AssertRCReturn (rc, rc);
     311        rc = vboxClipboardUtf16WinToLin(pwszSrcText, cwSrc, pwszDestText, cwDest);
     312        if (RT_FAILURE(rc))
     313        {
     314            Log(("writeToPasteboard: clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
     315            RTMemFree(pwszDestText);
     316            AssertRCReturn(rc, rc);
    317317        }
    318318
     
    321321        PasteboardItemID itemId = (PasteboardItemID)1;
    322322        /* Create a CData object which we could pass to the pasteboard */
    323         if ((textData = CFDataCreate (kCFAllocatorDefault,
    324                                       reinterpret_cast<UInt8*> (pwszDestText), cwDest * 2)))
     323        if ((textData = CFDataCreate(kCFAllocatorDefault,
     324                                     reinterpret_cast<UInt8*>(pwszDestText), cwDest * 2)))
    325325        {
    326326            /* Put the Utf-16 version to the pasteboard */
    327             PasteboardPutItemFlavor (pPasteboard, itemId,
    328                                      CFSTR ("public.utf16-plain-text"),
    329                                      textData, 0);
     327            PasteboardPutItemFlavor(pPasteboard, itemId,
     328                                    kUTTypeUTF16PlainText,
     329                                    textData, 0);
    330330        }
    331331        /* Create a Utf-8 version */
    332332        char *pszDestText;
    333         rc = RTUtf16ToUtf8 (pwszDestText, &pszDestText);
    334         if (RT_SUCCESS (rc))
     333        rc = RTUtf16ToUtf8(pwszDestText, &pszDestText);
     334        if (RT_SUCCESS(rc))
    335335        {
    336336            /* Create a CData object which we could pass to the pasteboard */
    337             if ((textData = CFDataCreate (kCFAllocatorDefault,
    338                                           reinterpret_cast<UInt8*> (pszDestText), strlen(pszDestText))))
     337            if ((textData = CFDataCreate(kCFAllocatorDefault,
     338                                         reinterpret_cast<UInt8*>(pszDestText), strlen(pszDestText))))
    339339            {
    340340                /* Put the Utf-8 version to the pasteboard */
    341                 PasteboardPutItemFlavor (pPasteboard, itemId,
    342                                          CFSTR ("public.utf8-plain-text"),
    343                                          textData, 0);
    344             }
    345             RTStrFree (pszDestText);
    346         }
    347 
    348         RTMemFree (pwszDestText);
     341                PasteboardPutItemFlavor(pPasteboard, itemId,
     342                                        kUTTypeUTF8PlainText,
     343                                        textData, 0);
     344            }
     345            RTStrFree(pszDestText);
     346        }
     347
     348        RTMemFree(pwszDestText);
    349349        rc = VINF_SUCCESS;
    350350    }
     
    359359        PasteboardItemID itemId = (PasteboardItemID)1;
    360360
    361         rc = vboxClipboardDibToBmp (pv, cb, &pBmp, &cbBmpSize);
    362         if (RT_SUCCESS (rc))
     361        rc = vboxClipboardDibToBmp(pv, cb, &pBmp, &cbBmpSize);
     362        if (RT_SUCCESS(rc))
    363363        {
    364364            /* Create a CData object which we could pass to the pasteboard */
    365             if ((bmpData = CFDataCreate (kCFAllocatorDefault,
    366                                           reinterpret_cast<UInt8*> (pBmp), cbBmpSize)))
     365            if ((bmpData = CFDataCreate(kCFAllocatorDefault,
     366                                         reinterpret_cast<UInt8*>(pBmp), cbBmpSize)))
    367367            {
    368368                /* Put the Utf-8 version to the pasteboard */
    369                 PasteboardPutItemFlavor (pPasteboard, itemId,
    370                                          kUTTypeBMP,
    371                                          bmpData, 0);
    372             }
    373             RTMemFree (pBmp);
     369                PasteboardPutItemFlavor(pPasteboard, itemId,
     370                                        kUTTypeBMP,
     371                                        bmpData, 0);
     372            }
     373            RTMemFree(pBmp);
    374374        }
    375375        rc = VINF_SUCCESS;
     
    378378        rc = VERR_NOT_IMPLEMENTED;
    379379
    380     Log (("writeToPasteboard: rc = %02X\n", rc));
     380    Log(("writeToPasteboard: rc = %02X\n", rc));
    381381    return rc;
    382382}
Note: See TracChangeset for help on using the changeset viewer.

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