Changeset 46335 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- May 30, 2013 7:48:09 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 86113
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r46313 r46335 130 130 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 131 131 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 */ 140 static 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)) 132 144 return i; 133 145 return NIL_CLIPX11FORMAT; … … 338 350 */ 339 351 static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx, 340 Atom*pTargets,352 CLIPX11FORMAT *pTargets, 341 353 size_t cTargets) 342 354 { … … 347 359 for (unsigned i = 0; i < cTargets; ++i) 348 360 { 349 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx, pTargets[i]);361 CLIPX11FORMAT format = pTargets[i]; 350 362 if (format != NIL_CLIPX11FORMAT) 351 363 { … … 366 378 { 367 379 bool success = true; 368 Atomtargets[2];380 CLIPX11FORMAT targets[2]; 369 381 CLIPX11FORMAT x11Format; 370 targets[0] = clip GetAtom(pCtx, "text/plain");371 targets[1] = clip GetAtom(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); 373 385 if (clipRealFormatForX11Format(x11Format) != TEXT) 374 386 success = false; 375 targets[0] = clip GetAtom(pCtx, "UTF8_STRING");376 targets[1] = clip GetAtom(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); 378 390 if (clipRealFormatForX11Format(x11Format) != UTF8) 379 391 success = false; … … 391 403 */ 392 404 static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx, 393 Atom*pTargets,405 CLIPX11FORMAT *pTargets, 394 406 size_t cTargets) 395 407 { … … 400 412 for (unsigned i = 0; i < cTargets; ++i) 401 413 { 402 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx, pTargets[i]);414 CLIPX11FORMAT format = pTargets[i]; 403 415 if (format != NIL_CLIPX11FORMAT) 404 416 { … … 423 435 * @param cTargets the size of the list in @a pTargets 424 436 */ 425 static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, Atom *pTargets,426 size_t cTargets)437 static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, 438 CLIPX11FORMAT *pTargets, size_t cTargets) 427 439 { 428 440 AssertPtrReturnVoid(pCtx); … … 434 446 { 435 447 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 #endif446 448 } 447 449 pCtx->X11BitmapFormat = INVALID; /* not yet supported */ … … 460 462 * @param cTargets the size of the array @a pTargets 461 463 */ 462 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, Atom*pTargets,464 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets, 463 465 size_t cTargets) 464 466 { … … 475 477 * @note callback for XtGetSelectionValue 476 478 */ 477 static void clipConvertX11Targets(Widget , XtPointer pClientData,479 static void clipConvertX11Targets(Widget widget, XtPointer pClientData, 478 480 Atom * /* selection */, Atom *atomType, 479 481 XtPointer pValue, long unsigned int *pcLen, … … 484 486 LogRel2(("clipConvertX11Targets: pValue=%p, *pcLen=%u, *atomType=%d, XT_CONVERT_FAIL=%d\n", 485 487 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 } 486 521 pCtx->fBusy = false; 487 522 if (pCtx->fUpdateNeeded) … … 497 532 { 498 533 clipReportEmptyX11CB(pCtx); 534 RTMemFree(pFormats); 499 535 return; 500 536 } 501 clipUpdateX11Targets(pCtx, (Atom *)pValue, *pcLen); 502 } 537 clipUpdateX11Targets(pCtx, pFormats, *pcLen); 538 } 539 RTMemFree(pFormats); 503 540 XtFree(reinterpret_cast<char *>(pValue)); 504 541 } … … 1917 1954 static void clipSendTargetUpdate(CLIPBACKEND *pCtx) 1918 1955 { 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)); 1920 1964 } 1921 1965
Note:
See TracChangeset
for help on using the changeset viewer.