Changeset 43812 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- Nov 6, 2012 4:15:44 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 81838
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r38904 r43812 63 63 TEXT, /* Treat this as Utf8, but it may really be ascii */ 64 64 CTEXT, 65 UTF8 65 UTF8, 66 BMP 66 67 }; 67 68 … … 88 89 { "TEXT", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 89 90 { "text/plain", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 90 { "COMPOUND_TEXT", CTEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT } 91 { "COMPOUND_TEXT", CTEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 92 { "image/bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 93 { "image/x-bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 94 { "image/x-MS-bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 95 /* TODO: Inkscape exports image/png but not bmp... */ 91 96 }; 92 97 … … 307 312 { 308 313 uint32_t u32VBoxFormats = clipVBoxFormatForX11Format(pCtx->X11TextFormat); 314 u32VBoxFormats |= clipVBoxFormatForX11Format(pCtx->X11BitmapFormat); 309 315 ClipReportX11Formats(pCtx->pFrontend, u32VBoxFormats); 310 316 } … … 383 389 384 390 /** 391 * Go through an array of X11 clipboard targets to see if they contain a bitmap 392 * format we can support, and if so choose the ones we prefer (e.g. we like 393 * BMP better than PNG because we don't have to convert). 394 * @param pCtx the clipboard backend context structure 395 * @param pTargets the list of targets 396 * @param cTargets the size of the list in @a pTargets 397 */ 398 static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx, 399 Atom *pTargets, 400 size_t cTargets) 401 { 402 CLIPX11FORMAT bestBitmapFormat = NIL_CLIPX11FORMAT; 403 CLIPFORMAT enmBestBitmapTarget = INVALID; 404 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 405 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 406 for (unsigned i = 0; i < cTargets; ++i) 407 { 408 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx->widget, 409 pTargets[i]); 410 if (format != NIL_CLIPX11FORMAT) 411 { 412 if ( (clipVBoxFormatForX11Format(format) 413 == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 414 && enmBestBitmapTarget < clipRealFormatForX11Format(format)) 415 { 416 enmBestBitmapTarget = clipRealFormatForX11Format(format); 417 bestBitmapFormat = format; 418 } 419 } 420 } 421 return bestBitmapFormat; 422 } 423 424 /** 385 425 * Go through an array of X11 clipboard targets to see if we can support any 386 426 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8 … … 396 436 AssertPtrReturnVoid(pTargets); 397 437 CLIPX11FORMAT bestTextFormat; 438 CLIPX11FORMAT bestBitmapFormat; 398 439 bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets); 399 440 if (pCtx->X11TextFormat != bestTextFormat) … … 412 453 } 413 454 pCtx->X11BitmapFormat = INVALID; /* not yet supported */ 455 bestBitmapFormat = clipGetBitmapFormatFromTargets(pCtx, pTargets, cTargets); 456 if (pCtx->X11BitmapFormat != bestBitmapFormat) 457 { 458 pCtx->X11BitmapFormat = bestBitmapFormat; 459 } 414 460 } 415 461 … … 1140 1186 RTMemFree(pv); 1141 1187 } 1188 else if ( (format == BMP) 1189 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)) 1190 { 1191 void *pv = NULL; 1192 uint32_t cb = 0; 1193 rc = clipReadVBoxClipboard(pCtx, 1194 VBOX_SHARED_CLIPBOARD_FMT_BITMAP, 1195 &pv, &cb); 1196 if (RT_SUCCESS(rc) && (cb == 0)) 1197 rc = VERR_NO_DATA; 1198 if (RT_SUCCESS(rc) && (format == BMP)) 1199 { 1200 /* Create a full BMP from it */ 1201 rc = vboxClipboardDibToBmp(pv, cb, (void **)pValReturn, 1202 (size_t *)pcLenReturn); 1203 } 1204 else 1205 rc = VERR_NOT_SUPPORTED; 1206 1207 if (RT_SUCCESS(rc)) 1208 { 1209 *atomTypeReturn = *atomTarget; 1210 *piFormatReturn = 8; 1211 } 1212 RTMemFree(pv); 1213 } 1142 1214 else 1143 1215 rc = VERR_NOT_SUPPORTED; … … 1475 1547 /** The text format we requested from X11 if we requested text */ 1476 1548 CLIPX11FORMAT mTextFormat; 1549 /** The bitmap format we requested from X11 if we requested bitmap */ 1550 CLIPX11FORMAT mBitmapFormat; 1477 1551 /** The clipboard context this request is associated with */ 1478 1552 CLIPBACKEND *mCtx; … … 1484 1558 1485 1559 /** 1486 * Convert the text obtained from the X11 clipboard to UTF-16LE with Windows 1487 * EOLs, place it in the buffer supplied and signal that data has arrived. 1560 * Convert the data obtained from the X11 clipboard to the required format, 1561 * place it in the buffer supplied and signal that data has arrived. 1562 * Convert the text obtained UTF-16LE with Windows EOLs. 1563 * Convert full BMP data to DIB format. 1488 1564 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1489 * the X11 clipboard contains a textformat we understand.1565 * the X11 clipboard contains a format we understand. 1490 1566 */ 1491 1567 static void clipConvertX11CB(Widget widget, XtPointer pClientData, … … 1495 1571 { 1496 1572 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pClientData; 1497 LogRelFlowFunc(("pReq->mFormat=%02X, pReq->mTextFormat=%u, pReq->mCtx=%p\n", 1498 pReq->mFormat, pReq->mTextFormat, pReq->mCtx)); 1573 LogRelFlowFunc(("pReq->mFormat=%02X, pReq->mTextFormat=%u, " 1574 "pReq->mBitmapFormat=%u, pReq->mCtx=%p\n", 1575 pReq->mFormat, pReq->mTextFormat, pReq->mBitmapFormat, 1576 pReq->mCtx)); 1499 1577 AssertPtr(pReq->mCtx); 1500 1578 Assert(pReq->mFormat != 0); /* sanity */ … … 1537 1615 } 1538 1616 } 1617 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 1618 { 1619 /* In which format is the clipboard data? */ 1620 switch (clipRealFormatForX11Format(pReq->mBitmapFormat)) 1621 { 1622 case BMP: 1623 { 1624 const void *pDib; 1625 size_t cbDibSize; 1626 rc = vboxClipboardBmpGetDib((const void *)pvSrc, cbSrc, 1627 &pDib, &cbDibSize); 1628 if (RT_SUCCESS(rc)) 1629 { 1630 pvDest = RTMemAlloc(cbDibSize); 1631 if (!pvDest) 1632 rc = VERR_NO_MEMORY; 1633 else 1634 { 1635 memcpy(pvDest, pDib, cbDibSize); 1636 cbDest = cbDibSize; 1637 } 1638 } 1639 break; 1640 } 1641 default: 1642 rc = VERR_INVALID_PARAMETER; 1643 } 1644 } 1539 1645 else 1540 1646 rc = VERR_NOT_IMPLEMENTED; … … 1572 1678 clipAtomForX11Format(pCtx->widget, 1573 1679 pCtx->X11TextFormat), 1680 clipConvertX11CB, 1681 reinterpret_cast<XtPointer>(pReq), 1682 CurrentTime); 1683 } 1684 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 1685 { 1686 pReq->mBitmapFormat = pCtx->X11BitmapFormat; 1687 if (pReq->mBitmapFormat == INVALID) 1688 /* VBox thinks we have data and we don't */ 1689 rc = VERR_NO_DATA; 1690 else 1691 /* Send out a request for the data to the current clipboard 1692 * owner */ 1693 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx->widget, "CLIPBOARD"), 1694 clipAtomForX11Format(pCtx->widget, 1695 pCtx->X11BitmapFormat), 1574 1696 clipConvertX11CB, 1575 1697 reinterpret_cast<XtPointer>(pReq),
Note:
See TracChangeset
for help on using the changeset viewer.