VirtualBox

Ignore:
Timestamp:
Nov 6, 2012 4:15:44 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81838
Message:

GuestHost/SharedClipboard: BMP support for the X11 shared clipboard, contributed by François Revel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp

    r38904 r43812  
    6363    TEXT,  /* Treat this as Utf8, but it may really be ascii */
    6464    CTEXT,
    65     UTF8
     65    UTF8,
     66    BMP
    6667};
    6768
     
    8889    { "TEXT", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    8990    { "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... */
    9196};
    9297
     
    307312{
    308313    uint32_t u32VBoxFormats = clipVBoxFormatForX11Format(pCtx->X11TextFormat);
     314    u32VBoxFormats |= clipVBoxFormatForX11Format(pCtx->X11BitmapFormat);
    309315    ClipReportX11Formats(pCtx->pFrontend, u32VBoxFormats);
    310316}
     
    383389
    384390/**
     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 */
     398static 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/**
    385425 * Go through an array of X11 clipboard targets to see if we can support any
    386426 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8
     
    396436    AssertPtrReturnVoid(pTargets);
    397437    CLIPX11FORMAT bestTextFormat;
     438    CLIPX11FORMAT bestBitmapFormat;
    398439    bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets);
    399440    if (pCtx->X11TextFormat != bestTextFormat)
     
    412453    }
    413454    pCtx->X11BitmapFormat = INVALID;  /* not yet supported */
     455    bestBitmapFormat = clipGetBitmapFormatFromTargets(pCtx, pTargets, cTargets);
     456    if (pCtx->X11BitmapFormat != bestBitmapFormat)
     457    {
     458        pCtx->X11BitmapFormat = bestBitmapFormat;
     459    }
    414460}
    415461
     
    11401186        RTMemFree(pv);
    11411187    }
     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    }
    11421214    else
    11431215        rc = VERR_NOT_SUPPORTED;
     
    14751547    /** The text format we requested from X11 if we requested text */
    14761548    CLIPX11FORMAT mTextFormat;
     1549    /** The bitmap format we requested from X11 if we requested bitmap */
     1550    CLIPX11FORMAT mBitmapFormat;
    14771551    /** The clipboard context this request is associated with */
    14781552    CLIPBACKEND *mCtx;
     
    14841558
    14851559/**
    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.
    14881564 * @note  X11 backend code, callback for XtGetSelectionValue, for use when
    1489  *        the X11 clipboard contains a text format we understand.
     1565 *        the X11 clipboard contains a format we understand.
    14901566 */
    14911567static void clipConvertX11CB(Widget widget, XtPointer pClientData,
     
    14951571{
    14961572    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));
    14991577    AssertPtr(pReq->mCtx);
    15001578    Assert(pReq->mFormat != 0);  /* sanity */
     
    15371615        }
    15381616    }
     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    }
    15391645    else
    15401646        rc = VERR_NOT_IMPLEMENTED;
     
    15721678                                clipAtomForX11Format(pCtx->widget,
    15731679                                                     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),
    15741696                                clipConvertX11CB,
    15751697                                reinterpret_cast<XtPointer>(pReq),
Note: See TracChangeset for help on using the changeset viewer.

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