VirtualBox

Changeset 21184 in vbox for trunk/src


Ignore:
Timestamp:
Jul 2, 2009 9:53:03 PM (16 years ago)
Author:
vboxsync
Message:

GuestHost/SharedClipboard: fix broken code for selecting the format to request from X11 and add a test for that code

File:
1 edited

Legend:

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

    r20966 r21184  
    6262    INVALID = 0,
    6363    TARGETS,
     64    TEXT,  /* Treat this as Utf8, but it may really be ascii */
    6465    CTEXT,
    6566    UTF8
     
    8586    { "text/plain;charset=utf-8", UTF8,
    8687      VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    87     { "STRING", UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    88     { "TEXT", UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    89     { "text/plain", UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     88    { "STRING", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     89    { "TEXT", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     90    { "text/plain", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    9091    { "COMPOUND_TEXT", CTEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }
    9192};
     
    333334    bool changed = false;
    334335    CLIPX11FORMAT bestTextFormat = NIL_CLIPX11FORMAT;
     336    CLIPFORMAT enmBestTextTarget = INVALID;
    335337    AssertPtrReturnVoid(pCtx);
    336338    AssertPtrReturnVoid(pTargets);
    337339    for (unsigned i = 0; i < cTargets; ++i)
    338340    {
    339         CLIPFORMAT enmBestTextTarget = INVALID;
    340341        CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx->widget,
    341342                                                       pTargets[i]);
     
    355356        changed = true;
    356357        pCtx->X11TextFormat = bestTextFormat;
     358#if defined(DEBUG) && !defined(TESTCASE)
     359        for (unsigned i = 0; i < cTargets; ++i)
     360            if (pTargets[i])
     361            {
     362                char *pszName = XGetAtomName(XtDisplay(pCtx->widget),
     363                                                   pTargets[i]);
     364                Log2(("%s: found target %s\n", __PRETTY_FUNCTION__, pszName));
     365                XFree(pszName);
     366            }
     367#endif
    357368    }
    358369    pCtx->X11BitmapFormat = INVALID;  /* not yet supported */
     
    959970                                                      *atomTarget);
    960971    CLIPFORMAT format = clipRealFormatForX11Format(x11Format);
    961     if (   ((format == UTF8) || (format == CTEXT))
     972    if (   ((format == UTF8) || (format == CTEXT) || (format == TEXT))
    962973        && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))
    963974    {
     
    969980        if (RT_SUCCESS(rc) && (cb == 0))
    970981            rc = VERR_NO_DATA;
    971         if (RT_SUCCESS(rc) && (format == UTF8))
     982        if (RT_SUCCESS(rc) && ((format == UTF8) || (format == TEXT)))
    972983            rc = clipWinTxtToUtf8ForX11CB(XtDisplay(pCtx->widget),
    973984                                          (PRTUTF16)pv, cb, atomTarget,
     
    13951406                break;
    13961407            case UTF8:
     1408            case TEXT:
    13971409            {
    13981410                /* If we are given broken Utf-8, we treat it as Latin1.  Is
     
    15151527#ifdef TESTCASE
    15161528
     1529/** @todo This unit test currently works by emulating the X11 and X toolkit
     1530 * APIs to exercise the code, since I didn't want to rewrite the code too much
     1531 * when I wrote the tests.  However, this makes it rather ugly and hard to
     1532 * understand.  Anyone doing any work on the code should feel free to
     1533 * rewrite the tests and the code to make them cleaner and more readable. */
     1534
    15171535#include <iprt/initterm.h>
    15181536#include <iprt/stream.h>
     
    17551773/* The current values of the X selection, which will be returned to the
    17561774 * XtGetSelectionValue callback. */
    1757 static Atom g_selTarget = 0;
     1775static Atom g_selTarget[3] = { 0 };
    17581776static Atom g_selType = 0;
    17591777static const void *g_pSelData = NULL;
     
    17731791            && selection != clipGetAtom(NULL, "CLIPBOARD")
    17741792            && selection != clipGetAtom(NULL, "TARGETS"))
    1775         || (   target != g_selTarget
     1793        || (   target != g_selTarget[0]
    17761794            && target != clipGetAtom(NULL, "TARGETS")))
    17771795    {
    17781796        /* Otherwise this is probably a caller error. */
    1779         Assert(target != g_selTarget);
     1797        Assert(target != g_selTarget[0]);
    17801798        callback(widget, closure, &selection, &type, NULL, &count, &format);
    17811799                /* Could not convert to target. */
     
    17901808            pValue = (XtPointer) RTMemDup(&g_selTarget, sizeof(g_selTarget));
    17911809        type = g_fTargetsTimeout ? XT_CONVERT_FAIL : XA_ATOM;
    1792         count = g_fTargetsFailure ? 0 : 1;
     1810        count = g_fTargetsFailure ? 0 : RT_ELEMENTS(g_selTarget);
    17931811        format = 32;
    17941812    }
     
    18881906{
    18891907    Atom clipAtom = clipGetAtom(NULL, "CLIPBOARD");
    1890     g_selTarget = clipGetAtom(NULL, pcszTarget);
     1908    g_selTarget[0] = clipGetAtom(NULL, pcszTarget);
     1909    g_selTarget[1] = clipGetAtom(NULL, "text/plain");
     1910    g_selTarget[2] = clipGetAtom(NULL, "TARGETS");
    18911911    g_selType = type;
    18921912    g_pSelData = data;
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