- Timestamp:
- May 18, 2019 5:09:25 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r78582 r78583 75 75 * Structures and Typedefs * 76 76 *********************************************************************************************************************************/ 77 /** The different X11 clipboard format targets. */ 78 typedef enum _CLIPX11FORMATTARGET 79 { 80 CLIPX11FORMATTARGET_INVALID = 0, 81 CLIPX11FORMATTARGET_TARGETS, 82 CLIPX11FORMATTARGET_TEXT, /* Treat this as Utf8, but it may really be ascii */ 83 CLIPX11FORMATTARGET_UTF8, 84 CLIPX11FORMATTARGET_BMP, 85 CLIPX11FORMATTARGET_HTML 86 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 87 , CLIPX11FORMATTARGET_URI_LIST 88 #endif 89 } CLIPX11FORMATTARGET; 90 91 /** Index into the format array. */ 92 typedef unsigned CLIPX11FORMATIDX; 77 /** The different clipboard formats which we support. */ 78 enum CLIPFORMAT 79 { 80 INVALID = 0, 81 TARGETS, 82 TEXT, /* Treat this as Utf8, but it may really be ascii */ 83 UTF8, 84 BMP, 85 HTML 86 }; 87 88 typedef unsigned CLIPX11FORMAT; 93 89 94 90 … … 105 101 /** The table mapping X11 names to data formats and to the corresponding 106 102 * VBox clipboard formats (currently only Unicode) */ 107 static struct _CLIPX11FORMATTABLE 108 { 109 /** The X11 atom name of the format (several names can match one format) */ 103 static struct _CLIPFORMATTABLE 104 { 105 /** The X11 atom name of the format (several names can match one format) 106 */ 110 107 const char *pcszAtom; 111 /** The format target corresponding to the atomname */112 CLIP X11FORMATTARGET enmTarget;108 /** The format corresponding to the name */ 109 CLIPFORMAT enmFormat; 113 110 /** The corresponding VBox clipboard format */ 114 VBOXCLIPBOARDFORMAT vboxFormat;111 uint32_t u32VBoxFormat; 115 112 } g_aFormats[] = 116 113 { 117 { "INVALID", CLIPX11FORMATTARGET_INVALID, 0 }, 118 { "UTF8_STRING", CLIPX11FORMATTARGET_UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 119 { "text/plain;charset=UTF-8", CLIPX11FORMATTARGET_UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 120 { "text/plain;charset=utf-8", CLIPX11FORMATTARGET_UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 121 { "STRING", CLIPX11FORMATTARGET_TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 122 { "TEXT", CLIPX11FORMATTARGET_TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 123 { "text/plain", CLIPX11FORMATTARGET_TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 124 { "text/html", CLIPX11FORMATTARGET_HTML, VBOX_SHARED_CLIPBOARD_FMT_HTML }, 125 { "text/html;charset=utf-8", CLIPX11FORMATTARGET_HTML, VBOX_SHARED_CLIPBOARD_FMT_HTML }, 126 { "image/bmp", CLIPX11FORMATTARGET_BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 127 { "image/x-bmp", CLIPX11FORMATTARGET_BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 128 { "image/x-MS-bmp", CLIPX11FORMATTARGET_BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 129 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 130 { "text/uri-list", CLIPX11FORMATTARGET_URI_LIST, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST }, 131 { "x-special/gnome-copied-files", CLIPX11FORMATTARGET_URI_LIST, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST } 132 #endif 114 { "INVALID", INVALID, 0 }, 115 { "UTF8_STRING", UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 116 { "text/plain;charset=UTF-8", UTF8, 117 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 118 { "text/plain;charset=utf-8", UTF8, 119 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 120 { "STRING", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 121 { "TEXT", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 122 { "text/plain", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT }, 123 { "text/html", HTML, VBOX_SHARED_CLIPBOARD_FMT_HTML }, 124 { "text/html;charset=utf-8", HTML, 125 VBOX_SHARED_CLIPBOARD_FMT_HTML }, 126 { "image/bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 127 { "image/x-bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }, 128 { "image/x-MS-bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP } 129 130 133 131 /** @todo Inkscape exports image/png but not bmp... */ 134 132 }; … … 136 134 enum 137 135 { 138 CLIPX11FORMATIDX_NIL= 0,139 CLIPX11FORMATIDX_MAX= RT_ELEMENTS(g_aFormats)136 NIL_CLIPX11FORMAT = 0, 137 MAX_CLIP_X11_FORMATS = RT_ELEMENTS(g_aFormats) 140 138 }; 141 139 142 140 143 /** Return x the atom name corresponding to a supported X11 format index.141 /** Return the atom corresponding to a supported X11 format. 144 142 * @param widget a valid Xt widget 145 143 */ 146 static Atom clipGetAtomFromFmtIdx(CLIPBACKEND *pCtx, CLIPX11FORMATIDX formatIdx) 147 { 148 return clipGetAtom(pCtx, g_aFormats[formatIdx].pcszAtom); 149 } 150 151 /** Returns the format target corresponding to a supported X11 format index. */ 152 static CLIPX11FORMATTARGET clipGetTargetFmtFromFmtIdx(CLIPX11FORMATIDX formatIdx) 153 { 154 return g_aFormats[formatIdx].enmTarget; 155 } 156 157 /** Returns the VBox format corresponding to a supported X11 format index. */ 158 static VBOXCLIPBOARDFORMAT clipGetVBoxFmtFromFmtIdx(CLIPX11FORMATIDX formatIdx) 159 { 160 return g_aFormats[formatIdx].vboxFormat; 161 } 162 163 /** 164 * Looks up the X11 format index matching a given X11 atom. 165 * 166 * @returns the format on success, CLIPX11FORMATIDX_NIL on failure. 144 static Atom clipAtomForX11Format(CLIPBACKEND *pCtx, CLIPX11FORMAT format) 145 { 146 return clipGetAtom(pCtx, g_aFormats[format].pcszAtom); 147 } 148 149 /** Return the CLIPFORMAT corresponding to a supported X11 format. */ 150 static CLIPFORMAT clipRealFormatForX11Format(CLIPX11FORMAT format) 151 { 152 return g_aFormats[format].enmFormat; 153 } 154 155 /** Return the atom corresponding to a supported X11 format. */ 156 static uint32_t clipVBoxFormatForX11Format(CLIPX11FORMAT format) 157 { 158 return g_aFormats[format].u32VBoxFormat; 159 } 160 161 /** Lookup the X11 format matching a given X11 atom. 162 * @returns the format on success, NIL_CLIPX11FORMAT on failure 167 163 * @param widget a valid Xt widget 168 164 */ 169 static CLIPX11FORMAT IDX clipGetFmtIdxFromAtom(CLIPBACKEND *pCtx, Atom atomFormat)165 static CLIPX11FORMAT clipFindX11FormatByAtom(CLIPBACKEND *pCtx, Atom atomFormat) 170 166 { 171 167 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 172 if (clip GetAtomFromFmtIdx(pCtx, i) == atomFormat)168 if (clipAtomForX11Format(pCtx, i) == atomFormat) 173 169 return i; 174 return CLIPX11FORMATIDX_NIL;170 return NIL_CLIPX11FORMAT; 175 171 } 176 172 177 173 #ifdef TESTCASE 178 174 /** Lookup the X11 format matching a given X11 atom text. 179 * @returns the format on success, NIL_CLIPX11FORMAT TARGETon failure175 * @returns the format on success, NIL_CLIPX11FORMAT on failure 180 176 * @param widget a valid Xt widget 181 177 */ 182 static CLIPX11FORMAT IDX clipGetFmtIdxFromAtomText(const char *pcsz)178 static CLIPX11FORMAT clipFindX11FormatByAtomText(const char *pcsz) 183 179 { 184 180 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 185 181 if (!strcmp(g_aFormats[i].pcszAtom, pcsz)) 186 182 return i; 187 return CLIPX11FORMATIDX_NIL;183 return NIL_CLIPX11FORMAT; 188 184 } 189 185 #endif 190 186 191 187 /** 192 * Enumerates supported X11 clipboard formats corresponding to a given VBox format.193 * 194 * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMAT TARGETif188 * Enumerates supported X11 clipboard formats corresponding to a given VBox 189 * format. 190 * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMAT if 195 191 * there are no more 196 * @param lastF mtIdx The format indexreturned from the last call of this function.197 * Use CLIPX11FORMATIDX_NILto start the enumeration.198 */ 199 static CLIPX11FORMAT IDX clipEnumFmtIdxForVBoxFmt(VBOXCLIPBOARDFORMAT vboxFormat,200 CLIPX11FORMATIDX lastFmtIdx)201 { 202 for (unsigned i = lastF mtIdx+ 1; i < RT_ELEMENTS(g_aFormats); ++i)203 if ( vboxFormat & clipGetVBoxFmtFromFmtIdx(i))192 * @param lastFormat The value returned from the last call of this function. 193 * Use NIL_CLIPX11FORMAT to start the enumeration. 194 */ 195 static CLIPX11FORMAT clipEnumX11Formats(uint32_t u32VBoxFormats, 196 CLIPX11FORMAT lastFormat) 197 { 198 for (unsigned i = lastFormat + 1; i < RT_ELEMENTS(g_aFormats); ++i) 199 if (u32VBoxFormats & clipVBoxFormatForX11Format(i)) 204 200 return i; 205 return CLIPX11FORMATIDX_NIL;201 return NIL_CLIPX11FORMAT; 206 202 } 207 203 … … 226 222 /** The best text format X11 has to offer, as an index into the formats 227 223 * table */ 228 CLIPX11FORMAT IDX X11TextFmtIdx;224 CLIPX11FORMAT X11TextFormat; 229 225 /** The best bitmap format X11 has to offer, as an index into the formats 230 226 * table */ 231 CLIPX11FORMAT IDX X11BitmapFmtIdx;227 CLIPX11FORMAT X11BitmapFormat; 232 228 /** The best HTML format X11 has to offer, as an index into the formats 233 229 * table */ 234 CLIPX11FORMATIDX X11HTMLFmtIdx; 235 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 236 /** The best URI list format X11 has to offer, as an index into the formats 237 * table */ 238 CLIPX11FORMATIDX X11URListFmtIdx; 239 #endif 230 CLIPX11FORMAT X11HTMLFormat; 240 231 /** What formats does VBox have on offer? */ 241 VBOXCLIPBOARDFORMATSvboxFormats;232 uint32_t vboxFormats; 242 233 /** Cache of the last unicode data that we received */ 243 234 void *pvUnicodeCache; … … 367 358 (XtPointer)client_data); 368 359 ssize_t cbWritten = write(pCtx->wakeupPipeWrite, WAKE_UP_STRING, WAKE_UP_STRING_LEN); 369 RT_NOREF(cbWritten);360 NOREF(cbWritten); 370 361 #else 371 RT_NOREF (pCtx);362 RT_NOREF1(pCtx); 372 363 testQueueToEventThread(proc, client_data); 373 364 #endif … … 379 370 static void clipReportFormatsToVBox(CLIPBACKEND *pCtx) 380 371 { 381 VBOXCLIPBOARDFORMATS vboxFormats = clipGetVBoxFmtFromFmtIdx(pCtx->X11TextFmtIdx); 382 vboxFormats |= clipGetVBoxFmtFromFmtIdx(pCtx->X11BitmapFmtIdx); 383 vboxFormats |= clipGetVBoxFmtFromFmtIdx(pCtx->X11HTMLFmtIdx); 384 385 LogRelFlowFunc(("clipReportFormatsToVBox formats: 0x%x\n", vboxFormats)); 386 LogRelFlowFunc(("clipReportFormatsToVBox txt: %d, bitm: %d, html:%d, vboxFormat: %d\n", 387 pCtx->X11TextFmtIdx, pCtx->X11BitmapFmtIdx, pCtx->X11HTMLFmtIdx, 388 vboxFormats)); 389 390 ClipReportX11Formats(pCtx->pFrontend, vboxFormats); 372 uint32_t u32VBoxFormats = clipVBoxFormatForX11Format(pCtx->X11TextFormat); 373 u32VBoxFormats |= clipVBoxFormatForX11Format(pCtx->X11BitmapFormat); 374 u32VBoxFormats |= clipVBoxFormatForX11Format(pCtx->X11HTMLFormat); 375 LogRelFlowFunc(("clipReportFormatsToVBox format: %d\n", u32VBoxFormats)); 376 LogRelFlowFunc(("clipReportFormatsToVBox txt: %d, bitm: %d, html:%d, u32VBoxFormats: %d\n", 377 pCtx->X11TextFormat, pCtx->X11BitmapFormat, pCtx->X11HTMLFormat, 378 u32VBoxFormats )); 379 ClipReportX11Formats(pCtx->pFrontend, u32VBoxFormats); 391 380 } 392 381 … … 396 385 static void clipResetX11Formats(CLIPBACKEND *pCtx) 397 386 { 398 pCtx->X11TextFmtIdx = CLIPX11FORMATIDX_NIL; 399 pCtx->X11BitmapFmtIdx = CLIPX11FORMATIDX_NIL; 400 pCtx->X11HTMLFmtIdx = CLIPX11FORMATIDX_NIL; 401 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 402 pCtx->X11URListFmtIdx = CLIPX11FORMATIDX_NIL; 403 #endif 387 pCtx->X11TextFormat = INVALID; 388 pCtx->X11BitmapFormat = INVALID; 389 pCtx->X11HTMLFormat = INVALID; 404 390 } 405 391 … … 411 397 } 412 398 399 /** 400 * Go through an array of X11 clipboard targets to see if they contain a text 401 * format we can support, and if so choose the ones we prefer (e.g. we like 402 * Utf8 better than plain text). 403 * @param pCtx the clipboard backend context structure 404 * @param pTargets the list of targets 405 * @param cTargets the size of the list in @a pTargets 406 */ 407 static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx, 408 CLIPX11FORMAT *pTargets, 409 size_t cTargets) 410 { 411 CLIPX11FORMAT bestTextFormat = NIL_CLIPX11FORMAT; 412 CLIPFORMAT enmBestTextTarget = INVALID; 413 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 414 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 415 for (unsigned i = 0; i < cTargets; ++i) 416 { 417 CLIPX11FORMAT format = pTargets[i]; 418 if (format != NIL_CLIPX11FORMAT) 419 { 420 if ( (clipVBoxFormatForX11Format(format) 421 == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 422 && enmBestTextTarget < clipRealFormatForX11Format(format)) 423 { 424 enmBestTextTarget = clipRealFormatForX11Format(format); 425 bestTextFormat = format; 426 } 427 } 428 } 429 return bestTextFormat; 430 } 431 413 432 #ifdef TESTCASE 414 433 static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx) 415 434 { 416 435 bool success = true; 417 CLIPX11FORMAT TARGETtargets[2];418 CLIPX11FORMAT TARGETx11Format;419 targets[0] = clip GetFmtIdxFromAtomText("text/plain");420 targets[1] = clip GetFmtIdxFromAtomText("image/bmp");436 CLIPX11FORMAT targets[2]; 437 CLIPX11FORMAT x11Format; 438 targets[0] = clipFindX11FormatByAtomText("text/plain"); 439 targets[1] = clipFindX11FormatByAtomText("image/bmp"); 421 440 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 422 if (clip GetTargetFmtFromFmtIdx(x11Format) != TEXT)441 if (clipRealFormatForX11Format(x11Format) != TEXT) 423 442 success = false; 424 targets[0] = clip GetFmtIdxFromAtomText("UTF8_STRING");425 targets[1] = clip GetFmtIdxFromAtomText("text/plain");443 targets[0] = clipFindX11FormatByAtomText("UTF8_STRING"); 444 targets[1] = clipFindX11FormatByAtomText("text/plain"); 426 445 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 427 if (clip GetTargetFmtFromFmtIdx(x11Format) != UTF8)446 if (clipRealFormatForX11Format(x11Format) != UTF8) 428 447 success = false; 429 448 return success; … … 435 454 * format we can support, and if so choose the ones we prefer (e.g. we like 436 455 * BMP better than PNG because we don't have to convert). 437 *438 456 * @param pCtx the clipboard backend context structure 439 457 * @param pTargets the list of targets 440 458 * @param cTargets the size of the list in @a pTargets 441 459 */ 442 static CLIPX11FORMATIDX clipGetBestFmtIdxFromTargets(CLIPBACKEND *pCtx, 443 VBOXCLIPBOARDFORMAT vboxFormat, 444 CLIPX11FORMATIDX *paTargets, size_t cTargets) 445 { 446 AssertPtrReturn(pCtx, CLIPX11FORMATIDX_NIL); 447 AssertReturn(VALID_PTR(paTargets) || cTargets == 0, CLIPX11FORMATIDX_NIL); 448 449 CLIPX11FORMATIDX bestFmtIdx = CLIPX11FORMATIDX_NIL; 450 CLIPX11FORMATTARGET enmBestTarget = CLIPX11FORMATTARGET_INVALID; 451 460 static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx, 461 CLIPX11FORMAT *pTargets, 462 size_t cTargets) 463 { 464 CLIPX11FORMAT bestBitmapFormat = NIL_CLIPX11FORMAT; 465 CLIPFORMAT enmBestBitmapTarget = INVALID; 466 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 467 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 452 468 for (unsigned i = 0; i < cTargets; ++i) 453 469 { 454 CLIPX11FORMAT IDX format = paTargets[i];455 if (format != CLIPX11FORMATIDX_NIL)470 CLIPX11FORMAT format = pTargets[i]; 471 if (format != NIL_CLIPX11FORMAT) 456 472 { 457 if ( (clipGetVBoxFmtFromFmtIdx(format) == vboxFormat) 458 && enmBestTarget < clipGetTargetFmtFromFmtIdx(format)) 473 if ( (clipVBoxFormatForX11Format(format) 474 == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 475 && enmBestBitmapTarget < clipRealFormatForX11Format(format)) 459 476 { 460 enmBest Target = clipGetTargetFmtFromFmtIdx(format);461 best FmtIdx= format;477 enmBestBitmapTarget = clipRealFormatForX11Format(format); 478 bestBitmapFormat = format; 462 479 } 463 480 } 464 481 } 465 return bestFmtIdx; 466 } 482 return bestBitmapFormat; 483 } 484 485 /** 486 * Go through an array of X11 clipboard targets to see if they contain a HTML 487 * format we can support, and if so choose the ones we prefer 488 * @param pCtx the clipboard backend context structure 489 * @param pTargets the list of targets 490 * @param cTargets the size of the list in @a pTargets 491 */ 492 static CLIPX11FORMAT clipGetHtmlFormatFromTargets(CLIPBACKEND *pCtx, 493 CLIPX11FORMAT *pTargets, 494 size_t cTargets) 495 { 496 CLIPX11FORMAT bestHTMLFormat = NIL_CLIPX11FORMAT; 497 CLIPFORMAT enmBestHtmlTarget = INVALID; 498 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 499 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 500 for (unsigned i = 0; i < cTargets; ++i) 501 { 502 CLIPX11FORMAT format = pTargets[i]; 503 if (format != NIL_CLIPX11FORMAT) 504 { 505 if ( (clipVBoxFormatForX11Format(format) == VBOX_SHARED_CLIPBOARD_FMT_HTML) 506 && enmBestHtmlTarget < clipRealFormatForX11Format(format)) 507 { 508 enmBestHtmlTarget = clipRealFormatForX11Format(format); 509 bestHTMLFormat = format; 510 } 511 } 512 } 513 return bestHTMLFormat; 514 } 515 467 516 468 517 /** … … 470 519 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8 471 520 * better than plain text). 472 *473 521 * @param pCtx the clipboard backend context structure 474 522 * @param pTargets the list of targets … … 476 524 */ 477 525 static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, 478 CLIPX11FORMAT IDX *paTargets, size_t cTargets)526 CLIPX11FORMAT *pTargets, size_t cTargets) 479 527 { 480 528 AssertPtrReturnVoid(pCtx); 481 AssertPtrReturnVoid(paTargets); 482 483 CLIPX11FORMATIDX bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, 484 paTargets, cTargets); 485 if (pCtx->X11TextFmtIdx != bestFmtIdx) 486 pCtx->X11TextFmtIdx = bestFmtIdx; 487 488 pCtx->X11BitmapFmtIdx = CLIPX11FORMATIDX_NIL; /* not yet supported */ 489 bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, paTargets, cTargets); 490 if (pCtx->X11BitmapFmtIdx != bestFmtIdx) 491 pCtx->X11BitmapFmtIdx = bestFmtIdx; 492 493 bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_HTML, paTargets, cTargets); 494 if(pCtx->X11HTMLFmtIdx != bestFmtIdx) 495 pCtx->X11HTMLFmtIdx = bestFmtIdx; 496 497 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 498 bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST, paTargets, cTargets); 499 if(pCtx->X11URListFmtIdx != bestFmtIdx) 500 pCtx->X11URListFmtIdx = bestFmtIdx; 501 #endif 529 AssertPtrReturnVoid(pTargets); 530 CLIPX11FORMAT bestTextFormat; 531 CLIPX11FORMAT bestBitmapFormat; 532 CLIPX11FORMAT bestHtmlFormat; 533 bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets); 534 if (pCtx->X11TextFormat != bestTextFormat) 535 { 536 pCtx->X11TextFormat = bestTextFormat; 537 } 538 pCtx->X11BitmapFormat = INVALID; /* not yet supported */ 539 bestBitmapFormat = clipGetBitmapFormatFromTargets(pCtx, pTargets, cTargets); 540 if (pCtx->X11BitmapFormat != bestBitmapFormat) 541 { 542 pCtx->X11BitmapFormat = bestBitmapFormat; 543 } 544 bestHtmlFormat = clipGetHtmlFormatFromTargets(pCtx, pTargets, cTargets); 545 if(pCtx->X11HTMLFormat != bestHtmlFormat) 546 { 547 pCtx->X11HTMLFormat = bestHtmlFormat; 548 } 502 549 } 503 550 … … 507 554 * Update the context's information about targets currently supported by X11, 508 555 * based on an array of X11 atoms. 509 *510 556 * @param pCtx the context to be updated 511 557 * @param pTargets the array of atoms describing the targets supported 512 558 * @param cTargets the size of the array @a pTargets 513 559 */ 514 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT IDX *paTargetFmtIdx, size_t cTargets)515 { 516 LogRel2(("Shared clipboard: clipUpdateX11Targets called\n")); 517 560 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets, 561 size_t cTargets) 562 { 563 LogRel2 (("%s: called\n", __FUNCTION__)); 518 564 #ifndef VBOX_AFTER_5_2 519 565 pCtx->fBusy = false; … … 526 572 } 527 573 #endif 528 529 if (paTargetFmtIdx == NULL) 530 { 574 if (pTargets == NULL) { 531 575 /* No data available */ 532 576 clipReportEmptyX11CB(pCtx); 533 577 return; 534 578 } 535 536 clipGetFormatsFromTargets(pCtx, paTargetFmtIdx, cTargets); 579 clipGetFormatsFromTargets(pCtx, pTargets, cTargets); 537 580 clipReportFormatsToVBox(pCtx); 538 581 } … … 545 588 * unit test. So keep it simple, be paranoid and log everything. 546 589 */ 547 static void clipConvertX11Targets(Widget widget, XtPointer p SvcCtxData,590 static void clipConvertX11Targets(Widget widget, XtPointer pClientData, 548 591 Atom * /* selection */, Atom *atomType, 549 592 XtPointer pValue, long unsigned int *pcLen, 550 593 int *piFormat) 551 594 { 552 RT_NOREF(piFormat); 553 554 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pSvcCtxData); 595 RT_NOREF1(piFormat); 596 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClientData); 555 597 Atom *pAtoms = (Atom *)pValue; 556 598 unsigned i, j; 557 558 LogRel2(("Shared clipboard: pValue=%p, *pcLen=%u, *atomType=%d%s\n", 599 LogRel2(("%s: pValue=%p, *pcLen=%u, *atomType=%d%s\n", __FUNCTION__, 559 600 pValue, *pcLen, *atomType, 560 601 *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : "")); 561 562 CLIPX11FORMATIDX *paFmtIdx = NULL; 563 602 CLIPX11FORMAT *pFormats = NULL; 564 603 if (*pcLen && pValue && (*atomType != XT_CONVERT_FAIL /* time out */)) 565 paFmtIdx = (CLIPX11FORMATIDX *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMATIDX)); 566 604 pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT)); 567 605 #if defined(DEBUG) && !defined(TESTCASE) 568 606 if (pValue) 569 607 { 570 608 for (i = 0; i < *pcLen; ++i) 571 {572 609 if (pAtoms[i]) 573 610 { 574 611 char *pszName = XGetAtomName(XtDisplay(widget), pAtoms[i]); 575 LogRel(("Shared clipboard: Found target %s\n", pszName)); 612 LogRel2(("%s: found target %s\n", __FUNCTION__, 613 pszName)); 576 614 XFree(pszName); 577 615 } 578 616 else 579 LogRel(("Shared clipboard: Found empty target\n")); 580 } 617 LogRel2(("%s: found empty target.\n", __FUNCTION__)); 581 618 } 582 619 #endif 583 584 if (paFmtIdx) 620 if (pFormats) 585 621 { 586 622 for (i = 0; i < *pcLen; ++i) … … 588 624 for (j = 0; j < RT_ELEMENTS(g_aFormats); ++j) 589 625 { 590 Atom target = XInternAtom(XtDisplay(widget), g_aFormats[j].pcszAtom, False); 626 Atom target = XInternAtom(XtDisplay(widget), 627 g_aFormats[j].pcszAtom, False); 591 628 if (*(pAtoms + i) == target) 592 p aFmtIdx[i] = j;629 pFormats[i] = j; 593 630 } 594 631 #if defined(DEBUG) && !defined(TESTCASE) 595 LogRel (("Shared clipboard: Reporting format %d (%s)\n",596 paFmtIdx[i], g_aFormats[paFmtIdx[i]].pcszAtom));632 LogRel2(("%s: reporting format %d (%s)\n", __FUNCTION__, 633 pFormats[i], g_aFormats[pFormats[i]].pcszAtom)); 597 634 #endif 598 635 } 599 636 } 600 637 else 601 LogRel2(("Shared clipboard: Reporting empty targets (none reported or allocation failure)\n")); 602 603 clipUpdateX11Targets(pCtx, paFmtIdx, *pcLen); 604 605 RTMemFree(paFmtIdx); 638 LogRel2(("%s: reporting empty targets (none reported or allocation failure).\n", 639 __FUNCTION__)); 640 clipUpdateX11Targets(pCtx, pFormats, *pcLen); 641 RTMemFree(pFormats); 606 642 XtFree(reinterpret_cast<char *>(pValue)); 607 643 } … … 616 652 static void clipQueryX11CBFormats(CLIPBACKEND *pCtx) 617 653 { 618 LogRel2 ((" Shared clipboard: Requesting the targets that the X11 clipboard offers\n"));619 654 LogRel2 (("%s: requesting the targets that the X11 clipboard offers\n", 655 __PRETTY_FUNCTION__)); 620 656 #ifndef VBOX_AFTER_5_2 621 657 if (pCtx->fBusy) … … 682 718 static DECLCALLBACK(int) clipEventThread(RTTHREAD hThreadSelf, void *pvUser) 683 719 { 684 RT_NOREF(hThreadSelf); 685 720 RT_NOREF1(hThreadSelf); 686 721 LogRel(("Shared clipboard: Starting shared clipboard thread\n")); 687 722 … … 690 725 if (pCtx->fGrabClipboardOnStart) 691 726 clipQueryX11CBFormats(pCtx); 692 693 727 while (XtAppGetExitFlag(pCtx->appContext) == FALSE) 694 728 { … … 696 730 XtAppProcessEvent(pCtx->appContext, XtIMAll); 697 731 } 698 699 732 LogRel(("Shared clipboard: Shared clipboard thread terminated successfully\n")); 700 733 return VINF_SUCCESS; … … 731 764 static void clipStopEventThreadWorker(void *pUserData, void *) 732 765 { 766 733 767 CLIPBACKEND *pCtx = (CLIPBACKEND *)pUserData; 734 768 … … 795 829 #endif 796 830 797 /** 798 * This is the callback which is scheduled when data is available on the 799 * wakeup pipe. It simply reads all data from the pipe. 800 */ 831 /** This is the callback which is scheduled when data is available on the 832 * wakeup pipe. It simply reads all data from the pipe. */ 801 833 static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *) 802 834 { … … 804 836 char acBuf[WAKE_UP_STRING_LEN]; 805 837 806 LogRel2(("Shared clipboard: clipDrainWakeupPipe called\n")); 807 838 LogRel2(("clipDrainWakeupPipe: called\n")); 808 839 while (read(pCtx->wakeupPipeRead, acBuf, sizeof(acBuf)) > 0) {} 809 840 } 810 841 811 /** 812 * X11 specific initialisation for the shared clipboard. 813 * 842 /** X11 specific initialisation for the shared clipboard. 814 843 * @note X11 backend code. 815 844 */ … … 832 861 if (NULL == pDisplay) 833 862 { 834 LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running \n"));863 LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running.\n")); 835 864 rc = VERR_NOT_SUPPORTED; 836 865 } … … 840 869 rc = clipLoadXFixes(pDisplay, pCtx); 841 870 if (RT_FAILURE(rc)) 842 LogRel(("Shared clipboard: Failed to load the XFIXES extension \n"));871 LogRel(("Shared clipboard: Failed to load the XFIXES extension.\n")); 843 872 } 844 873 #endif … … 851 880 if (NULL == pCtx->widget) 852 881 { 853 LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager \n"));882 LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager.\n")); 854 883 rc = VERR_NO_MEMORY; 855 884 } … … 882 911 rc = RTErrConvertFromErrno(errno); 883 912 if (RT_FAILURE(rc)) 884 LogRel(("Shared clipboard: Failed to setup the termination mechanism \n"));913 LogRel(("Shared clipboard: Failed to setup the termination mechanism.\n")); 885 914 } 886 915 else … … 894 923 895 924 /** 896 * Constructs the X11 backend of the shared clipboard. 897 * 925 * Construct the X11 backend of the shared clipboard. 898 926 * @note X11 backend code 899 927 */ … … 909 937 * This is important for VBoxHeadless. 910 938 */ 911 LogRel (("Shared clipboard: X11 DISPLAY variable not set -- disabling Shared Clipboard\n"));939 LogRelFunc(("X11 DISPLAY variable not set -- disabling shared clipboard\n")); 912 940 pCtx->fHaveX11 = false; 913 941 return pCtx; … … 917 945 918 946 LogRel(("Shared clipboard: Initializing X11 clipboard backend\n")); 919 920 947 if (pCtx) 921 948 pCtx->pFrontend = pFrontend; … … 924 951 925 952 /** 926 * Destructs the shared clipboard X11 backend. 927 * 953 * Destruct the shared clipboard X11 backend. 928 954 * @note X11 backend code 929 955 */ … … 939 965 940 966 /** 941 * Announces to the X11 backend that we are ready to start. 942 * 967 * Announce to the X11 backend that we are ready to start. 943 968 * @param grab whether we should try to grab the shared clipboard at once 944 969 */ … … 946 971 { 947 972 int rc = VINF_SUCCESS; 948 949 LogRel2(("Shared clipboard: Starting\n")); 950 973 LogRelFlowFunc(("\n")); 951 974 /* 952 975 * Immediately return if we are not connected to the X server. … … 968 991 if (RT_FAILURE(rc)) 969 992 { 970 LogRel(("Shared clipboard: Failed to start the shared clipboard thread , rc=%Rrc\n", rc));993 LogRel(("Shared clipboard: Failed to start the shared clipboard thread.\n")); 971 994 clipUninit(pCtx); 972 995 } … … 977 1000 978 1001 /** 979 * Shuts down the shared clipboard X11 backend. 980 * 981 * @note X11 backend code. 1002 * Shut down the shared clipboard X11 backend. 1003 * @note X11 backend code 982 1004 * @note Any requests from this object to get clipboard data from VBox 983 1005 * *must* have completed or aborted before we are called, as … … 995 1017 return VINF_SUCCESS; 996 1018 997 LogRel(("Shared clipboard: Stopping X11 backend\n")); 998 1019 LogRelFunc(("stopping the shared clipboard X11 backend\n")); 999 1020 /* Write to the "stop" pipe */ 1000 1021 clipQueueToEventThread(pCtx, clipStopEventThreadWorker, (XtPointer) pCtx); … … 1014 1035 AssertRC(rcThread); 1015 1036 else 1016 LogRel(("Shared clipboard: Stopping X11 backend failed with rc=%Rrc\n", rc)); 1017 1037 LogRelFunc(("rc=%Rrc\n", rc)); 1018 1038 clipUninit(pCtx); 1019 1039 LogRelFlowFunc(("returning %Rrc.\n", rc)); 1020 1040 RT_NOREF_PV(rcThread); 1021 1041 return rc; … … 1025 1045 * Satisfy a request from X11 for clipboard targets supported by VBox. 1026 1046 * 1027 * @returns IPRT status code.1028 * @param atomTypeReturn The type of the data we are returning .1047 * @returns iprt status code 1048 * @param atomTypeReturn The type of the data we are returning 1029 1049 * @param pValReturn A pointer to the data we are returning. This 1030 1050 * should be set to memory allocated by XtMalloc, 1031 1051 * which will be freed later by the Xt toolkit. 1032 * @param pcLenReturn The length of the data we are returning .1052 * @param pcLenReturn The length of the data we are returning 1033 1053 * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are 1034 * returning. 1035 * 1054 * returning 1036 1055 * @note X11 backend code, called by the XtOwnSelection callback. 1037 1056 */ … … 1041 1060 int *piFormatReturn) 1042 1061 { 1043 Atom *atomTargets = (Atom *)XtMalloc((CLIPX11FORMATIDX_MAX + 3) * sizeof(Atom)); 1062 Atom *atomTargets = (Atom *)XtMalloc( (MAX_CLIP_X11_FORMATS + 3) 1063 * sizeof(Atom)); 1044 1064 unsigned cTargets = 0; 1045 1046 1065 LogRelFlowFunc (("called\n")); 1047 1048 CLIPX11FORMATIDX fmtIdx = CLIPX11FORMATIDX_NIL; 1049 1066 CLIPX11FORMAT format = NIL_CLIPX11FORMAT; 1050 1067 do 1051 1068 { 1052 f mtIdx = clipEnumFmtIdxForVBoxFmt(pCtx->vboxFormats, fmtIdx);1053 if (f mtIdx != CLIPX11FORMATIDX_NIL)1069 format = clipEnumX11Formats(pCtx->vboxFormats, format); 1070 if (format != NIL_CLIPX11FORMAT) 1054 1071 { 1055 atomTargets[cTargets] = clip GetAtomFromFmtIdx(pCtx, fmtIdx);1072 atomTargets[cTargets] = clipAtomForX11Format(pCtx, format); 1056 1073 ++cTargets; 1057 1074 } 1058 } while (fmtIdx != CLIPX11FORMATIDX_NIL); 1059 1075 } while (format != NIL_CLIPX11FORMAT); 1060 1076 /* We always offer these */ 1061 atomTargets[cTargets] 1077 atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS"); 1062 1078 atomTargets[cTargets + 1] = clipGetAtom(pCtx, "MULTIPLE"); 1063 1079 atomTargets[cTargets + 2] = clipGetAtom(pCtx, "TIMESTAMP"); 1064 1065 1080 *atomTypeReturn = XA_ATOM; 1066 1081 *pValReturn = (XtPointer)atomTargets; 1067 1082 *pcLenReturn = cTargets + 3; 1068 1083 *piFormatReturn = 32; 1069 1070 1084 return VINF_SUCCESS; 1071 1085 } 1072 1086 1073 /** 1074 * This is a wrapper around ClipRequestDataForX11 that will cache the 1087 /** This is a wrapper around ClipRequestDataForX11 that will cache the 1075 1088 * data returned. 1076 1089 */ 1077 static int clipReadVBoxClipboard(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMAT vboxFormat,1090 static int clipReadVBoxClipboard(CLIPBACKEND *pCtx, uint32_t u32Format, 1078 1091 void **ppv, uint32_t *pcb) 1079 1092 { 1080 1093 int rc = VINF_SUCCESS; 1081 LogRelFlowFunc(("pCtx=%p, vboxFormat=%02X, ppv=%p, pcb=%p\n", pCtx,1082 vboxFormat, ppv, pcb));1083 if ( vboxFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)1094 LogRelFlowFunc(("pCtx=%p, u32Format=%02X, ppv=%p, pcb=%p\n", pCtx, 1095 u32Format, ppv, pcb)); 1096 if (u32Format == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 1084 1097 { 1085 1098 if (pCtx->pvUnicodeCache == NULL) 1086 rc = ClipRequestDataForX11(pCtx->pFrontend, vboxFormat,1099 rc = ClipRequestDataForX11(pCtx->pFrontend, u32Format, 1087 1100 &pCtx->pvUnicodeCache, 1088 1101 &pCtx->cbUnicodeCache); … … 1096 1109 } 1097 1110 else 1098 rc = ClipRequestDataForX11(pCtx->pFrontend, vboxFormat,1111 rc = ClipRequestDataForX11(pCtx->pFrontend, u32Format, 1099 1112 ppv, pcb); 1100 1113 LogRelFlowFunc(("returning %Rrc\n", rc)); … … 1105 1118 1106 1119 /** 1107 * Calculates a buffer size large enough to hold the source Windows format 1108 * text converted into Unix Utf8, including the null terminator. 1109 * 1110 * @returns IPRT status code. 1111 * @param pwsz the source text in UCS-2 with Windows EOLs. 1120 * Calculate a buffer size large enough to hold the source Windows format 1121 * text converted into Unix Utf8, including the null terminator 1122 * @returns iprt status code 1123 * @param pwsz the source text in UCS-2 with Windows EOLs 1112 1124 * @param cwc the size in USC-2 elements of the source text, with or 1113 * without the terminator .1114 * @param pcbActual where to store the buffer size needed .1125 * without the terminator 1126 * @param pcbActual where to store the buffer size needed 1115 1127 */ 1116 1128 static int clipWinTxtBufSizeForUtf8(PRTUTF16 pwsz, size_t cwc, … … 1125 1137 1126 1138 /** 1127 * Convert stext from Windows format (UCS-2 with CRLF line endings) to standard1139 * Convert text from Windows format (UCS-2 with CRLF line endings) to standard 1128 1140 * Utf-8. 1129 1141 * 1130 * @returns IPRT status code. 1131 * @param pwszSrc the text to be converted. 1132 * @param cbSrc the length of @a pwszSrc in bytes. 1133 * @param pszBuf where to write the converted string. 1134 * @param cbBuf the size of the buffer pointed to by @a pszBuf. 1142 * @returns iprt status code 1143 * 1144 * @param pwszSrc the text to be converted 1145 * @param cbSrc the length of @a pwszSrc in bytes 1146 * @param pszBuf where to write the converted string 1147 * @param cbBuf the size of the buffer pointed to by @a pszBuf 1135 1148 * @param pcbActual where to store the size of the converted string. 1136 1149 * optional. … … 1166 1179 LogRelFlowFunc(("returning %Rrc\n", rc)); 1167 1180 if (RT_SUCCESS(rc)) 1168 LogRelFlowFunc (("converted string is %.*s. Returning \n", cbDest,1181 LogRelFlowFunc (("converted string is %.*s. Returning.\n", cbDest, 1169 1182 pszBuf)); 1170 1183 return rc; … … 1172 1185 1173 1186 /** 1174 * Satisf iesa request from X11 to convert the clipboard text to Utf-8. We1187 * Satisfy a request from X11 to convert the clipboard text to Utf-8. We 1175 1188 * return null-terminated text, but can cope with non-null-terminated input. 1176 1189 * 1177 * @returns IPRT status code.1190 * @returns iprt status code 1178 1191 * @param pDisplay an X11 display structure, needed for conversions 1179 * performed by Xlib .1180 * @param pv the text to be converted (UCS-2 with Windows EOLs) .1181 * @param cb the length of the text in @cb in bytes .1192 * performed by Xlib 1193 * @param pv the text to be converted (UCS-2 with Windows EOLs) 1194 * @param cb the length of the text in @cb in bytes 1182 1195 * @param atomTypeReturn where to store the atom for the type of the data 1183 * we are returning .1196 * we are returning 1184 1197 * @param pValReturn where to store the pointer to the data we are 1185 1198 * returning. This should be to memory allocated by … … 1187 1200 * later. 1188 1201 * @param pcLenReturn where to store the length of the data we are 1189 * returning .1202 * returning 1190 1203 * @param piFormatReturn where to store the bit width (8, 16, 32) of the 1191 * data we are returning .1204 * data we are returning 1192 1205 */ 1193 1206 static int clipWinTxtToUtf8ForX11CB(Display *pDisplay, PRTUTF16 pwszSrc, … … 1198 1211 int *piFormatReturn) 1199 1212 { 1200 RT_NOREF (pDisplay, pcLenReturn);1213 RT_NOREF2(pDisplay, pcLenReturn); 1201 1214 1202 1215 /* This may slightly overestimate the space needed. */ … … 1222 1235 1223 1236 /** 1224 * Satisf iesa request from X11 to convert the clipboard HTML fragment to Utf-8. We1237 * Satisfy a request from X11 to convert the clipboard HTML fragment to Utf-8. We 1225 1238 * return null-terminated text, but can cope with non-null-terminated input. 1226 1239 * 1227 * @returns IPRT status code.1240 * @returns iprt status code 1228 1241 * @param pDisplay an X11 display structure, needed for conversions 1229 * performed by Xlib .1230 * @param pv the text to be converted (UTF8 with Windows EOLs) .1231 * @param cb the length of the text in @cb in bytes .1242 * performed by Xlib 1243 * @param pv the text to be converted (UTF8 with Windows EOLs) 1244 * @param cb the length of the text in @cb in bytes 1232 1245 * @param atomTypeReturn where to store the atom for the type of the data 1233 * we are returning .1246 * we are returning 1234 1247 * @param pValReturn where to store the pointer to the data we are 1235 1248 * returning. This should be to memory allocated by … … 1237 1250 * later. 1238 1251 * @param pcLenReturn where to store the length of the data we are 1239 * returning .1252 * returning 1240 1253 * @param piFormatReturn where to store the bit width (8, 16, 32) of the 1241 * data we are returning .1254 * data we are returning 1242 1255 */ 1243 1256 static int clipWinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc, … … 1248 1261 int *piFormatReturn) 1249 1262 { 1250 RT_NOREF (pDisplay, pValReturn);1263 RT_NOREF2(pDisplay, pValReturn); 1251 1264 1252 1265 /* This may slightly overestimate the space needed. */ … … 1267 1280 } 1268 1281 1282 1269 1283 /** 1270 1284 * Does this atom correspond to one of the two selection types we support? 1271 *1272 1285 * @param widget a valid Xt widget 1273 1286 * @param selType the atom in question … … 1280 1293 1281 1294 /** 1282 * Remove sa trailing nul character from a string by adjusting the string1295 * Remove a trailing nul character from a string by adjusting the string 1283 1296 * length. Some X11 applications don't like zero-terminated text... 1284 *1285 1297 * @param pText the text in question 1286 1298 * @param pcText the length of the text, adjusted on return … … 1288 1300 */ 1289 1301 static void clipTrimTrailingNul(XtPointer pText, unsigned long *pcText, 1290 CLIP X11FORMATTARGET format)1302 CLIPFORMAT format) 1291 1303 { 1292 1304 AssertPtrReturnVoid(pText); 1293 1305 AssertPtrReturnVoid(pcText); 1294 AssertReturnVoid( (format == CLIPX11FORMATTARGET_UTF8) 1295 || (format == CLIPX11FORMATTARGET_TEXT) 1296 || (format == CLIPX11FORMATTARGET_HTML)); 1306 AssertReturnVoid((format == UTF8) || (format == TEXT) || (format == HTML)); 1297 1307 if (((char *)pText)[*pcText - 1] == '\0') 1298 1308 --(*pcText); … … 1306 1316 { 1307 1317 int rc = VINF_SUCCESS; 1308 1309 CLIPX11FORMATIDX fmtIdx = clipGetFmtIdxFromAtom(pCtx, *atomTarget); 1310 CLIPX11FORMATTARGET fmtTgt = clipGetTargetFmtFromFmtIdx(fmtIdx); 1311 1312 if ( ((fmtTgt == CLIPX11FORMATTARGET_UTF8) || (fmtTgt == CLIPX11FORMATTARGET_TEXT)) 1318 CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx, *atomTarget); 1319 CLIPFORMAT format = clipRealFormatForX11Format(x11Format); 1320 if ( ((format == UTF8) || (format == TEXT)) 1313 1321 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)) 1314 1322 { 1315 1323 void *pv = NULL; 1316 1324 uint32_t cb = 0; 1317 rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pv, &cb); 1325 rc = clipReadVBoxClipboard(pCtx, 1326 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, 1327 &pv, &cb); 1318 1328 if (RT_SUCCESS(rc) && (cb == 0)) 1319 1329 rc = VERR_NO_DATA; 1320 1321 if (RT_SUCCESS(rc) && ( (fmtTgt == CLIPX11FORMATTARGET_UTF8) 1322 || (fmtTgt == CLIPX11FORMATTARGET_TEXT))) 1323 { 1330 if (RT_SUCCESS(rc) && ((format == UTF8) || (format == TEXT))) 1324 1331 rc = clipWinTxtToUtf8ForX11CB(XtDisplay(pCtx->widget), 1325 1332 (PRTUTF16)pv, cb, atomTarget, 1326 1333 atomTypeReturn, pValReturn, 1327 1334 pcLenReturn, piFormatReturn); 1328 }1329 1330 1335 if (RT_SUCCESS(rc)) 1331 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtTgt); 1332 1336 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format); 1333 1337 RTMemFree(pv); 1334 1338 } 1335 else if ( (f mtTgt == CLIPX11FORMATTARGET_BMP)1339 else if ( (format == BMP) 1336 1340 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)) 1337 1341 { 1338 1342 void *pv = NULL; 1339 1343 uint32_t cb = 0; 1340 rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, &pv, &cb); 1344 rc = clipReadVBoxClipboard(pCtx, 1345 VBOX_SHARED_CLIPBOARD_FMT_BITMAP, 1346 &pv, &cb); 1341 1347 if (RT_SUCCESS(rc) && (cb == 0)) 1342 1348 rc = VERR_NO_DATA; 1343 1344 if (RT_SUCCESS(rc) && (fmtTgt == CLIPX11FORMATTARGET_BMP)) 1349 if (RT_SUCCESS(rc) && (format == BMP)) 1345 1350 { 1346 /* Create a full BMP from it .*/1351 /* Create a full BMP from it */ 1347 1352 rc = vboxClipboardDibToBmp(pv, cb, (void **)pValReturn, 1348 1353 (size_t *)pcLenReturn); … … 1356 1361 *piFormatReturn = 8; 1357 1362 } 1358 1359 1363 RTMemFree(pv); 1360 1364 } 1361 else if ( (fmtTgt == CLIPX11FORMATTARGET_HTML)1362 1365 else if ( (format == HTML) 1366 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_HTML)) 1363 1367 { 1364 1368 void *pv = NULL; 1365 1369 uint32_t cb = 0; 1366 rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_HTML, &pv, &cb); 1370 rc = clipReadVBoxClipboard(pCtx, 1371 VBOX_SHARED_CLIPBOARD_FMT_HTML, 1372 &pv, &cb); 1367 1373 if (RT_SUCCESS(rc) && (cb == 0)) 1368 1374 rc = VERR_NO_DATA; 1369 1370 1375 if (RT_SUCCESS(rc)) 1371 1376 { … … 1379 1384 */ 1380 1385 rc = clipWinHTMLToUtf8ForX11CB(XtDisplay(pCtx->widget), 1381 (const char*)pv, cb, atomTarget, 1382 atomTypeReturn, pValReturn, 1383 pcLenReturn, piFormatReturn); 1386 (const char*)pv, cb, atomTarget, 1387 atomTypeReturn, pValReturn, 1388 pcLenReturn, piFormatReturn); 1389 1390 1384 1391 if (RT_SUCCESS(rc)) 1385 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtTgt); 1386 1392 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format); 1387 1393 RTMemFree(pv); 1388 1394 } 1389 1395 } 1390 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST1391 else if ( (fmtTgt == CLIPX11FORMATTARGET_URI_LIST)1392 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST))1393 {1394 /** Nothing to do here yet. */1395 }1396 #endif1397 1396 else 1398 1397 rc = VERR_NOT_SUPPORTED; … … 1401 1400 1402 1401 /** 1403 * Returns VBox's clipboard data for an X11 client. 1404 * 1405 * @note X11 backend code, callback for XtOwnSelection. 1402 * Return VBox's clipboard data for an X11 client. 1403 * @note X11 backend code, callback for XtOwnSelection 1406 1404 */ 1407 1405 static Boolean clipXtConvertSelectionProc(Widget widget, Atom *atomSelection, … … 1436 1434 CLIPBACKEND *pCtx; 1437 1435 /** Formats supported by VBox */ 1438 VBOXCLIPBOARDFORMATS vboxFormats;1436 uint32_t formats; 1439 1437 } CLIPNEWVBOXFORMATS; 1440 1438 … … 1450 1448 1451 1449 /** 1452 * Take spossession of the X11 clipboard (and middle-button selection).1453 */ 1454 static void clipGrabX11CB(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMATS vboxFormats)1450 * Take possession of the X11 clipboard (and middle-button selection). 1451 */ 1452 static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats) 1455 1453 { 1456 1454 if (XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1457 1455 CurrentTime, clipXtConvertSelectionProc, NULL, 0)) 1458 1456 { 1459 pCtx->vboxFormats = vboxFormats; 1460 1457 pCtx->vboxFormats = u32Formats; 1461 1458 /* Grab the middle-button paste selection too. */ 1462 1459 XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "PRIMARY"), … … 1478 1475 * Worker function for ClipAnnounceFormatToX11 which runs on the 1479 1476 * event thread. 1480 *1481 1477 * @param pUserData Pointer to a CLIPNEWVBOXFORMATS structure containing 1482 1478 * information about the VBox formats available and the 1483 1479 * clipboard context data. Must be freed by the worker. 1484 1480 */ 1485 static void clipNewVBoxFormatsWorker(void *pUserData, void * /* interval */) 1481 static void clipNewVBoxFormatsWorker(void *pUserData, 1482 void * /* interval */) 1486 1483 { 1487 1484 CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData; 1488 1489 1485 CLIPBACKEND *pCtx = pFormats->pCtx; 1490 VBOXCLIPBOARDFORMAT vboxFormat = pFormats->vboxFormats; 1491 1486 uint32_t u32Formats = pFormats->formats; 1492 1487 RTMemFree(pFormats); 1493 1494 LogRelFlowFunc (("vboxFormat=%RU32\n", vboxFormat)); 1495 1488 LogRelFlowFunc (("u32Formats=%d\n", u32Formats)); 1496 1489 clipInvalidateVBoxCBCache(pCtx); 1497 clipGrabX11CB(pCtx, vboxFormat);1490 clipGrabX11CB(pCtx, u32Formats); 1498 1491 clipResetX11Formats(pCtx); 1499 1500 1492 LogRelFlowFunc(("returning\n")); 1501 1493 } … … 1504 1496 * VBox is taking possession of the shared clipboard. 1505 1497 * 1506 * @param vboxFormats Clipboard formats that VBox is offering1498 * @param u32Formats Clipboard formats that VBox is offering 1507 1499 * @note X11 backend code 1508 1500 */ 1509 int ClipAnnounceFormatToX11(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMATS vboxFormats)1501 int ClipAnnounceFormatToX11(CLIPBACKEND *pCtx, uint32_t u32Formats) 1510 1502 { 1511 1503 /* … … 1515 1507 return VINF_SUCCESS; 1516 1508 1517 int rc;1518 1519 1509 /* This must be freed by the worker callback */ 1520 1510 CLIPNEWVBOXFORMATS *pFormats = 1521 1511 (CLIPNEWVBOXFORMATS *) RTMemAlloc(sizeof(CLIPNEWVBOXFORMATS)); 1522 1523 1512 if (pFormats != NULL) /* if it is we will soon have other problems */ 1524 1513 { 1525 1514 pFormats->pCtx = pCtx; 1526 pFormats-> vboxFormats = vboxFormats;1515 pFormats->formats = u32Formats; 1527 1516 clipQueueToEventThread(pCtx, clipNewVBoxFormatsWorker, 1528 1517 (XtPointer) pFormats); 1529 rc = VINF_SUCCESS; 1530 } 1531 else 1532 rc = VERR_NO_MEMORY; 1533 1534 return rc; 1535 } 1536 1537 /** 1538 * Massages generic Utf16 with CR end-of-lines into the format Windows expects 1518 } 1519 1520 return VINF_SUCCESS; 1521 } 1522 1523 /** 1524 * Massage generic Utf16 with CR end-of-lines into the format Windows expects 1539 1525 * and return the result in a RTMemAlloc allocated buffer. 1540 * 1541 * @returns IPRT status code. 1542 * @param pwcSrc The source Utf16. 1526 * @returns IPRT status code 1527 * @param pwcSrc The source Utf16 1543 1528 * @param cwcSrc The number of 16bit elements in @a pwcSrc, not counting 1544 * the terminating zero .1545 * @param ppwszDest Where to store the buffer address .1529 * the terminating zero 1530 * @param ppwszDest Where to store the buffer address 1546 1531 * @param pcbDest On success, where to store the number of bytes written. 1547 * Undefined otherwise. Optional .1532 * Undefined otherwise. Optional 1548 1533 */ 1549 1534 static int clipUtf16ToWinTxt(RTUTF16 *pwcSrc, size_t cwcSrc, … … 1584 1569 1585 1570 /** 1586 * Convert sUtf-8 text with CR end-of-lines into Utf-16 as Windows expects it1571 * Convert Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it 1587 1572 * and return the result in a RTMemAlloc allocated buffer. 1588 * 1589 * @returns IPRT status code. 1590 * @param pcSrc The source Utf-8. 1573 * @returns IPRT status code 1574 * @param pcSrc The source Utf-8 1591 1575 * @param cbSrc The size of the source in bytes, not counting the 1592 * terminating zero .1593 * @param ppwszDest Where to store the buffer address .1576 * terminating zero 1577 * @param ppwszDest Where to store the buffer address 1594 1578 * @param pcbDest On success, where to store the number of bytes written. 1595 * Undefined otherwise. Optional .1579 * Undefined otherwise. Optional 1596 1580 */ 1597 1581 static int clipUtf8ToWinTxt(const char *pcSrc, unsigned cbSrc, … … 1618 1602 1619 1603 /** 1620 * Convert sLatin-1 text with CR end-of-lines into Utf-16 as Windows expects1604 * Convert Latin-1 text with CR end-of-lines into Utf-16 as Windows expects 1621 1605 * it and return the result in a RTMemAlloc allocated buffer. 1622 * 1623 * @returns IPRT status code. 1624 * @param pcSrc The source text. 1606 * @returns IPRT status code 1607 * @param pcSrc The source text 1625 1608 * @param cbSrc The size of the source in bytes, not counting the 1626 * terminating zero .1627 * @param ppwszDest Where to store the buffer address .1609 * terminating zero 1610 * @param ppwszDest Where to store the buffer address 1628 1611 * @param pcbDest On success, where to store the number of bytes written. 1629 * Undefined otherwise. Optional .1612 * Undefined otherwise. Optional 1630 1613 */ 1631 1614 static int clipLatin1ToWinTxt(char *pcSrc, unsigned cbSrc, … … 1681 1664 1682 1665 /** 1683 * Converts Utf16 text into UTF8 as Windows expects 1684 * it and return the result in a RTMemAlloc allocated buffer. 1685 * 1686 * @returns IPRT status code. 1687 * @param pcSrc The source text. 1688 * @param cbSrc The size of the source in bytes, not counting the 1689 * terminating zero. 1690 * @param ppwszDest Where to store the buffer address. 1691 * @param pcbDest On success, where to store the number of bytes written. 1692 * Undefined otherwise. Optional. 1693 */ 1666 * Convert Utf16 text into UTF8 as Windows expects 1667 * it and return the result in a RTMemAlloc allocated buffer. 1668 * @returns IPRT status code 1669 * @param pcSrc The source text 1670 * @param cbSrc The size of the source in bytes, not counting the 1671 * terminating zero 1672 * @param ppwszDest Where to store the buffer address 1673 * @param pcbDest On success, where to store the number of bytes written. 1674 * Undefined otherwise. Optional 1675 */ 1694 1676 int clipUTF16ToWinHTML(RTUTF16 *pwcBuf, size_t cb, char **ppszOut, uint32_t *pcOut) 1695 1677 { … … 1752 1734 } 1753 1735 1736 1737 1754 1738 /** A structure containing information about where to store a request 1755 1739 * for the X11 clipboard contents. */ 1756 1740 struct _CLIPREADX11CBREQ 1757 1741 { 1758 /** @todo r=andy Why all those different CLIPX11FORMATTARGET members? Shouldn't be one enough? */1759 1760 1742 /** The format VBox would like the data in */ 1761 VBOXCLIPBOARDFORMATmFormat;1743 uint32_t mFormat; 1762 1744 /** The text format we requested from X11 if we requested text */ 1763 CLIPX11FORMAT IDX mTextFmtIdx;1745 CLIPX11FORMAT mTextFormat; 1764 1746 /** The bitmap format we requested from X11 if we requested bitmap */ 1765 CLIPX11FORMAT IDX mBitmapFmtIdx;1747 CLIPX11FORMAT mBitmapFormat; 1766 1748 /** The HTML format we requested from X11 if we requested HTML */ 1767 CLIPX11FORMATIDX mHtmlFmtIdx; 1768 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 1769 /** The URI list format we requested from X11 if we requested URI list */ 1770 CLIPX11FORMATIDX mURIListFmtIdx; 1771 #endif 1749 CLIPX11FORMAT mHtmlFormat; 1772 1750 /** The clipboard context this request is associated with */ 1773 1751 CLIPBACKEND *mCtx; … … 1779 1757 1780 1758 /** 1781 * Convert sthe data obtained from the X11 clipboard to the required format,1759 * Convert the data obtained from the X11 clipboard to the required format, 1782 1760 * place it in the buffer supplied and signal that data has arrived. 1783 1761 * Convert the text obtained UTF-16LE with Windows EOLs. 1784 1762 * Convert full BMP data to DIB format. 1785 *1786 1763 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1787 1764 * the X11 clipboard contains a format we understand. 1788 1765 */ 1789 static void clipConvertX11CB(void *p SvcCtxData, void *pvSrc, unsigned cbSrc)1790 { 1791 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) p SvcCtxData;1766 static void clipConvertX11CB(void *pClientData, void *pvSrc, unsigned cbSrc) 1767 { 1768 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pClientData; 1792 1769 LogRelFlowFunc(("pReq->mFormat=%02X, pReq->mTextFormat=%u, " 1793 1770 "pReq->mBitmapFormat=%u, pReq->mHtmlFormat=%u, pReq->mCtx=%p\n", 1794 pReq->mFormat, pReq->mTextF mtIdx, pReq->mBitmapFmtIdx,1795 pReq->mHtmlF mtIdx, pReq->mCtx));1771 pReq->mFormat, pReq->mTextFormat, pReq->mBitmapFormat, 1772 pReq->mHtmlFormat, pReq->mCtx)); 1796 1773 AssertPtr(pReq->mCtx); 1797 1774 Assert(pReq->mFormat != 0); /* sanity */ … … 1814 1791 { 1815 1792 /* In which format is the clipboard data? */ 1816 switch (clip GetTargetFmtFromFmtIdx(pReq->mTextFmtIdx))1793 switch (clipRealFormatForX11Format(pReq->mTextFormat)) 1817 1794 { 1818 case CLIPX11FORMATTARGET_UTF8:1819 case CLIPX11FORMATTARGET_TEXT:1795 case UTF8: 1796 case TEXT: 1820 1797 { 1821 1798 /* If we are given broken Utf-8, we treat it as Latin1. Is … … 1837 1814 { 1838 1815 /* In which format is the clipboard data? */ 1839 switch (clip GetTargetFmtFromFmtIdx(pReq->mBitmapFmtIdx))1816 switch (clipRealFormatForX11Format(pReq->mBitmapFormat)) 1840 1817 { 1841 case CLIPX11FORMATTARGET_BMP:1818 case BMP: 1842 1819 { 1843 1820 const void *pDib; … … 1865 1842 { 1866 1843 /* In which format is the clipboard data? */ 1867 switch (clip GetTargetFmtFromFmtIdx(pReq->mHtmlFmtIdx))1844 switch (clipRealFormatForX11Format(pReq->mHtmlFormat)) 1868 1845 { 1869 case CLIPX11FORMATTARGET_HTML:1846 case HTML: 1870 1847 { 1871 1848 /* The common VBox HTML encoding will be - Utf8 … … 1914 1891 } 1915 1892 } 1916 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST1917 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)1918 {1919 // @todo1920 }1921 #endif1922 1893 else 1923 1894 rc = VERR_NOT_IMPLEMENTED; … … 1931 1902 #ifndef TESTCASE 1932 1903 /** 1933 * Convert sthe data obtained from the X11 clipboard to the required format,1904 * Convert the data obtained from the X11 clipboard to the required format, 1934 1905 * place it in the buffer supplied and signal that data has arrived. 1935 1906 * Convert the text obtained UTF-16LE with Windows EOLs. 1936 1907 * Convert full BMP data to DIB format. 1937 *1938 1908 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1939 1909 * the X11 clipboard contains a format we understand. 1940 1910 */ 1941 static void cbConvertX11CB(Widget widget, XtPointer p SvcCtxData,1911 static void cbConvertX11CB(Widget widget, XtPointer pClientData, 1942 1912 Atom * /* selection */, Atom *atomType, 1943 1913 XtPointer pvSrc, long unsigned int *pcLen, 1944 1914 int *piFormat) 1945 1915 { 1946 RT_NOREF (widget);1916 RT_NOREF1(widget); 1947 1917 if (*atomType == XT_CONVERT_FAIL) /* Xt timeout */ 1948 clipConvertX11CB(p SvcCtxData, NULL, 0);1918 clipConvertX11CB(pClientData, NULL, 0); 1949 1919 else 1950 clipConvertX11CB(p SvcCtxData, pvSrc, (*pcLen) * (*piFormat) / 8);1920 clipConvertX11CB(pClientData, pvSrc, (*pcLen) * (*piFormat) / 8); 1951 1921 1952 1922 XtFree((char *)pvSrc); … … 1955 1925 1956 1926 #ifdef TESTCASE 1957 static void testRequestData(CLIPBACKEND* pCtx, CLIPX11FORMAT TARGETtarget,1927 static void testRequestData(CLIPBACKEND* pCtx, CLIPX11FORMAT target, 1958 1928 void *closure); 1959 1929 #endif 1960 1930 1961 static void getSelectionValue(CLIPBACKEND *pCtx, CLIPX11FORMAT IDXformat,1931 static void getSelectionValue(CLIPBACKEND *pCtx, CLIPX11FORMAT format, 1962 1932 CLIPREADX11CBREQ *pReq) 1963 1933 { 1964 1934 #ifndef TESTCASE 1965 1935 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1966 clip GetAtomFromFmtIdx(pCtx, format),1936 clipAtomForX11Format(pCtx, format), 1967 1937 cbConvertX11CB, 1968 1938 reinterpret_cast<XtPointer>(pReq), … … 1975 1945 /** Worker function for ClipRequestDataFromX11 which runs on the event 1976 1946 * thread. */ 1977 static void vboxClipboardReadX11Worker(void *pUserData, void * /* interval */) 1947 static void vboxClipboardReadX11Worker(void *pUserData, 1948 void * /* interval */) 1978 1949 { 1979 1950 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *)pUserData; … … 1986 1957 pCtx->fBusy = true; 1987 1958 if (fBusy) 1988 {1989 1959 /* If the clipboard is busy just fend off the request. */ 1990 1960 rc = VERR_TRY_AGAIN; 1991 }1992 1961 else 1993 1962 #endif … … 1997 1966 * VBox wants to read data in the given format. 1998 1967 */ 1999 pReq->mTextFmtIdx = pCtx->X11TextFmtIdx; 2000 if (pReq->mTextFmtIdx == CLIPX11FORMATIDX_NIL) 2001 { 1968 pReq->mTextFormat = pCtx->X11TextFormat; 1969 if (pReq->mTextFormat == INVALID) 2002 1970 /* VBox thinks we have data and we don't */ 2003 1971 rc = VERR_NO_DATA; 2004 }2005 else2006 {2007 /* Send out a request for the data to the current clipboard owner */2008 getSelectionValue(pCtx, pCtx->X11TextFmtIdx, pReq);2009 }2010 }2011 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP)2012 {2013 pReq->mBitmapFmtIdx = pCtx->X11BitmapFmtIdx;2014 if (pReq->mBitmapFmtIdx == CLIPX11FORMATIDX_NIL)2015 {2016 /* VBox thinks we have data and we don't */2017 rc = VERR_NO_DATA;2018 }2019 else2020 {2021 /* Send out a request for the data to the current clipboard2022 * owner */2023 getSelectionValue(pCtx, pCtx->X11BitmapFmtIdx, pReq);2024 }2025 }2026 else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_HTML)2027 {2028 /* Send out a request for the data to the current clipboard owner */2029 pReq->mHtmlFmtIdx = pCtx->X11HTMLFmtIdx;2030 if(pReq->mHtmlFmtIdx == CLIPX11FORMATIDX_NIL)2031 {2032 /* VBox thinks we have data and we don't */2033 rc = VERR_NO_DATA;2034 }2035 1972 else 2036 1973 /* Send out a request for the data to the current clipboard 2037 1974 * owner */ 2038 getSelectionValue(pCtx, pCtx->X11HTMLFmtIdx, pReq); 2039 } 2040 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 2041 else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 2042 { 2043 /* Send out a request for the data to the current clipboard owner */ 2044 pReq->mURIListFmtIdx = pCtx->X11URListFmtIdx; 2045 if(pReq->mURIListFmtIdx == CLIPX11FORMATIDX_NIL) 2046 { 1975 getSelectionValue(pCtx, pCtx->X11TextFormat, pReq); 1976 } 1977 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 1978 { 1979 pReq->mBitmapFormat = pCtx->X11BitmapFormat; 1980 if (pReq->mBitmapFormat == INVALID) 1981 /* VBox thinks we have data and we don't */ 1982 rc = VERR_NO_DATA; 1983 else 1984 /* Send out a request for the data to the current clipboard 1985 * owner */ 1986 getSelectionValue(pCtx, pCtx->X11BitmapFormat, pReq); 1987 } 1988 else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_HTML) 1989 { 1990 /* Send out a request for the data to the current clipboard 1991 * owner */ 1992 pReq->mHtmlFormat = pCtx->X11HTMLFormat; 1993 if(pReq->mHtmlFormat == INVALID) 2047 1994 /* VBox thinks we have data and we don't */ 2048 1995 rc = VERR_NO_DATA; 2049 }2050 1996 else 2051 { 2052 /* Send out a request for the data to the current clipboard owner */ 2053 getSelectionValue(pCtx, pCtx->X11HTMLFmtIdx, pReq); 2054 } 2055 } 2056 #endif 1997 /* Send out a request for the data to the current clipboard 1998 * owner */ 1999 getSelectionValue(pCtx, pCtx->X11HTMLFormat, pReq); 2000 } 2057 2001 else 2058 2002 { … … 2062 2006 #endif 2063 2007 } 2064 2065 2008 if (RT_FAILURE(rc)) 2066 2009 { … … 2071 2014 RTMemFree(pReq); 2072 2015 } 2073 2074 2016 LogRelFlowFunc(("status %Rrc\n", rc)); 2075 2017 } … … 2078 2020 * Called when VBox wants to read the X11 clipboard. 2079 2021 * 2080 * @returns IPRT status code.2081 * @param pCtx Context data for the clipboard backend .2082 * @param vboxFormat The format that the VBox would like to receive the data in.2083 * @param pv Where to write the data to.2084 * @param cb The size of the buffer to write the data to.2085 * @param pcbActual Where to write the actual size of the written data.2086 * 2087 * @note We allocate a request structure which must be freed by the worker .2088 */ 2089 int ClipRequestDataFromX11(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMAT vboxFormat,2022 * @returns iprt status code 2023 * @param pCtx Context data for the clipboard backend 2024 * @param u32Format The format that the VBox would like to receive the data 2025 * in 2026 * @param pv Where to write the data to 2027 * @param cb The size of the buffer to write the data to 2028 * @param pcbActual Where to write the actual size of the written data 2029 * @note We allocate a request structure which must be freed by the worker 2030 */ 2031 int ClipRequestDataFromX11(CLIPBACKEND *pCtx, uint32_t u32Format, 2090 2032 CLIPREADCBREQ *pReq) 2091 2033 { … … 2102 2044 else 2103 2045 { 2104 pX11Req->mFormat = vboxFormat;2046 pX11Req->mFormat = u32Format; 2105 2047 pX11Req->mCtx = pCtx; 2106 2048 pX11Req->mReq = pReq; … … 2176 2118 2177 2119 /* Return the data in the simulated VBox clipboard. */ 2178 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, VBOXCLIPBOARDFORMAT vboxFormat, void **ppv, uint32_t *pcb)2179 { 2180 RT_NOREF (pCtx, vboxFormat);2120 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb) 2121 { 2122 RT_NOREF2(pCtx, u32Format); 2181 2123 *pcb = g_vboxDatacb; 2182 2124 if (g_vboxDatapv != NULL) … … 2191 2133 2192 2134 Display *XtDisplay(Widget w) 2193 { RT_NOREF(w); return (Display *) 0xffff; }2194 2195 void XtAppSetExitFlag(XtAppContext app_context) { RT_NOREF(app_context); }2196 2197 void XtDestroyWidget(Widget w) { RT_NOREF(w); }2135 { NOREF(w); return (Display *) 0xffff; } 2136 2137 void XtAppSetExitFlag(XtAppContext app_context) { NOREF(app_context); } 2138 2139 void XtDestroyWidget(Widget w) { NOREF(w); } 2198 2140 2199 2141 XtAppContext XtCreateApplicationContext(void) { return (XtAppContext)0xffff; } 2200 2142 2201 void XtDestroyApplicationContext(XtAppContext app_context) { RT_NOREF(app_context); }2143 void XtDestroyApplicationContext(XtAppContext app_context) { NOREF(app_context); } 2202 2144 2203 2145 void XtToolkitInitialize(void) {} … … 2223 2165 } 2224 2166 2225 void XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed) { RT_NOREF (widget, mapped_when_managed); }2226 2227 void XtRealizeWidget(Widget widget) { RT_NOREF(widget); }2167 void XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed) { RT_NOREF2(widget, mapped_when_managed); } 2168 2169 void XtRealizeWidget(Widget widget) { NOREF(widget); } 2228 2170 2229 2171 XtInputId XtAppAddInput(XtAppContext app_context, int source, XtPointer condition, XtInputCallbackProc proc, XtPointer closure) … … 2255 2197 2256 2198 /* Take a request for the targets we are currently offering. */ 2257 static CLIPX11FORMAT TARGETg_selTargets[10] = { 0 };2199 static CLIPX11FORMAT g_selTargets[10] = { 0 }; 2258 2200 static size_t g_cTargets = 0; 2259 2201 … … 2270 2212 static int g_selFormat = 0; 2271 2213 2272 void testRequestData(CLIPBACKEND *pCtx, CLIPX11FORMAT TARGETtarget, void *closure)2273 { 2274 RT_NOREF (pCtx);2214 void testRequestData(CLIPBACKEND *pCtx, CLIPX11FORMAT target, void *closure) 2215 { 2216 RT_NOREF1(pCtx); 2275 2217 unsigned long count = 0; 2276 2218 int format = 0; … … 2299 2241 void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats) 2300 2242 { 2301 RT_NOREF (pCtx);2243 RT_NOREF1(pCtx); 2302 2244 g_fX11Formats = u32Formats; 2303 2245 } … … 2328 2270 XtSelectionDoneProc done) 2329 2271 { 2330 RT_NOREF (widget, time);2272 RT_NOREF2(widget, time); 2331 2273 if (selection != XInternAtom(NULL, "CLIPBOARD", 0)) 2332 2274 return True; /* We don't really care about this. */ … … 2379 2321 { 2380 2322 Atom clipAtom = XInternAtom(NULL, "CLIPBOARD", 0); 2381 g_selTargets[0] = clip GetFmtIdxFromAtomText(pcszTarget);2323 g_selTargets[0] = clipFindX11FormatByAtomText(pcszTarget); 2382 2324 g_cTargets = 1; 2383 2325 g_selType = type; … … 2405 2347 char *XGetAtomName(Display *display, Atom atom) 2406 2348 { 2407 RT_NOREF (display);2349 RT_NOREF1(display); 2408 2350 AssertReturn((unsigned)atom < RT_ELEMENTS(g_aFormats) + 1, NULL); 2409 2351 const char *pcszName = NULL; … … 2447 2389 void ClipCompleteDataRequestFromX11(VBOXCLIPBOARDCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb) 2448 2390 { 2449 RT_NOREF (pCtx);2391 RT_NOREF1(pCtx); 2450 2392 if (cb <= MAX_BUF_SIZE) 2451 2393 { … … 2600 2542 static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx, const char *pcszTarget, Atom typeExp, const char *valueExp) 2601 2543 { 2602 RT_NOREF (pCtx);2544 RT_NOREF1(pCtx); 2603 2545 bool retval = false; 2604 2546 Atom type; … … 2641 2583 static void testStringFromVBoxFailed(RTTEST hTest, CLIPBACKEND *pCtx, const char *pcszTarget) 2642 2584 { 2643 RT_NOREF (pCtx);2585 RT_NOREF1(pCtx); 2644 2586 Atom type; 2645 2587 XtPointer value = NULL; … … 2656 2598 static void testNoSelectionOwnership(CLIPBACKEND *pCtx, const char *pcszTestCtx) 2657 2599 { 2658 RT_NOREF (pCtx);2600 RT_NOREF1(pCtx); 2659 2601 RTTESTI_CHECK_MSG(!g_ownsSel, ("context: %s\n", pcszTestCtx)); 2660 2602 } … … 2682 2624 clipSendTargetUpdate(pCtx); 2683 2625 if (clipQueryFormats() == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 2684 RTTestFailed(hTest, "Failed to report targets after bad host request \n");2626 RTTestFailed(hTest, "Failed to report targets after bad host request.\n"); 2685 2627 } 2686 2628 } … … 2949 2891 void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats) 2950 2892 { 2951 RT_NOREF (pCtx, u32Formats);2893 RT_NOREF2(pCtx, u32Formats); 2952 2894 } 2953 2895
Note:
See TracChangeset
for help on using the changeset viewer.