VirtualBox

Ignore:
Timestamp:
May 30, 2013 7:48:09 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86113
Message:

GuestHost/SharedClipboard/X11: some separation of logic and host API.

File:
1 edited

Legend:

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

    r46313 r46335  
    130130    for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i)
    131131        if (clipAtomForX11Format(pCtx, i) == atomFormat)
     132            return i;
     133    return NIL_CLIPX11FORMAT;
     134}
     135
     136/** Lookup the X11 format matching a given X11 atom text.
     137 * @returns the format on success, NIL_CLIPX11FORMAT on failure
     138 * @param   widget a valid Xt widget
     139 */
     140static CLIPX11FORMAT clipFindX11FormatByAtomText(CLIPBACKEND *pCtx, const char *pcsz)
     141{
     142    for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i)
     143        if (!strcmp(g_aFormats[i].pcszAtom, pcsz))
    132144            return i;
    133145    return NIL_CLIPX11FORMAT;
     
    338350 */
    339351static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx,
    340                                                   Atom *pTargets,
     352                                                  CLIPX11FORMAT *pTargets,
    341353                                                  size_t cTargets)
    342354{
     
    347359    for (unsigned i = 0; i < cTargets; ++i)
    348360    {
    349         CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx, pTargets[i]);
     361        CLIPX11FORMAT format = pTargets[i];
    350362        if (format != NIL_CLIPX11FORMAT)
    351363        {
     
    366378{
    367379    bool success = true;
    368     Atom targets[2];
     380    CLIPX11FORMAT targets[2];
    369381    CLIPX11FORMAT x11Format;
    370     targets[0] = clipGetAtom(pCtx, "text/plain");
    371     targets[1] = clipGetAtom(pCtx, "TARGETS");
    372     x11Format = clipGetTextFormatFromTargets(pCtx, targets, 3);
     382    targets[0] = clipFindX11FormatByAtomText(pCtx, "text/plain");
     383    targets[1] = clipFindX11FormatByAtomText(pCtx, "image/bmp");
     384    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2);
    373385    if (clipRealFormatForX11Format(x11Format) != TEXT)
    374386        success = false;
    375     targets[0] = clipGetAtom(pCtx, "UTF8_STRING");
    376     targets[1] = clipGetAtom(pCtx, "text/plain");
    377     x11Format = clipGetTextFormatFromTargets(pCtx, targets, 3);
     387    targets[0] = clipFindX11FormatByAtomText(pCtx, "UTF8_STRING");
     388    targets[1] = clipFindX11FormatByAtomText(pCtx, "text/plain");
     389    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2);
    378390    if (clipRealFormatForX11Format(x11Format) != UTF8)
    379391        success = false;
     
    391403 */
    392404static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx,
    393                                                     Atom *pTargets,
     405                                                    CLIPX11FORMAT *pTargets,
    394406                                                    size_t cTargets)
    395407{
     
    400412    for (unsigned i = 0; i < cTargets; ++i)
    401413    {
    402         CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx, pTargets[i]);
     414        CLIPX11FORMAT format = pTargets[i];
    403415        if (format != NIL_CLIPX11FORMAT)
    404416        {
     
    423435 * @param  cTargets  the size of the list in @a pTargets
    424436 */
    425 static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, Atom *pTargets,
    426                                       size_t cTargets)
     437static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx,
     438                                      CLIPX11FORMAT *pTargets, size_t cTargets)
    427439{
    428440    AssertPtrReturnVoid(pCtx);
     
    434446    {
    435447        pCtx->X11TextFormat = bestTextFormat;
    436 #if defined(DEBUG) && !defined(TESTCASE)
    437         for (unsigned i = 0; i < cTargets; ++i)
    438             if (pTargets[i])
    439             {
    440                 char *pszName = XGetAtomName(XtDisplay(pCtx->widget),
    441                                                    pTargets[i]);
    442                 LogRel2(("%s: found target %s\n", __PRETTY_FUNCTION__, pszName));
    443                 XFree(pszName);
    444             }
    445 #endif
    446448    }
    447449    pCtx->X11BitmapFormat = INVALID;  /* not yet supported */
     
    460462 * @param  cTargets  the size of the array @a pTargets
    461463 */
    462 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, Atom *pTargets,
     464static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets,
    463465                                 size_t cTargets)
    464466{
     
    475477 * @note  callback for XtGetSelectionValue
    476478 */
    477 static void clipConvertX11Targets(Widget, XtPointer pClientData,
     479static void clipConvertX11Targets(Widget widget, XtPointer pClientData,
    478480                                  Atom * /* selection */, Atom *atomType,
    479481                                  XtPointer pValue, long unsigned int *pcLen,
     
    484486    LogRel2(("clipConvertX11Targets: pValue=%p, *pcLen=%u, *atomType=%d, XT_CONVERT_FAIL=%d\n",
    485487             pValue, *pcLen, *atomType, XT_CONVERT_FAIL));
     488    CLIPX11FORMAT *pFormats = NULL;
     489    if (*pcLen)
     490    {
     491        pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT));
     492        if (!pFormats)
     493        {
     494            XtFree((char *)pValue);
     495            return;
     496        }
     497    }
     498    if (pValue)
     499    {
     500        Atom *pAtoms = (Atom *)pValue;
     501        unsigned i, j;
     502#if defined(DEBUG) && !defined(TESTCASE)
     503        for (i = 0; i < *pcLen; ++i)
     504            if (pAtoms[i])
     505            {
     506                char *pszName = XGetAtomName(XtDisplay(widget), pAtoms[i]);
     507                LogRel2(("%s: found target %s\n", __PRETTY_FUNCTION__,
     508                         pszName));
     509                XFree(pszName);
     510            }
     511#endif
     512        for (i = 0; i < *pcLen; ++i)
     513            for (j = 0; j < RT_ELEMENTS(g_aFormats); ++j)
     514            {
     515                Atom target = XInternAtom(XtDisplay(widget),
     516                                          g_aFormats[j].pcszAtom, False);
     517                if (*(pAtoms + i) == target)
     518                    pFormats[i] = j;
     519            }
     520    }
    486521    pCtx->fBusy = false;
    487522    if (pCtx->fUpdateNeeded)
     
    497532        {
    498533            clipReportEmptyX11CB(pCtx);
     534            RTMemFree(pFormats);
    499535            return;
    500536        }
    501         clipUpdateX11Targets(pCtx, (Atom *)pValue, *pcLen);
    502     }
     537        clipUpdateX11Targets(pCtx, pFormats, *pcLen);
     538    }
     539    RTMemFree(pFormats);
    503540    XtFree(reinterpret_cast<char *>(pValue));
    504541}
     
    19171954static void clipSendTargetUpdate(CLIPBACKEND *pCtx)
    19181955{
    1919     clipUpdateX11Targets(pCtx, g_selTarget, RT_ELEMENTS(g_selTarget));
     1956    CLIPX11FORMAT selTarget[RT_ELEMENTS(g_selTarget)];
     1957    unsigned i, j;
     1958    RT_ZERO(selTarget);
     1959    for (i = 0; i < RT_ELEMENTS(g_selTarget); ++i)
     1960        for (j = 0; j < RT_ELEMENTS(g_aFormats); ++j)
     1961            if (XInternAtom(NULL, g_aFormats[j].pcszAtom, 0) == g_selTarget[i])
     1962                selTarget[i] = j;
     1963    clipUpdateX11Targets(pCtx, selTarget, RT_ELEMENTS(selTarget));
    19201964}
    19211965
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