Changeset 3895 in vbox
- Timestamp:
- Jul 27, 2007 7:17:56 AM (17 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/xclient/clipboard.cpp
r3332 r3895 26 26 #define USE_UTF8 27 27 #define USE_CTEXT 28 #define USE_LATIN129 28 30 29 #define LOG_GROUP LOG_GROUP_HGCM … … 81 80 INVALID = 0, 82 81 TARGETS, 83 LATIN1,84 82 CTEXT, 85 83 UTF8, … … 660 658 break; 661 659 case UTF8: 662 case LATIN1:663 660 { 664 661 /* If we are given broken Utf-8, we treat it as Latin1. Is this acceptable? */ … … 1242 1239 *pcLenReturn = property.nitems; 1243 1240 *piFormatReturn = property.format; 1244 LogFlowFunc(("rc = true\n"));1245 return true;1246 }1247 1248 /**1249 * Satisfy a request from the guest to convert the clipboard text to Latin1.1250 *1251 * @returns true if we successfully convert the data to the format requested, false otherwise.1252 *1253 * @param atomTypeReturn The type of the data we are returning1254 * @param pValReturn A pointer to the data we are returning. This should be to memory1255 * allocated by XtMalloc, which will be freed by the toolkit later1256 * @param pcLenReturn The length of the data we are returning1257 * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning1258 */1259 static Boolean vboxClipboardConvertLatin1(Atom *atomTypeReturn, XtPointer *pValReturn,1260 unsigned long *pcLenReturn, int *piFormatReturn)1261 {1262 enum { LINEFEED = 0xa, CARRIAGERETURN = 0xd };1263 PRTUTF16 pu16HostText;1264 unsigned cbHostText, cwHostText, cbGuestPos = 0, cbGuestText;1265 unsigned char *pcGuestText;1266 int rc;1267 1268 LogFlowFunc(("\n"));1269 /* Get the host UTF16 data */1270 rc = vboxClipboardReadHostData(VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT,1271 reinterpret_cast<void **>(&pu16HostText), &cbHostText);1272 if ((rc != VINF_SUCCESS) || cbHostText == 0)1273 {1274 Log (("vboxClipboardConvertUtf16: vboxClipboardReadHostData returned %Vrc, %d bytes of data\n", rc, cbGuestText));1275 g_ctx.hostFormats = 0;1276 LogFlowFunc(("rc = false\n"));1277 return false;1278 }1279 cwHostText = cbHostText / 2;1280 cbGuestText = cwHostText;1281 pcGuestText = reinterpret_cast<unsigned char *>(XtMalloc(cbGuestText));1282 if (pcGuestText == 0)1283 {1284 RTMemFree(reinterpret_cast<void *>(pu16HostText));1285 LogFlowFunc(("rc = false\n"));1286 return false;1287 }1288 for (unsigned i = 0; i < cwHostText; ++i, ++cbGuestPos)1289 {1290 if ( (i + 1 < cwHostText)1291 && (pu16HostText[i] == CARRIAGERETURN)1292 && (pu16HostText[i + 1] == LINEFEED))1293 ++i;1294 if (pu16HostText[i] < 256)1295 pcGuestText[cbGuestPos] = pu16HostText[i];1296 else1297 /* Any better ideas as to how to do this? */1298 pcGuestText[cbGuestPos] = '.';1299 }1300 Log (("vboxClipboardConvertLatin1: returning Latin-1, original text is %.*ls\n", cwHostText,1301 pu16HostText));1302 Log (("vboxClipboardConvertLatin1: converted text is %.*s\n", cbGuestPos,1303 pcGuestText));1304 RTMemFree(reinterpret_cast<void *>(pu16HostText));1305 *atomTypeReturn = XA_STRING;1306 *pValReturn = reinterpret_cast<XtPointer>(pcGuestText);1307 *pcLenReturn = cbGuestPos;1308 *piFormatReturn = 8;1309 1241 LogFlowFunc(("rc = true\n")); 1310 1242 return true; … … 1380 1312 case CTEXT: 1381 1313 rc = vboxClipboardConvertCText(atomTypeReturn, pValReturn, pcLenReturn, piFormatReturn); 1382 LogFlowFunc(("rc=%d\n", rc));1383 return rc;1384 case LATIN1:1385 rc = vboxClipboardConvertLatin1(atomTypeReturn, pValReturn, pcLenReturn, piFormatReturn);1386 1314 LogFlowFunc(("rc=%d\n", rc)); 1387 1315 return rc; … … 1720 1648 vboxClipboardAddFormat("text/plain;charset=utf-8", UTF8, 1721 1649 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1650 vboxClipboardAddFormat("STRING", UTF8, 1651 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1652 vboxClipboardAddFormat("TEXT", UTF8, 1653 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1654 vboxClipboardAddFormat("text/plain", UTF8, 1655 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1722 1656 #endif 1723 1657 #ifdef USE_CTEXT 1724 1658 vboxClipboardAddFormat("COMPOUND_TEXT", CTEXT, 1725 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1726 #endif1727 #ifdef USE_LATIN11728 vboxClipboardAddFormat("STRING", LATIN1,1729 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1730 vboxClipboardAddFormat("TEXT", LATIN1,1731 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1732 vboxClipboardAddFormat("text/plain", LATIN1,1733 1659 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1734 1660 #endif -
trunk/src/VBox/HostServices/SharedClipboard/linux.cpp
r3338 r3895 24 24 #define USE_UTF8 25 25 #define USE_CTEXT 26 #define USE_LATIN127 26 28 27 #include <vector> … … 50 49 #include <X11/Xproto.h> 51 50 52 #define USE_UTF1653 #define USE_UTF854 #define USE_CTEXT55 #define USE_LATIN156 57 51 /** The different clipboard formats which we support. */ 58 52 enum g_eClipboardFormats … … 60 54 INVALID = 0, 61 55 TARGETS, 62 LATIN1,63 56 CTEXT, 64 57 UTF8, … … 798 791 break; 799 792 case UTF8: 800 case LATIN1:801 793 { 802 794 /* If we are given broken Utf-8, we treat it as Latin1. Is this acceptable? */ … … 1007 999 vboxClipboardAddFormat("text/plain;charset=utf-8", UTF8, 1008 1000 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1001 vboxClipboardAddFormat("STRING", UTF8, 1002 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1003 vboxClipboardAddFormat("TEXT", UTF8, 1004 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1005 vboxClipboardAddFormat("text/plain", UTF8, 1006 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1009 1007 #endif 1010 1008 #ifdef USE_CTEXT 1011 1009 vboxClipboardAddFormat("COMPOUND_TEXT", CTEXT, 1012 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1013 #endif1014 #ifdef USE_LATIN11015 vboxClipboardAddFormat("STRING", LATIN1,1016 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1017 vboxClipboardAddFormat("TEXT", LATIN1,1018 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1019 vboxClipboardAddFormat("text/plain", LATIN1,1020 1010 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1021 1011 #endif … … 1375 1365 if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0)) 1376 1366 { 1377 LogRel (("vboxClipboardConvert Utf8: vboxClipboardReadDataFromClient returned %Vrc, %d bytes of data\n", rc, g_ctx.pClient->data.cb));1367 LogRel (("vboxClipboardConvertCText: vboxClipboardReadDataFromClient returned %Vrc, %d bytes of data\n", rc, g_ctx.pClient->data.cb)); 1378 1368 vboxClipboardEmptyGuestBuffer(); 1379 1369 return false; … … 1453 1443 *pcLenReturn = property.nitems; 1454 1444 *piFormatReturn = property.format; 1455 return true;1456 }1457 1458 1459 /**1460 * Satisfy a request from the host to convert the clipboard text to Latin1.1461 *1462 * @returns true if we successfully convert the data to the format requested, false otherwise.1463 *1464 * @param atomTypeReturn The type of the data we are returning1465 * @param pValReturn A pointer to the data we are returning. This should be to memory1466 * allocated by XtMalloc, which will be freed by the toolkit later1467 * @param pcLenReturn The length of the data we are returning1468 * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning1469 */1470 static Boolean vboxClipboardConvertLatin1(Atom *atomTypeReturn, XtPointer *pValReturn,1471 unsigned long *pcLenReturn, int *piFormatReturn)1472 {1473 PRTUTF16 pu16GuestText;1474 size_t cwGuestText, cbHostPos = 0;1475 unsigned char *pcHostText;1476 int rc;1477 1478 LogFlow (("vboxClipboardConvertLatin1 called\n"));1479 rc = vboxClipboardReadDataFromClient(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);1480 if (RT_FAILURE(rc) || (g_ctx.pClient->data.cb == 0))1481 {1482 Log (("vboxClipboardConvertLatin1: vboxClipboardReadDataFromClient returned %Vrc, %d bytes of data\n", rc, g_ctx.pClient->data.cb));1483 vboxClipboardEmptyGuestBuffer();1484 return false;1485 }1486 pu16GuestText = reinterpret_cast<PRTUTF16>(g_ctx.pClient->data.pv);1487 cwGuestText = g_ctx.pClient->data.cb / 2;1488 pcHostText = reinterpret_cast<unsigned char *>(XtMalloc(cwGuestText));1489 if (pcHostText == 0)1490 {1491 vboxClipboardEmptyGuestBuffer();1492 return false;1493 }1494 for (unsigned i = 0; i < cwGuestText; ++i, ++cbHostPos)1495 {1496 if ( (i + 1 < cwGuestText)1497 && (pu16GuestText[i] == CARRIAGERETURN)1498 && (pu16GuestText[i + 1] == LINEFEED))1499 ++i;1500 if (pu16GuestText[i] < 256)1501 pcHostText[cbHostPos] = pu16GuestText[i];1502 else1503 /* Any better ideas as to how to do this? */1504 pcHostText[cbHostPos] = '.';1505 }1506 Log (("vboxClipboardConvertLatin1: returning Latin-1, original text is %.*ls\n", cwGuestText,1507 pu16GuestText));1508 Log (("vboxClipboardConvertLatin1: converted text is %.*s\n", cbHostPos,1509 pcHostText));1510 vboxClipboardEmptyGuestBuffer();1511 *atomTypeReturn = XA_STRING;1512 *pValReturn = reinterpret_cast<XtPointer>(pcHostText);1513 *pcLenReturn = cbHostPos;1514 *piFormatReturn = 8;1515 1445 return true; 1516 1446 } … … 1582 1512 return vboxClipboardConvertCText(atomTypeReturn, pValReturn, pcLenReturn, 1583 1513 piFormatReturn); 1584 case LATIN1:1585 return vboxClipboardConvertLatin1(atomTypeReturn, pValReturn, pcLenReturn,1586 piFormatReturn);1587 1514 default: 1588 1515 Log(("vboxClipboardConvertProc: bad format\n"));
Note:
See TracChangeset
for help on using the changeset viewer.