Changeset 7117 in vbox
- Timestamp:
- Feb 25, 2008 3:54:42 PM (17 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedClipboard
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/Makefile.kmk
r7073 r7117 35 35 VBoxSharedClipboard_SOURCES.darwin = \ 36 36 darwin.cpp \ 37 38 37 clipboard-helper.cpp \ 38 darwin-pasteboard.cpp 39 39 if1of ($(BUILD_TARGET),linux solaris) 40 40 ifndef VBOX_HEADLESS 41 41 VBoxSharedClipboard_SOURCES += \ 42 43 linux.cpp42 clipboard-helper.cpp \ 43 linux.cpp 44 44 else 45 45 VBoxSharedClipboard_SOURCES += \ 46 linux-stub.cpp46 linux-stub.cpp 47 47 endif 48 48 endif -
trunk/src/VBox/HostServices/SharedClipboard/clipboard-helper.cpp
-
Property eol-style
set to
native
r7073 r7117 1 /* $Id$ */ 1 2 /** @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. 5 4 */ 6 5 … … 21 20 #include <iprt/assert.h> 22 21 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 24 int vboxClipboardUtf16GetWinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest) 24 25 { 25 26 size_t cwDest, i; 26 27 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) 35 33 { 36 34 LogRel(("vboxClipboardUtf16GetWinSize: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n")); 37 AssertReturn(p u16Src[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);35 AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER); 38 36 } 39 37 if (cwSrc == 0) … … 46 44 /* Calculate the size of the destination text string. */ 47 45 /* Is this Utf16 or Utf16-LE? */ 48 for (i = (p u16Src[0] == UTF16LEMARKER ? 1 : 0); i < cwSrc; ++i, ++cwDest)49 { 50 if (p u16Src[i] == LINEFEED)46 for (i = (pwszSrc[0] == UTF16LEMARKER ? 1 : 0); i < cwSrc; ++i, ++cwDest) 47 { 48 if (pwszSrc[i] == LINEFEED) 51 49 ++cwDest; 52 if (p u16Src[i] == 0)50 if (pwszSrc[i] == 0) 53 51 { 54 52 /* Don't count this, as we do so below. */ … … 63 61 } 64 62 65 int vboxClipboardUtf16LinToWin(PRTUTF16 p u16Src, size_t cwSrc, PRTUTF16 pu16Dest,63 int vboxClipboardUtf16LinToWin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, 66 64 size_t cwDest) 67 65 { 68 66 size_t i, j; 69 LogFlowFunc(("p u16Src=%.*ls, cwSrc=%u\n", cwSrc, pu16Src, cwSrc));70 if (!VALID_PTR(p u16Src) || !VALID_PTR(pu16Dest))71 { 72 LogRel(("vboxClipboardUtf16LinToWin: received an invalid pointer, p u16Src=%p, pu16Dest=%p, returning VERR_INVALID_PARAMETER\n", pu16Src, pu16Dest));73 AssertReturn(VALID_PTR(p u16Src) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);74 } 75 /* We only take little endian Utf16 */ 76 if (p u16Src[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) 77 75 { 78 76 LogRel(("vboxClipboardUtf16LinToWin: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n")); 79 AssertReturn(p u16Src[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);77 AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER); 80 78 } 81 79 if (cwSrc == 0) … … 91 89 } 92 90 /* Don't copy the endian marker. */ 93 for (i = (p u16Src[0] == UTF16LEMARKER ? 1 : 0), j = 0; i < cwSrc; ++i, ++j)91 for (i = (pwszSrc[0] == UTF16LEMARKER ? 1 : 0), j = 0; i < cwSrc; ++i, ++j) 94 92 { 95 93 /* Don't copy the null byte, as we add it below. */ 96 if (p u16Src[i] == 0)94 if (pwszSrc[i] == 0) 97 95 break; 98 96 if (j == cwDest) … … 101 99 return VERR_BUFFER_OVERFLOW; 102 100 } 103 if (p u16Src[i] == LINEFEED)101 if (pwszSrc[i] == LINEFEED) 104 102 { 105 103 pu16Dest[j] = CARRIAGERETURN; … … 111 109 } 112 110 } 113 pu16Dest[j] = p u16Src[i];111 pu16Dest[j] = pwszSrc[i]; 114 112 } 115 113 /* Add the trailing null. */ … … 124 122 } 125 123 126 int vboxClipboardUtf16GetLinSize(PRTUTF16 p u16Src, size_t cwSrc, size_t *pcwDest)124 int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest) 127 125 { 128 126 size_t cwDest; 129 127 130 LogFlowFunc(("p u16Src=%.*ls, cwSrc=%u\n", cwSrc, pu16Src, cwSrc));131 if (!VALID_PTR(p u16Src))132 { 133 LogRel(("vboxClipboardUtf16GetLinSize: received an invalid Utf16 string %p. Returning VERR_INVALID_PARAMETER.\n", p u16Src));134 AssertReturn(VALID_PTR(p u16Src), VERR_INVALID_PARAMETER);135 } 136 /* We only take little endian Utf16 */ 137 if (p u16Src[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) 138 136 { 139 137 LogRel(("vboxClipboardUtf16GetLinSize: received a big endian Utf16 string. Returning VERR_INVALID_PARAMETER.\n")); 140 AssertReturn(p u16Src[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER);138 AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER); 141 139 } 142 140 if (cwSrc == 0) … … 148 146 /* Calculate the size of the destination text string. */ 149 147 /* Is this Utf16 or Utf16-LE? */ 150 if (p u16Src[0] == UTF16LEMARKER)148 if (pwszSrc[0] == UTF16LEMARKER) 151 149 cwDest = 0; 152 150 else … … 155 153 { 156 154 if ( (i + 1 < cwSrc) 157 && (p u16Src[i] == CARRIAGERETURN)158 && (p u16Src[i + 1] == LINEFEED))155 && (pwszSrc[i] == CARRIAGERETURN) 156 && (pwszSrc[i + 1] == LINEFEED)) 159 157 { 160 158 ++i; 161 159 } 162 if (p u16Src[i] == 0)160 if (pwszSrc[i] == 0) 163 161 { 164 162 break; … … 172 170 } 173 171 174 int vboxClipboardUtf16WinToLin(PRTUTF16 p u16Src, size_t cwSrc, PRTUTF16 pu16Dest,172 int vboxClipboardUtf16WinToLin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, 175 173 size_t cwDest) 176 174 { 177 175 size_t cwDestPos; 178 176 179 LogFlowFunc(("p u16Src=%.*ls, cwSrc=%u, pu16Dest=%p, cwDest=%u\n",180 cwSrc, p u16Src, cwSrc, pu16Dest, cwDest));177 LogFlowFunc(("pwszSrc=%.*ls, cwSrc=%u, pu16Dest=%p, cwDest=%u\n", 178 cwSrc, pwszSrc, cwSrc, pu16Dest, cwDest)); 181 179 /* A buffer of size 0 may not be an error, but it is not a good idea either. */ 182 180 Assert(cwDest > 0); 183 if (!VALID_PTR(p u16Src) || !VALID_PTR(pu16Dest))184 { 185 LogRel(("vboxClipboardUtf16WinToLin: received an invalid ptr, p u16Src=%p, pu16Dest=%p, returning VERR_INVALID_PARAMETER\n", pu16Src, pu16Dest));186 AssertReturn(VALID_PTR(p u16Src) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);187 } 188 /* We only take little endian Utf16 */ 189 if (p u16Src[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) 190 188 { 191 189 LogRel(("vboxClipboardUtf16WinToLin: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n")); … … 204 202 } 205 203 /* Prepend the Utf16 byte order marker if it is missing. */ 206 if (p u16Src[0] == UTF16LEMARKER)204 if (pwszSrc[0] == UTF16LEMARKER) 207 205 { 208 206 cwDestPos = 0; … … 215 213 for (size_t i = 0; i < cwSrc; ++i, ++cwDestPos) 216 214 { 217 if (p u16Src[i] == 0)215 if (pwszSrc[i] == 0) 218 216 { 219 217 break; … … 225 223 } 226 224 if ( (i + 1 < cwSrc) 227 && (p u16Src[i] == CARRIAGERETURN)228 && (p u16Src[i + 1] == LINEFEED))225 && (pwszSrc[i] == CARRIAGERETURN) 226 && (pwszSrc[i + 1] == LINEFEED)) 229 227 { 230 228 ++i; 231 229 } 232 pu16Dest[cwDestPos] = p u16Src[i];230 pu16Dest[cwDestPos] = pwszSrc[i]; 233 231 } 234 232 /* Terminating zero */ -
Property eol-style
set to
-
trunk/src/VBox/HostServices/SharedClipboard/clipboard-helper.h
-
Property eol-style
set to
native
r7073 r7117 1 /* $Id$ */ 1 2 /** @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. 5 4 */ 6 5 … … 17 16 */ 18 17 19 #ifndef __ CLIPBOARD_HELPER_H20 #define __ CLIPBOARD_HELPER_H18 #ifndef ___CLIPBOARD_HELPER_H 19 #define ___CLIPBOARD_HELPER_H 21 20 22 21 #include <iprt/string.h> … … 40 39 * @returns RT error code 41 40 * 42 * @param p u16Src The source Utf16 string41 * @param pwszSrc The source Utf16 string 43 42 * @param cwSrc The length in 16 bit words of the source string 44 43 * @retval pcwDest The length of the destination string in 16 bit words 45 44 */ 46 int vboxClipboardUtf16GetWinSize(PRTUTF16 p u16Src, size_t cwSrc, size_t *pcwDest);45 int vboxClipboardUtf16GetWinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest); 47 46 48 47 /** … … 52 51 * @returns VBox status code 53 52 * 54 * @param p u16Src Source Utf16 text to convert53 * @param pwszSrc Source Utf16 text to convert 55 54 * @param cwSrc Size of the source text in 16 bit words 56 55 * @retval pu16Dest Buffer to store the converted text to. 57 56 * @retval pcwDest Size of the buffer for the converted text in 16 bit words 58 57 */ 59 int vboxClipboardUtf16LinToWin(PRTUTF16 p u16Src, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest);58 int vboxClipboardUtf16LinToWin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest); 60 59 61 60 /** … … 65 64 * @returns RT status code 66 65 * 67 * @param p u16Src The source Utf16 string66 * @param pwszSrc The source Utf16 string 68 67 * @param cwSrc The length in 16 bit words of the source string 69 68 * @retval pcwDest The length of the destination string in 16 bit words 70 69 */ 71 int vboxClipboardUtf16GetLinSize(PRTUTF16 p u16Src, size_t cwSrc, size_t *pcwDest);70 int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest); 72 71 73 72 /** … … 77 76 * @returns VBox status code 78 77 * 79 * @param p u16Src Text to convert78 * @param pwszSrc Text to convert 80 79 * @param cwSrc Size of the source text in 16 bit words 81 80 * @param pu16Dest The buffer to store the converted text to 82 81 * @param cwDest The size of the buffer for the destination text in 16 bit words 83 82 */ 84 int vboxClipboardUtf16WinToLin(PRTUTF16 p u16Src, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest);83 int vboxClipboardUtf16WinToLin(PRTUTF16 pwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest); 85 84 86 #endif /* __CLIPBOARD_HELPER_H */85 #endif 87 86 -
Property eol-style
set to
-
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
-
Property eol-style
set to
native
r7073 r7117 1 /* $Id$ */ 1 2 /** @file 2 * 3 * Shared Clipboard: 4 * Mac OS X host implementation. 3 * Shared Clipboard: Mac OS X host implementation. 5 4 */ 6 5 … … 17 16 */ 18 17 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? 20 20 #define VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT 0x01 21 21 #define VBOX_SHARED_CLIPBOARD_FMT_BITMAP 0x02 … … 34 34 //#define SHOW_CLIPBOARD_CONTENT 35 35 36 int initPasteboard (PasteboardRef &pPasteboard)36 int initPasteboard (PasteboardRef *pPasteboardRef) 37 37 { 38 38 int rc = VINF_SUCCESS; 39 39 40 if (PasteboardCreate (kPasteboardClipboard, &pPasteboard))40 if (PasteboardCreate (kPasteboardClipboard, pPasteboardRef)) 41 41 rc = VERR_NOT_SUPPORTED; 42 42 … … 44 44 } 45 45 46 void destroyPasteboard (PasteboardRef &pPasteboard)47 { 48 CFRelease ( pPasteboard);49 pPasteboard= NULL;50 } 51 52 int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t &u32Formats)46 void destroyPasteboard (PasteboardRef *pPasteboardRef) 47 { 48 CFRelease (*pPasteboardRef); 49 *pPasteboardRef = NULL; 50 } 51 52 int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t pfFormats) 53 53 { 54 54 Log (("queryPasteboardFormats\n")); … … 74 74 if (!(err = PasteboardGetItemIdentifier (pPasteboard, 1, &itemID))) 75 75 { 76 /* Retrieve all flavors in the pasteboard, maybe there 76 /* Retrieve all flavors in the pasteboard, maybe there 77 77 * is something we can use. */ 78 78 CFArrayRef flavorTypeArray; … … 91 91 { 92 92 Log (("Unicode flavor detected.\n")); 93 u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;93 *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT; 94 94 } 95 95 } … … 103 103 } 104 104 105 int readFromPasteboard (PasteboardRef pPasteboard, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual)106 { 107 Log (("readFromPastboard: u32Format = %02X\n", u32Format));105 int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual) 106 { 107 Log (("readFromPastboard: fFormat = %02X\n", fFormat)); 108 108 109 109 OSStatus err = noErr; … … 124 124 { 125 125 /* The guest request unicode */ 126 if ( u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)126 if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 127 127 { 128 128 CFDataRef outData; 129 PRTUTF16 p u16Tmp = 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. 131 131 * Has to be investigated. */ 132 132 #if 0 … … 135 135 { 136 136 Log (("Clipboard content is utf-16\n")); 137 rc = RTUtf16DupEx (&p u16Tmp, (RTUTF16*)CFDataGetBytePtr (outData), 0);137 rc = RTUtf16DupEx (&pwszTmp, (PRTUTF16)CFDataGetBytePtr (outData), 0); 138 138 } 139 139 /* Second try is utf-8 */ 140 else 141 #endif 140 else 141 #endif 142 142 if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf8-plain-text"), &outData))) 143 143 { 144 144 Log (("readFromPastboard: clipboard content is utf-8\n")); 145 rc = RTStrToUtf16 ((const char*)CFDataGetBytePtr (outData), &p u16Tmp);146 } 147 if (p u16Tmp)145 rc = RTStrToUtf16 ((const char*)CFDataGetBytePtr (outData), &pwszTmp); 146 } 147 if (pwszTmp) 148 148 { 149 149 /* Check how much longer will the converted text will be. */ 150 size_t cwSrc Len = RTUtf16Len (pu16Tmp);151 size_t cwDest Len;152 rc = vboxClipboardUtf16GetWinSize (p u16Tmp, cwSrcLen, &cwDestLen);150 size_t cwSrc = RTUtf16Len (pwszTmp); 151 size_t cwDest; 152 rc = vboxClipboardUtf16GetWinSize (pwszTmp, cwSrc, &cwDest); 153 153 if (RT_FAILURE (rc)) 154 154 { 155 RTUtf16Free (p u16Tmp);155 RTUtf16Free (pwszTmp); 156 156 Log (("readFromPastboard: clipboard conversion failed. vboxClipboardUtf16GetWinSize returned %Vrc. Abandoning.\n", rc)); 157 157 AssertRCReturn (rc, rc); 158 158 } 159 159 /* Set the actually needed data size */ 160 *pcbActual = cwDest Len* 2;160 *pcbActual = cwDest * 2; 161 161 /* Return success state */ 162 162 rc = VINF_SUCCESS; … … 164 164 if (*pcbActual <= cb) 165 165 { 166 rc = vboxClipboardUtf16LinToWin (p u16Tmp, RTUtf16Len (pu16Tmp), static_cast <PRTUTF16> (pv), cb / 2);166 rc = vboxClipboardUtf16LinToWin (pwszTmp, RTUtf16Len (pwszTmp), static_cast <PRTUTF16> (pv), cb / 2); 167 167 if (RT_FAILURE (rc)) 168 168 { 169 RTUtf16Free (p u16Tmp);169 RTUtf16Free (pwszTmp); 170 170 Log (("readFromPastboard: clipboard conversion failed. vboxClipboardUtf16LinToWin() returned %Vrc. Abandoning.\n", rc)); 171 171 AssertRCReturn (rc, rc); … … 176 176 } 177 177 /* Free the temp string */ 178 RTUtf16Free (p u16Tmp);178 RTUtf16Free (pwszTmp); 179 179 } 180 180 } … … 185 185 } 186 186 187 int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t u32Format)188 { 189 Log (("writeToPasteboard: u32Format = %02X\n", u32Format));190 187 int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat) 188 { 189 Log (("writeToPasteboard: fFormat = %02X\n", fFormat)); 190 191 191 /* Clear the pastboard */ 192 192 if (PasteboardClear (pPasteboard)) … … 198 198 int rc = VERR_NOT_SUPPORTED; 199 199 /* Handle the unicode text */ 200 if ( u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)200 if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 201 201 { 202 PRTUTF16 p u16SrcText = static_cast <PRTUTF16> (pv);203 size_t cwSrc Len= cb / 2;204 size_t cwDest Len= 0;202 PRTUTF16 pwszSrcText = static_cast <PRTUTF16> (pv); 203 size_t cwSrc = cb / 2; 204 size_t cwDest = 0; 205 205 /* How long will the converted text be? */ 206 rc = vboxClipboardUtf16GetLinSize (p u16SrcText, cwSrcLen, &cwDestLen);206 rc = vboxClipboardUtf16GetLinSize (pwszSrcText, cwSrc, &cwDest); 207 207 if (RT_FAILURE (rc)) 208 208 { … … 211 211 } 212 212 /* Empty clipboard? Not critical */ 213 if (cwDest Len == 0)213 if (cwDest == NULL) 214 214 { 215 215 Log (("writeToPasteboard: received empty clipboard data from the guest, returning false.\n")); … … 217 217 } 218 218 /* Allocate the necessary memory */ 219 PRTUTF16 p u16DestText = static_cast <PRTUTF16> (RTMemAlloc (cwDestLen* 2));220 if (p u16DestText == 0)221 { 222 Log (("writeToPasteboard: failed to allocate %d bytes\n", cwDest Len* 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)); 223 223 return VERR_NO_MEMORY; 224 224 } 225 225 /* Convert the EOL */ 226 rc = vboxClipboardUtf16WinToLin (p u16SrcText, cwSrcLen, pu16DestText, cwDestLen);226 rc = vboxClipboardUtf16WinToLin (pwszSrcText, cwSrc, pwszDestText, cwDest); 227 227 if (RT_FAILURE (rc)) 228 228 { 229 229 Log (("writeToPasteboard: clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Vrc. Abandoning.\n", rc)); 230 RTMemFree (p u16DestText);230 RTMemFree (pwszDestText); 231 231 AssertRCReturn (rc, rc); 232 232 } … … 237 237 /* Create a CData object which we could pass to the pasteboard */ 238 238 if ((textData = CFDataCreate (kCFAllocatorDefault, 239 reinterpret_cast<UInt8*> (p u16DestText), cwDestLen* 2)))239 reinterpret_cast<UInt8*> (pwszDestText), cwDest * 2))) 240 240 { 241 241 /* Put the Utf-16 version to the pasteboard */ … … 245 245 } 246 246 /* Create a Utf-8 version */ 247 char *p u8DestText;248 rc = RTUtf16ToUtf8 (p u16DestText, &pu8DestText);247 char *pszDestText; 248 rc = RTUtf16ToUtf8 (pwszDestText, &pszDestText); 249 249 if (RT_SUCCESS (rc)) 250 250 { 251 251 /* Create a CData object which we could pass to the pasteboard */ 252 252 if ((textData = CFDataCreate (kCFAllocatorDefault, 253 reinterpret_cast<UInt8*> (p u8DestText), RTUtf16CalcUtf8Len (pu16DestText))))253 reinterpret_cast<UInt8*> (pszDestText), RTUtf16CalcUtf8Len (pwszDestText)))) /** @todo r=bird: why not strlen(pszDestText)? */ 254 254 { 255 255 /* Put the Utf-8 version to the pasteboard */ … … 258 258 textData, 0); 259 259 } 260 RTStrFree (p u8DestText);261 } 262 263 RTMemFree (p u16DestText);260 RTStrFree (pszDestText); 261 } 262 263 RTMemFree (pwszDestText); 264 264 rc = VINF_SUCCESS; 265 265 } -
Property eol-style
set to
-
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.h
-
Property eol-style
set to
native
r7073 r7117 1 /* $Id$ */ 1 2 /** @file 2 * 3 * Shared Clipboard: 4 * Mac OS X host implementation. 3 * Shared Clipboard: Mac OS X host implementation. 5 4 */ 6 5 … … 17 16 */ 18 17 19 #ifndef __ DARWIN_PASTEBOARD_H20 #define __ DARWIN_PASTEBOARD_H18 #ifndef ___DARWIN_PASTEBOARD_H 19 #define ___DARWIN_PASTEBOARD_H 21 20 22 21 typedef struct OpaquePasteboardRef; 23 22 typedef struct OpaquePasteboardRef *PasteboardRef; 24 23 25 int initPasteboard (PasteboardRef &pPasteboard);26 void destroyPasteboard (PasteboardRef &pPasteboard);24 int initPasteboard (PasteboardRef *pPasteboardRef); 25 void destroyPasteboard (PasteboardRef *pPasteboardRef); 27 26 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);27 int queryPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats); 28 int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual); 29 int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat); 31 30 32 #endif /* __DARWIN-PASTEBOARD_H */31 #endif 33 32 -
Property eol-style
set to
-
trunk/src/VBox/HostServices/SharedClipboard/darwin.cpp
-
Property eol-style
set to
native
r7073 r7117 1 /* $Id$ */ 1 2 /** @file 2 * 3 * Shared Clipboard: 4 * Mac OS X host. 3 * Shared Clipboard: Mac OS X host. 5 4 */ 6 5 … … 24 23 #include "VBoxClipboard.h" 25 24 /* 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 27 26 * defined in Carbon and in VBox/ostypes.h also. */ 28 27 #include "darwin-pasteboard.h" … … 31 30 struct _VBOXCLIPBOARDCONTEXT 32 31 { 33 /* We have a separate thread to poll for new clipboard content */32 /** We have a separate thread to poll for new clipboard content */ 34 33 RTTHREAD thread; 35 bool 36 37 /* The reference to the current pasteboard */34 bool volatile fTerminate; 35 36 /** The reference to the current pasteboard */ 38 37 PasteboardRef pasteboard; 39 38 … … 41 40 }; 42 41 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. */ 44 43 static VBOXCLIPBOARDCONTEXT g_ctx; 45 44 … … 49 48 return VINF_SUCCESS; 50 49 51 uint32_t u32Formats = 0;50 uint32_t fFormats = 0; 52 51 /* 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)); 59 58 } 60 59 … … 65 64 { 66 65 Log (("vboxClipboardThread: starting clipboard thread\n")); 67 66 68 67 AssertReturn (VALID_PTR (pvUser), VERR_INVALID_PARAMETER); 69 68 … … 94 93 g_ctx.fTerminate = false; 95 94 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, 99 98 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 100 99 … … 109 108 g_ctx.fTerminate = true; 110 109 111 destroyPasteboard ( g_ctx.pasteboard);110 destroyPasteboard (&g_ctx.pasteboard); 112 111 113 112 /* Wait for the clipboard thread to terminate. */ … … 148 147 /* Sync the host clipboard content with the client. */ 149 148 int rc = vboxClipboardChanged (pClient->pCtx); 150 149 151 150 return rc; 152 151 } … … 158 157 { 159 158 Log (("vboxClipboardDisconnect\n")); 160 159 161 160 g_ctx.pClient = NULL; 162 161 } … … 179 178 } 180 179 181 vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, 180 vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, 182 181 u32Formats); 183 182 } -
Property eol-style
set to
Note:
See TracChangeset
for help on using the changeset viewer.