VirtualBox

Changeset 7117 in vbox


Ignore:
Timestamp:
Feb 25, 2008 3:54:42 PM (17 years ago)
Author:
vboxsync
Message:

r=bird: subversion attributes. some hungarian fixes. do not pass stuff by reference unless its normal C++ code and very convenient (because it makes it totally unreadable otherwise). A couple of questions. (hope it still compiles)

Location:
trunk/src/VBox/HostServices/SharedClipboard
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/Makefile.kmk

    r7073 r7117  
    3535VBoxSharedClipboard_SOURCES.darwin = \
    3636        darwin.cpp \
    37     clipboard-helper.cpp \
    38     darwin-pasteboard.cpp
     37        clipboard-helper.cpp \
     38        darwin-pasteboard.cpp
    3939if1of ($(BUILD_TARGET),linux solaris)
    4040 ifndef VBOX_HEADLESS
    4141  VBoxSharedClipboard_SOURCES += \
    42     clipboard-helper.cpp \
    43         linux.cpp
     42        clipboard-helper.cpp \
     43        linux.cpp
    4444 else
    4545  VBoxSharedClipboard_SOURCES += \
    46         linux-stub.cpp
     46        linux-stub.cpp
    4747 endif
    4848endif
  • trunk/src/VBox/HostServices/SharedClipboard/clipboard-helper.cpp

    • Property eol-style set to native
    r7073 r7117  
     1/* $Id$ */
    12/** @file
    2  *
    3  * Shared Clipboard:
    4  * Some helper function for converting between the various eol.
     3 * Shared Clipboard: Some helper function for converting between the various eol.
    54 */
    65
     
    2120#include <iprt/assert.h>
    2221
    23 int vboxClipboardUtf16GetWinSize(PRTUTF16 pu16Src, size_t cwSrc, size_t *pcwDest)
     22/** @todo use const where appropriate; delinuxifiy the code (*Lin* -> *Host*); use AssertLogRel*. */
     23
     24int vboxClipboardUtf16GetWinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest)
    2425{
    2526    size_t cwDest, i;
    2627
    27     LogFlowFunc(("pu16Src=%.*ls, cwSrc=%u\n", cwSrc, pu16Src, cwSrc));
    28     if (pu16Src == 0)
    29     {
    30         LogRel(("vboxClipboardUtf16GetWinSize: received a null Utf16 string, returning VERR_INVALID_PARAMETER\n"));
    31         AssertReturn(pu16Src != 0, VERR_INVALID_PARAMETER);
    32     }
    33     /* We only take little endian Utf16 */
    34     if (pu16Src[0] == UTF16BEMARKER)
     28    LogFlowFunc(("pwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pwszSrc, cwSrc));
     29    AssertLogRelMsgReturn(pwszSrc != NULL, ("vboxClipboardUtf16GetWinSize: received a null Utf16 string, returning VERR_INVALID_PARAMETER\n"), VERR_INVALID_PARAMETER);
     30/** @todo convert the remainder of the Assert stuff to AssertLogRel. */
     31    /* We only take little endian Utf16 */
     32    if (pwszSrc[0] == UTF16BEMARKER)
    3533    {
    3634        LogRel(("vboxClipboardUtf16GetWinSize: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
    37         AssertReturn(pu16Src[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);
     35        AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);
    3836    }
    3937    if (cwSrc == 0)
     
    4644    /* Calculate the size of the destination text string. */
    4745    /* Is this Utf16 or Utf16-LE? */
    48     for (i = (pu16Src[0] == UTF16LEMARKER ? 1 : 0); i < cwSrc; ++i, ++cwDest)
    49     {
    50         if (pu16Src[i] == LINEFEED)
     46    for (i = (pwszSrc[0] == UTF16LEMARKER ? 1 : 0); i < cwSrc; ++i, ++cwDest)
     47    {
     48        if (pwszSrc[i] == LINEFEED)
    5149            ++cwDest;
    52         if (pu16Src[i] == 0)
     50        if (pwszSrc[i] == 0)
    5351        {
    5452            /* Don't count this, as we do so below. */
     
    6361}
    6462
    65 int vboxClipboardUtf16LinToWin(PRTUTF16 pu16Src, size_t cwSrc, PRTUTF16 pu16Dest,
     63int vboxClipboardUtf16LinToWin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest,
    6664                               size_t cwDest)
    6765{
    6866    size_t i, j;
    69     LogFlowFunc(("pu16Src=%.*ls, cwSrc=%u\n", cwSrc, pu16Src, cwSrc));
    70     if (!VALID_PTR(pu16Src) || !VALID_PTR(pu16Dest))
    71     {
    72         LogRel(("vboxClipboardUtf16LinToWin: received an invalid pointer, pu16Src=%p, pu16Dest=%p, returning VERR_INVALID_PARAMETER\n", pu16Src, pu16Dest));
    73         AssertReturn(VALID_PTR(pu16Src) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);
    74     }
    75     /* We only take little endian Utf16 */
    76     if (pu16Src[0] == UTF16BEMARKER)
     67    LogFlowFunc(("pwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pwszSrc, cwSrc));
     68    if (!VALID_PTR(pwszSrc) || !VALID_PTR(pu16Dest))
     69    {
     70        LogRel(("vboxClipboardUtf16LinToWin: received an invalid pointer, pwszSrc=%p, pu16Dest=%p, returning VERR_INVALID_PARAMETER\n", pwszSrc, pu16Dest));
     71        AssertReturn(VALID_PTR(pwszSrc) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);
     72    }
     73    /* We only take little endian Utf16 */
     74    if (pwszSrc[0] == UTF16BEMARKER)
    7775    {
    7876        LogRel(("vboxClipboardUtf16LinToWin: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
    79         AssertReturn(pu16Src[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);
     77        AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);
    8078    }
    8179    if (cwSrc == 0)
     
    9189    }
    9290    /* Don't copy the endian marker. */
    93     for (i = (pu16Src[0] == UTF16LEMARKER ? 1 : 0), j = 0; i < cwSrc; ++i, ++j)
     91    for (i = (pwszSrc[0] == UTF16LEMARKER ? 1 : 0), j = 0; i < cwSrc; ++i, ++j)
    9492    {
    9593        /* Don't copy the null byte, as we add it below. */
    96         if (pu16Src[i] == 0)
     94        if (pwszSrc[i] == 0)
    9795            break;
    9896        if (j == cwDest)
     
    10199            return VERR_BUFFER_OVERFLOW;
    102100        }
    103         if (pu16Src[i] == LINEFEED)
     101        if (pwszSrc[i] == LINEFEED)
    104102        {
    105103            pu16Dest[j] = CARRIAGERETURN;
     
    111109            }
    112110        }
    113         pu16Dest[j] = pu16Src[i];
     111        pu16Dest[j] = pwszSrc[i];
    114112    }
    115113    /* Add the trailing null. */
     
    124122}
    125123
    126 int vboxClipboardUtf16GetLinSize(PRTUTF16 pu16Src, size_t cwSrc, size_t *pcwDest)
     124int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest)
    127125{
    128126    size_t cwDest;
    129127
    130     LogFlowFunc(("pu16Src=%.*ls, cwSrc=%u\n", cwSrc, pu16Src, cwSrc));
    131     if (!VALID_PTR(pu16Src))
    132     {
    133         LogRel(("vboxClipboardUtf16GetLinSize: received an invalid Utf16 string %p.  Returning VERR_INVALID_PARAMETER.\n", pu16Src));
    134         AssertReturn(VALID_PTR(pu16Src), VERR_INVALID_PARAMETER);
    135     }
    136     /* We only take little endian Utf16 */
    137     if (pu16Src[0] == UTF16BEMARKER)
     128    LogFlowFunc(("pwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pwszSrc, cwSrc));
     129    if (!VALID_PTR(pwszSrc))
     130    {
     131        LogRel(("vboxClipboardUtf16GetLinSize: received an invalid Utf16 string %p.  Returning VERR_INVALID_PARAMETER.\n", pwszSrc));
     132        AssertReturn(VALID_PTR(pwszSrc), VERR_INVALID_PARAMETER);
     133    }
     134    /* We only take little endian Utf16 */
     135    if (pwszSrc[0] == UTF16BEMARKER)
    138136    {
    139137        LogRel(("vboxClipboardUtf16GetLinSize: received a big endian Utf16 string.  Returning VERR_INVALID_PARAMETER.\n"));
    140         AssertReturn(pu16Src[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);
     138        AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);
    141139    }
    142140    if (cwSrc == 0)
     
    148146    /* Calculate the size of the destination text string. */
    149147    /* Is this Utf16 or Utf16-LE? */
    150     if (pu16Src[0] == UTF16LEMARKER)
     148    if (pwszSrc[0] == UTF16LEMARKER)
    151149        cwDest = 0;
    152150    else
     
    155153    {
    156154        if (   (i + 1 < cwSrc)
    157             && (pu16Src[i] == CARRIAGERETURN)
    158             && (pu16Src[i + 1] == LINEFEED))
     155            && (pwszSrc[i] == CARRIAGERETURN)
     156            && (pwszSrc[i + 1] == LINEFEED))
    159157        {
    160158            ++i;
    161159        }
    162         if (pu16Src[i] == 0)
     160        if (pwszSrc[i] == 0)
    163161        {
    164162            break;
     
    172170}
    173171
    174 int vboxClipboardUtf16WinToLin(PRTUTF16 pu16Src, size_t cwSrc, PRTUTF16 pu16Dest,
     172int vboxClipboardUtf16WinToLin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest,
    175173                               size_t cwDest)
    176174{
    177175    size_t cwDestPos;
    178176
    179     LogFlowFunc(("pu16Src=%.*ls, cwSrc=%u, pu16Dest=%p, cwDest=%u\n",
    180                  cwSrc, pu16Src, cwSrc, pu16Dest, cwDest));
     177    LogFlowFunc(("pwszSrc=%.*ls, cwSrc=%u, pu16Dest=%p, cwDest=%u\n",
     178                 cwSrc, pwszSrc, cwSrc, pu16Dest, cwDest));
    181179    /* A buffer of size 0 may not be an error, but it is not a good idea either. */
    182180    Assert(cwDest > 0);
    183     if (!VALID_PTR(pu16Src) || !VALID_PTR(pu16Dest))
    184     {
    185         LogRel(("vboxClipboardUtf16WinToLin: received an invalid ptr, pu16Src=%p, pu16Dest=%p, returning VERR_INVALID_PARAMETER\n", pu16Src, pu16Dest));
    186         AssertReturn(VALID_PTR(pu16Src) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);
    187     }
    188     /* We only take little endian Utf16 */
    189     if (pu16Src[0] == UTF16BEMARKER)
     181    if (!VALID_PTR(pwszSrc) || !VALID_PTR(pu16Dest))
     182    {
     183        LogRel(("vboxClipboardUtf16WinToLin: received an invalid ptr, pwszSrc=%p, pu16Dest=%p, returning VERR_INVALID_PARAMETER\n", pwszSrc, pu16Dest));
     184        AssertReturn(VALID_PTR(pwszSrc) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);
     185    }
     186    /* We only take little endian Utf16 */
     187    if (pwszSrc[0] == UTF16BEMARKER)
    190188    {
    191189        LogRel(("vboxClipboardUtf16WinToLin: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
     
    204202    }
    205203    /* Prepend the Utf16 byte order marker if it is missing. */
    206     if (pu16Src[0] == UTF16LEMARKER)
     204    if (pwszSrc[0] == UTF16LEMARKER)
    207205    {
    208206        cwDestPos = 0;
     
    215213    for (size_t i = 0; i < cwSrc; ++i, ++cwDestPos)
    216214    {
    217         if (pu16Src[i] == 0)
     215        if (pwszSrc[i] == 0)
    218216        {
    219217            break;
     
    225223        }
    226224        if (   (i + 1 < cwSrc)
    227             && (pu16Src[i] == CARRIAGERETURN)
    228             && (pu16Src[i + 1] == LINEFEED))
     225            && (pwszSrc[i] == CARRIAGERETURN)
     226            && (pwszSrc[i + 1] == LINEFEED))
    229227        {
    230228            ++i;
    231229        }
    232         pu16Dest[cwDestPos] = pu16Src[i];
     230        pu16Dest[cwDestPos] = pwszSrc[i];
    233231    }
    234232    /* Terminating zero */
  • trunk/src/VBox/HostServices/SharedClipboard/clipboard-helper.h

    • Property eol-style set to native
    r7073 r7117  
     1/* $Id$ */
    12/** @file
    2  *
    3  * Shared Clipboard:
    4  * Some helper function for converting between the various eol.
     3 * Shared Clipboard: Some helper function for converting between the various eol.
    54 */
    65
     
    1716 */
    1817
    19 #ifndef __CLIPBOARD_HELPER_H
    20 #define __CLIPBOARD_HELPER_H
     18#ifndef ___CLIPBOARD_HELPER_H
     19#define ___CLIPBOARD_HELPER_H
    2120
    2221#include <iprt/string.h>
     
    4039 * @returns RT error code
    4140 *
    42  * @param   pu16Src  The source Utf16 string
     41 * @param   pwszSrc  The source Utf16 string
    4342 * @param   cwSrc    The length in 16 bit words of the source string
    4443 * @retval  pcwDest  The length of the destination string in 16 bit words
    4544 */
    46 int vboxClipboardUtf16GetWinSize(PRTUTF16 pu16Src, size_t cwSrc, size_t *pcwDest);
     45int vboxClipboardUtf16GetWinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest);
    4746
    4847/**
     
    5251 * @returns VBox status code
    5352 *
    54  * @param   pu16Src  Source Utf16 text to convert
     53 * @param   pwszSrc  Source Utf16 text to convert
    5554 * @param   cwSrc    Size of the source text in 16 bit words
    5655 * @retval  pu16Dest Buffer to store the converted text to.
    5756 * @retval  pcwDest  Size of the buffer for the converted text in 16 bit words
    5857 */
    59 int vboxClipboardUtf16LinToWin(PRTUTF16 pu16Src, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest);
     58int vboxClipboardUtf16LinToWin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest);
    6059
    6160/**
     
    6564 * @returns RT status code
    6665 *
    67  * @param   pu16Src  The source Utf16 string
     66 * @param   pwszSrc  The source Utf16 string
    6867 * @param   cwSrc    The length in 16 bit words of the source string
    6968 * @retval  pcwDest  The length of the destination string in 16 bit words
    7069 */
    71 int vboxClipboardUtf16GetLinSize(PRTUTF16 pu16Src, size_t cwSrc, size_t *pcwDest);
     70int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest);
    7271
    7372/**
     
    7776 * @returns VBox status code
    7877 *
    79  * @param   pu16Src       Text to convert
     78 * @param   pwszSrc       Text to convert
    8079 * @param   cwSrc         Size of the source text in 16 bit words
    8180 * @param   pu16Dest      The buffer to store the converted text to
    8281 * @param   cwDest        The size of the buffer for the destination text in 16 bit words
    8382 */
    84 int vboxClipboardUtf16WinToLin(PRTUTF16 pu16Src, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest);
     83int vboxClipboardUtf16WinToLin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest);
    8584
    86 #endif /* __CLIPBOARD_HELPER_H */
     85#endif
    8786
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp

    • Property eol-style set to native
    r7073 r7117  
     1/* $Id$ */
    12/** @file
    2  *
    3  * Shared Clipboard:
    4  * Mac OS X host implementation.
     3 * Shared Clipboard: Mac OS X host implementation.
    54 */
    65
     
    1716 */
    1817
    19 // @todo: same as defined in VBoxClipboardSvc.h
     18/// @todo: same as defined in VBoxClipboardSvc.h
     19/// @todo r-bird: why don't you include it?
    2020#define VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT 0x01
    2121#define VBOX_SHARED_CLIPBOARD_FMT_BITMAP      0x02
     
    3434//#define SHOW_CLIPBOARD_CONTENT
    3535
    36 int initPasteboard (PasteboardRef &pPasteboard)
     36int initPasteboard (PasteboardRef *pPasteboardRef)
    3737{
    3838    int rc = VINF_SUCCESS;
    3939
    40     if (PasteboardCreate (kPasteboardClipboard, &pPasteboard))
     40    if (PasteboardCreate (kPasteboardClipboard, pPasteboardRef))
    4141        rc = VERR_NOT_SUPPORTED;
    4242
     
    4444}
    4545
    46 void destroyPasteboard (PasteboardRef &pPasteboard)
    47 {
    48     CFRelease (pPasteboard);
    49     pPasteboard = NULL;
    50 }
    51 
    52 int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t &u32Formats)
     46void destroyPasteboard (PasteboardRef *pPasteboardRef)
     47{
     48    CFRelease (*pPasteboardRef);
     49    *pPasteboardRef = NULL;
     50}
     51
     52int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t pfFormats)
    5353{
    5454    Log (("queryPasteboardFormats\n"));
     
    7474    if (!(err = PasteboardGetItemIdentifier (pPasteboard, 1, &itemID)))
    7575    {
    76         /* Retrieve all flavors in the pasteboard, maybe there 
     76        /* Retrieve all flavors in the pasteboard, maybe there
    7777         * is something we can use. */
    7878        CFArrayRef flavorTypeArray;
     
    9191                {
    9292                    Log (("Unicode flavor detected.\n"));
    93                     u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
     93                    *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
    9494                }
    9595            }
     
    103103}
    104104
    105 int readFromPasteboard (PasteboardRef pPasteboard, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual)
    106 {
    107     Log (("readFromPastboard: u32Format = %02X\n", u32Format));
     105int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual)
     106{
     107    Log (("readFromPastboard: fFormat = %02X\n", fFormat));
    108108
    109109    OSStatus err = noErr;
     
    124124    {
    125125        /* The guest request unicode */
    126         if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     126        if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    127127        {
    128128            CFDataRef outData;
    129             PRTUTF16 pu16Tmp = NULL;
    130             /* Utf-16 is currently broken on more than one line. 
     129            PRTUTF16 pwszTmp = NULL;
     130            /* Utf-16 is currently broken on more than one line.
    131131             * Has to be investigated. */
    132132#if 0
     
    135135            {
    136136                Log (("Clipboard content is utf-16\n"));
    137                 rc = RTUtf16DupEx (&pu16Tmp, (RTUTF16*)CFDataGetBytePtr (outData), 0);
     137                rc = RTUtf16DupEx (&pwszTmp, (PRTUTF16)CFDataGetBytePtr (outData), 0);
    138138            }
    139139            /* Second try is utf-8 */
    140             else 
    141 #endif 
     140            else
     141#endif
    142142                if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf8-plain-text"), &outData)))
    143143                {
    144144                    Log (("readFromPastboard: clipboard content is utf-8\n"));
    145                     rc = RTStrToUtf16 ((const char*)CFDataGetBytePtr (outData), &pu16Tmp);
    146                 }
    147             if (pu16Tmp)
     145                    rc = RTStrToUtf16 ((const char*)CFDataGetBytePtr (outData), &pwszTmp);
     146                }
     147            if (pwszTmp)
    148148            {
    149149                /* Check how much longer will the converted text will be. */
    150                 size_t cwSrcLen = RTUtf16Len (pu16Tmp);
    151                 size_t cwDestLen;
    152                 rc = vboxClipboardUtf16GetWinSize (pu16Tmp, cwSrcLen, &cwDestLen);
     150                size_t cwSrc = RTUtf16Len (pwszTmp);
     151                size_t cwDest;
     152                rc = vboxClipboardUtf16GetWinSize (pwszTmp, cwSrc, &cwDest);
    153153                if (RT_FAILURE (rc))
    154154                {
    155                     RTUtf16Free (pu16Tmp);
     155                    RTUtf16Free (pwszTmp);
    156156                    Log (("readFromPastboard: clipboard conversion failed.  vboxClipboardUtf16GetWinSize returned %Vrc.  Abandoning.\n", rc));
    157157                    AssertRCReturn (rc, rc);
    158158                }
    159159                /* Set the actually needed data size */
    160                 *pcbActual = cwDestLen * 2;
     160                *pcbActual = cwDest * 2;
    161161                /* Return success state */
    162162                rc = VINF_SUCCESS;
     
    164164                if (*pcbActual <= cb)
    165165                {
    166                     rc = vboxClipboardUtf16LinToWin (pu16Tmp, RTUtf16Len (pu16Tmp), static_cast <PRTUTF16> (pv), cb / 2);
     166                    rc = vboxClipboardUtf16LinToWin (pwszTmp, RTUtf16Len (pwszTmp), static_cast <PRTUTF16> (pv), cb / 2);
    167167                    if (RT_FAILURE (rc))
    168168                    {
    169                         RTUtf16Free (pu16Tmp);
     169                        RTUtf16Free (pwszTmp);
    170170                        Log (("readFromPastboard: clipboard conversion failed.  vboxClipboardUtf16LinToWin() returned %Vrc.  Abandoning.\n", rc));
    171171                        AssertRCReturn (rc, rc);
     
    176176                }
    177177                /* Free the temp string */
    178                 RTUtf16Free (pu16Tmp);
     178                RTUtf16Free (pwszTmp);
    179179            }
    180180        }
     
    185185}
    186186
    187 int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t u32Format)
    188 {
    189     Log (("writeToPasteboard: u32Format = %02X\n", u32Format));
    190  
     187int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat)
     188{
     189    Log (("writeToPasteboard: fFormat = %02X\n", fFormat));
     190
    191191    /* Clear the pastboard */
    192192    if (PasteboardClear (pPasteboard))
     
    198198    int rc = VERR_NOT_SUPPORTED;
    199199    /* Handle the unicode text */
    200     if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     200    if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    201201    {
    202         PRTUTF16 pu16SrcText = static_cast <PRTUTF16> (pv);
    203         size_t cwSrcLen = cb / 2;
    204         size_t cwDestLen = 0;
     202        PRTUTF16 pwszSrcText = static_cast <PRTUTF16> (pv);
     203        size_t cwSrc = cb / 2;
     204        size_t cwDest = 0;
    205205        /* How long will the converted text be? */
    206         rc = vboxClipboardUtf16GetLinSize (pu16SrcText, cwSrcLen, &cwDestLen);
     206        rc = vboxClipboardUtf16GetLinSize (pwszSrcText, cwSrc, &cwDest);
    207207        if (RT_FAILURE (rc))
    208208        {
     
    211211        }
    212212        /* Empty clipboard? Not critical */
    213         if (cwDestLen == 0)
     213        if (cwDest == NULL)
    214214        {
    215215            Log (("writeToPasteboard: received empty clipboard data from the guest, returning false.\n"));
     
    217217        }
    218218        /* Allocate the necessary memory */
    219         PRTUTF16 pu16DestText = static_cast <PRTUTF16> (RTMemAlloc (cwDestLen * 2));
    220         if (pu16DestText == 0)
    221         {
    222             Log (("writeToPasteboard: failed to allocate %d bytes\n", cwDestLen * 2));
     219        PRTUTF16 pwszDestText = static_cast <PRTUTF16> (RTMemAlloc (cwDest * 2));
     220        if (pwszDestText == NULL)
     221        {
     222            Log (("writeToPasteboard: failed to allocate %d bytes\n", cwDest * 2));
    223223            return VERR_NO_MEMORY;
    224224        }
    225225        /* Convert the EOL */
    226         rc = vboxClipboardUtf16WinToLin (pu16SrcText, cwSrcLen, pu16DestText, cwDestLen);
     226        rc = vboxClipboardUtf16WinToLin (pwszSrcText, cwSrc, pwszDestText, cwDest);
    227227        if (RT_FAILURE (rc))
    228228        {
    229229            Log (("writeToPasteboard: clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Vrc.  Abandoning.\n", rc));
    230             RTMemFree (pu16DestText);
     230            RTMemFree (pwszDestText);
    231231            AssertRCReturn (rc, rc);
    232232        }
     
    237237        /* Create a CData object which we could pass to the pasteboard */
    238238        if ((textData = CFDataCreate (kCFAllocatorDefault,
    239                                       reinterpret_cast<UInt8*> (pu16DestText), cwDestLen * 2)))
     239                                      reinterpret_cast<UInt8*> (pwszDestText), cwDest * 2)))
    240240        {
    241241            /* Put the Utf-16 version to the pasteboard */
     
    245245        }
    246246        /* Create a Utf-8 version */
    247         char *pu8DestText;
    248         rc = RTUtf16ToUtf8 (pu16DestText, &pu8DestText);
     247        char *pszDestText;
     248        rc = RTUtf16ToUtf8 (pwszDestText, &pszDestText);
    249249        if (RT_SUCCESS (rc))
    250250        {
    251251            /* Create a CData object which we could pass to the pasteboard */
    252252            if ((textData = CFDataCreate (kCFAllocatorDefault,
    253                                           reinterpret_cast<UInt8*> (pu8DestText), RTUtf16CalcUtf8Len (pu16DestText))))
     253                                          reinterpret_cast<UInt8*> (pszDestText), RTUtf16CalcUtf8Len (pwszDestText)))) /** @todo r=bird: why not strlen(pszDestText)? */
    254254            {
    255255                /* Put the Utf-8 version to the pasteboard */
     
    258258                                         textData, 0);
    259259            }
    260             RTStrFree (pu8DestText);
    261         }
    262 
    263         RTMemFree (pu16DestText);
     260            RTStrFree (pszDestText);
     261        }
     262
     263        RTMemFree (pwszDestText);
    264264        rc = VINF_SUCCESS;
    265265    }
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.h

    • Property eol-style set to native
    r7073 r7117  
     1/* $Id$ */
    12/** @file
    2  *
    3  * Shared Clipboard:
    4  * Mac OS X host implementation.
     3 * Shared Clipboard: Mac OS X host implementation.
    54 */
    65
     
    1716 */
    1817
    19 #ifndef __DARWIN_PASTEBOARD_H
    20 #define __DARWIN_PASTEBOARD_H
     18#ifndef ___DARWIN_PASTEBOARD_H
     19#define ___DARWIN_PASTEBOARD_H
    2120
    2221typedef struct OpaquePasteboardRef;
    2322typedef struct OpaquePasteboardRef *PasteboardRef;
    2423
    25 int initPasteboard (PasteboardRef &pPasteboard);
    26 void destroyPasteboard (PasteboardRef &pPasteboard);
     24int initPasteboard (PasteboardRef *pPasteboardRef);
     25void destroyPasteboard (PasteboardRef *pPasteboardRef);
    2726
    28 int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t &u32Formats);
    29 int readFromPasteboard (PasteboardRef pPasteboard, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual);
    30 int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t u32Format);
     27int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats);
     28int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual);
     29int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat);
    3130
    32 #endif /* __DARWIN-PASTEBOARD_H */
     31#endif
    3332
  • trunk/src/VBox/HostServices/SharedClipboard/darwin.cpp

    • Property eol-style set to native
    r7073 r7117  
     1/* $Id$ */
    12/** @file
    2  *
    3  * Shared Clipboard:
    4  * Mac OS X host.
     3 * Shared Clipboard: Mac OS X host.
    54 */
    65
     
    2423#include "VBoxClipboard.h"
    2524/* We do the work in a separate cpp file because
    26  * of the conflicting typedef "OSType". This is 
     25 * of the conflicting typedef "OSType". This is
    2726 * defined in Carbon and in VBox/ostypes.h also. */
    2827#include "darwin-pasteboard.h"
     
    3130struct _VBOXCLIPBOARDCONTEXT
    3231{
    33     /* We have a separate thread to poll for new clipboard content */
     32    /** We have a separate thread to poll for new clipboard content */
    3433    RTTHREAD thread;
    35     bool     fTerminate;
    36 
    37     /* The reference to the current pasteboard */
     34    bool volatile fTerminate;
     35
     36    /** The reference to the current pasteboard */
    3837    PasteboardRef pasteboard;
    3938
     
    4140};
    4241
    43 /* Only one client is supported. There seems to be no need for more clients. */
     42/** Only one client is supported. There seems to be no need for more clients. */
    4443static VBOXCLIPBOARDCONTEXT g_ctx;
    4544
     
    4948        return VINF_SUCCESS;
    5049
    51     uint32_t u32Formats = 0;
     50    uint32_t fFormats = 0;
    5251    /* Retrieve the formats currently in the clipboard and supported by vbox */
    53     int rc = queryPasteboardFormats (pCtx->pasteboard, u32Formats);
    54 
    55     if (u32Formats > 0)
    56     {
    57         vboxSvcClipboardReportMsg (pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, u32Formats);
    58         Log (("vboxClipboardChanged u32Formats %02X\n", u32Formats));
     52    int rc = queryPasteboardFormats (pCtx->pasteboard, fFormats);
     53
     54    if (fFormats > 0)
     55    {
     56        vboxSvcClipboardReportMsg (pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, fFormats);
     57        Log (("vboxClipboardChanged fFormats %02X\n", fFormats));
    5958    }
    6059
     
    6564{
    6665    Log (("vboxClipboardThread: starting clipboard thread\n"));
    67    
     66
    6867    AssertReturn (VALID_PTR (pvUser), VERR_INVALID_PARAMETER);
    6968
     
    9493    g_ctx.fTerminate = false;
    9594
    96     rc = initPasteboard (g_ctx.pasteboard);
    97 
    98     rc = RTThreadCreate (&g_ctx.thread, vboxClipboardThread, &g_ctx, 0, 
     95    rc = initPasteboard (&g_ctx.pasteboard);
     96
     97    rc = RTThreadCreate (&g_ctx.thread, vboxClipboardThread, &g_ctx, 0,
    9998                         RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP");
    10099
     
    109108    g_ctx.fTerminate = true;
    110109
    111     destroyPasteboard (g_ctx.pasteboard);
     110    destroyPasteboard (&g_ctx.pasteboard);
    112111
    113112    /* Wait for the clipboard thread to terminate. */
     
    148147    /* Sync the host clipboard content with the client. */
    149148    int rc = vboxClipboardChanged (pClient->pCtx);
    150    
     149
    151150    return rc;
    152151}
     
    158157{
    159158    Log (("vboxClipboardDisconnect\n"));
    160    
     159
    161160    g_ctx.pClient = NULL;
    162161}
     
    179178    }
    180179
    181     vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, 
     180    vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
    182181                               u32Formats);
    183182}
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