VirtualBox

Changeset 21425 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Jul 9, 2009 11:05:49 AM (16 years ago)
Author:
vboxsync
Message:

GuestHost/SharedClipboard: properly test and fix our selection of the prefered X11 target format on offer

File:
1 edited

Legend:

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

    r21269 r21425  
    319319
    320320/**
    321  * Go through an array of X11 clipboard targets to see if we can support any
    322  * of them and if relevant to choose the ones we prefer (e.g. we like Utf8
    323  * better than compound text).
     321 * Go through an array of X11 clipboard targets to see if they contain a text
     322 * format we can support, and if so choose the ones we prefer (e.g. we like
     323 * Utf8 better than compound text).
    324324 * @param  pCtx      the clipboard backend context structure
    325325 * @param  pTargets  the list of targets
    326326 * @param  cTargets  the size of the list in @a pTargets
    327  * @param  pChanged  This is set to true if the formats available have changed
    328  *                   from VBox's point of view, and to false otherwise.
    329  *                   Somehow this didn't feel right as a return value.
    330  */
    331 void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, Atom *pTargets,
    332                                size_t cTargets, bool *pChanged)
    333 {
    334     bool changed = false;
     327 */
     328static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx,
     329                                                  Atom *pTargets,
     330                                                  size_t cTargets)
     331{
    335332    CLIPX11FORMAT bestTextFormat = NIL_CLIPX11FORMAT;
    336333    CLIPFORMAT enmBestTextTarget = INVALID;
    337     AssertPtrReturnVoid(pCtx);
    338     AssertPtrReturnVoid(pTargets);
     334    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     335    AssertPtrReturn(pTargets, NIL_CLIPX11FORMAT);
    339336    for (unsigned i = 0; i < cTargets; ++i)
    340337    {
     
    352349        }
    353350    }
     351    return bestTextFormat;
     352}
     353
     354#ifdef TESTCASE
     355static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx)
     356{
     357    bool success = true;
     358    Atom targets[3];
     359    CLIPX11FORMAT x11Format;
     360    targets[0] = clipGetAtom(NULL, "COMPOUND_TEXT");
     361    targets[1] = clipGetAtom(NULL, "text/plain");
     362    targets[2] = clipGetAtom(NULL, "TARGETS");
     363    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 3);
     364    if (clipRealFormatForX11Format(x11Format) != CTEXT)
     365        success = false;
     366    targets[0] = clipGetAtom(NULL, "UTF8_STRING");
     367    targets[1] = clipGetAtom(NULL, "text/plain");
     368    targets[2] = clipGetAtom(NULL, "COMPOUND_TEXT");
     369    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 3);
     370    if (clipRealFormatForX11Format(x11Format) != UTF8)
     371        success = false;
     372    return success;
     373}
     374#endif
     375
     376/**
     377 * Go through an array of X11 clipboard targets to see if we can support any
     378 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8
     379 * better than compound text).
     380 * @param  pCtx      the clipboard backend context structure
     381 * @param  pTargets  the list of targets
     382 * @param  cTargets  the size of the list in @a pTargets
     383 * @param  pChanged  This is set to true if the formats available have changed
     384 *                   from VBox's point of view, and to false otherwise.
     385 *                   Somehow this didn't feel right as a return value.
     386 */
     387static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, Atom *pTargets,
     388                                      size_t cTargets, bool *pChanged)
     389{
     390    bool changed = false;
     391    AssertPtrReturnVoid(pCtx);
     392    AssertPtrReturnVoid(pTargets);
     393    CLIPX11FORMAT bestTextFormat;
     394    bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets);
    354395    if (pCtx->X11TextFormat != bestTextFormat)
    355396    {
     
    10571098}
    10581099
    1059 /** Gives up ownership of the X11 clipboard */
    1060 static void clipGiveUpX11CB(CLIPBACKEND *pCtx)
    1061 {
    1062     XtDisownSelection(pCtx->widget, clipGetAtom(pCtx->widget, "CLIPBOARD"),
    1063                       CurrentTime);
    1064     XtDisownSelection(pCtx->widget, clipGetAtom(pCtx->widget, "PRIMARY"),
    1065                       CurrentTime);
    1066     pCtx->fOwnsClipboard = false;
    1067     pCtx->vboxFormats = 0;
    1068 }
    1069 
    10701100/**
    10711101 * Take possession of the X11 clipboard (and middle-button selection).
     
    17671797/* The current values of the X selection, which will be returned to the
    17681798 * XtGetSelectionValue callback. */
    1769 static Atom g_selTarget[3] = { 0 };
     1799static Atom g_selTarget[1] = { 0 };
    17701800static Atom g_selType = 0;
    17711801static const void *g_pSelData = NULL;
     
    19011931    Atom clipAtom = clipGetAtom(NULL, "CLIPBOARD");
    19021932    g_selTarget[0] = clipGetAtom(NULL, pcszTarget);
    1903     g_selTarget[1] = clipGetAtom(NULL, "text/plain");
    1904     g_selTarget[2] = clipGetAtom(NULL, "TARGETS");
    19051933    g_selType = type;
    19061934    g_pSelData = data;
     
    23622390    }
    23632391
     2392    /*** X11 text format conversion ***/
     2393    RTPrintf(TEST_NAME ": TESTING selection of X11 text formats\n");
     2394    if (!clipTestTextFormatConversion(pCtx))
     2395    {
     2396        RTPrintf(TEST_NAME ": Failed to select the right X11 text formats\n");
     2397        ++cErrs;
     2398    }
     2399
    23642400    /*** Utf-8 from VBox ***/
    23652401    RTPrintf(TEST_NAME ": TESTING reading Utf-8 from VBox\n");
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