Changeset 81656 in vbox for trunk/src/VBox/GuestHost
- Timestamp:
- Nov 4, 2019 4:40:12 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r81655 r81656 117 117 { "INVALID", INVALID, 0 }, 118 118 { "UTF8_STRING", UTF8, VBOX_SHCL_FMT_UNICODETEXT }, 119 { "text/plain;charset=UTF-8", UTF8, 120 VBOX_SHCL_FMT_UNICODETEXT }, 121 { "text/plain;charset=utf-8", UTF8, 122 VBOX_SHCL_FMT_UNICODETEXT }, 119 { "text/plain;charset=UTF-8", UTF8, VBOX_SHCL_FMT_UNICODETEXT }, 120 { "text/plain;charset=utf-8", UTF8, VBOX_SHCL_FMT_UNICODETEXT }, 123 121 { "STRING", TEXT, VBOX_SHCL_FMT_UNICODETEXT }, 124 122 { "TEXT", TEXT, VBOX_SHCL_FMT_UNICODETEXT }, 125 123 { "text/plain", TEXT, VBOX_SHCL_FMT_UNICODETEXT }, 126 124 { "text/html", HTML, VBOX_SHCL_FMT_HTML }, 127 { "text/html;charset=utf-8", HTML, 128 VBOX_SHCL_FMT_HTML }, 125 { "text/html;charset=utf-8", HTML, VBOX_SHCL_FMT_HTML }, 129 126 { "image/bmp", BMP, VBOX_SHCL_FMT_BITMAP }, 130 127 { "image/x-bmp", BMP, VBOX_SHCL_FMT_BITMAP }, … … 141 138 142 139 143 /** Return the atom corresponding to a supported X11 format. 140 /** 141 * Returns the atom corresponding to a supported X11 format. 144 142 * @param widget a valid Xt widget 145 143 */ … … 149 147 } 150 148 151 /** Return the CLIPFORMAT corresponding to a supported X11 format. */ 149 /** 150 * Returns the CLIPFORMAT corresponding to a supported X11 format. 151 */ 152 152 static CLIPFORMAT clipRealFormatForX11Format(CLIPX11FORMAT format) 153 153 { … … 155 155 } 156 156 157 /** Return the atom corresponding to a supported X11 format. */157 /** Returns the atom corresponding to a supported X11 format. */ 158 158 static uint32_t clipVBoxFormatForX11Format(CLIPX11FORMAT format) 159 159 { … … 161 161 } 162 162 163 /** Lookup the X11 format matching a given X11 atom. 164 * @returns the format on success, NIL_CLIPX11FORMAT on failure 165 * @param widget a valid Xt widget 163 /** 164 * Looks up the X11 format matching a given X11 atom. 165 * 166 * @returns The format on success, NIL_CLIPX11FORMAT on failure. 167 * @param Widget a valid Xt widget. 166 168 */ 167 169 static CLIPX11FORMAT clipFindX11FormatByAtom(CLIPBACKEND *pCtx, Atom atomFormat) … … 174 176 175 177 #ifdef TESTCASE 176 /** Lookup the X11 format matching a given X11 atom text. 178 /** 179 * Looks up the X11 format matching a given X11 atom text. 180 * 177 181 * @returns the format on success, NIL_CLIPX11FORMAT on failure 178 * @param widget a valid Xt widget182 * @param Widget a valid Xt widget. 179 183 */ 180 184 static CLIPX11FORMAT clipFindX11FormatByAtomText(const char *pcsz) … … 190 194 * Enumerates supported X11 clipboard formats corresponding to a given VBox 191 195 * format. 192 * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMAT if 193 * there are no more 196 * 197 * @returns The next matching X11 format in the list, or NIL_CLIPX11FORMAT if 198 * there are no more. 194 199 * @param lastFormat The value returned from the last call of this function. 195 200 * Use NIL_CLIPX11FORMAT to start the enumeration. … … 273 278 } g_contexts[CLIP_MAX_CONTEXTS]; 274 279 275 /** Register a new X11 clipboard context. */280 /** Registers a new X11 clipboard context. */ 276 281 static int clipRegisterContext(CLIPBACKEND *pCtx) 277 282 { … … 319 324 } 320 325 321 /** Find an X11 clipboard context. */326 /** Finds an X11 clipboard context. */ 322 327 static CLIPBACKEND *clipLookupContext(Widget widget) 323 328 { … … 335 340 } 336 341 337 /** Convert an atom name string to an X11 atom, looking it up in a cache338 * before asking the server */342 /** Converts an atom name string to an X11 atom, looking it up in a cache 343 * before asking the server. */ 339 344 static Atom clipGetAtom(CLIPBACKEND *pCtx, const char *pszName) 340 345 { … … 379 384 380 385 /** 381 * Report the formats currently supported by the X11 clipboard to VBox.386 * Reports the formats currently supported by the X11 clipboard to VBox. 382 387 */ 383 388 static void clipReportFormatsToVBox(CLIPBACKEND *pCtx) … … 394 399 395 400 /** 396 * Forget which formats were previously in the X11 clipboard. Called when we401 * Forgets which formats were previously in the X11 clipboard. Called when we 397 402 * grab the clipboard. */ 398 403 static void clipResetX11Formats(CLIPBACKEND *pCtx) … … 403 408 } 404 409 405 /** Tell VBox that X11 currently has nothing in its clipboard. */410 /** Tells VBox that X11 currently has nothing in its clipboard. */ 406 411 static void clipReportEmptyX11CB(CLIPBACKEND *pCtx) 407 412 { … … 414 419 * format we can support, and if so choose the ones we prefer (e.g. we like 415 420 * Utf8 better than plain text). 416 * @param pCtx the clipboard backend context structure 417 * @param pTargets the list of targets 418 * @param cTargets the size of the list in @a pTargets 421 * 422 * @return Supported X clipboard format. 423 * @param pCtx The clipboard backend context structure. 424 * @param pTargets The list of targets. 425 * @param cTargets The size of the list in @a pTargets. 419 426 */ 420 427 static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx, … … 422 429 size_t cTargets) 423 430 { 431 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 432 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 433 424 434 CLIPX11FORMAT bestTextFormat = NIL_CLIPX11FORMAT; 425 435 CLIPFORMAT enmBestTextTarget = INVALID; 426 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);427 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);428 436 for (unsigned i = 0; i < cTargets; ++i) 429 437 { … … 446 454 static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx) 447 455 { 448 bool success = true;456 bool fSuccess = true; 449 457 CLIPX11FORMAT targets[2]; 450 458 CLIPX11FORMAT x11Format; … … 453 461 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 454 462 if (clipRealFormatForX11Format(x11Format) != TEXT) 455 success = false;463 fSuccess = false; 456 464 targets[0] = clipFindX11FormatByAtomText("UTF8_STRING"); 457 465 targets[1] = clipFindX11FormatByAtomText("text/plain"); 458 466 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 459 467 if (clipRealFormatForX11Format(x11Format) != UTF8) 460 success = false;461 return success;468 fSuccess = false; 469 return fSuccess; 462 470 } 463 471 #endif 464 472 465 473 /** 466 * Go through an array of X11 clipboard targets to see if they contain a bitmap474 * Goes through an array of X11 clipboard targets to see if they contain a bitmap 467 475 * format we can support, and if so choose the ones we prefer (e.g. we like 468 476 * BMP better than PNG because we don't have to convert). 469 * @param pCtx the clipboard backend context structure 470 * @param pTargets the list of targets 471 * @param cTargets the size of the list in @a pTargets 477 * 478 * @return Supported X clipboard format. 479 * @param pCtx The clipboard backend context structure. 480 * @param pTargets The list of targets. 481 * @param cTargets The size of the list in @a pTargets. 472 482 */ 473 483 static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx, … … 475 485 size_t cTargets) 476 486 { 487 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 488 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 489 477 490 CLIPX11FORMAT bestBitmapFormat = NIL_CLIPX11FORMAT; 478 491 CLIPFORMAT enmBestBitmapTarget = INVALID; 479 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);480 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);481 492 for (unsigned i = 0; i < cTargets; ++i) 482 493 { … … 497 508 498 509 /** 499 * Go through an array of X11 clipboard targets to see if they contain a HTML 500 * format we can support, and if so choose the ones we prefer 501 * @param pCtx the clipboard backend context structure 502 * @param pTargets the list of targets 503 * @param cTargets the size of the list in @a pTargets 510 * Goes through an array of X11 clipboard targets to see if they contain a HTML 511 * format we can support, and if so choose the ones we prefer. 512 * 513 * @return Supported X clipboard format. 514 * @param pCtx The clipboard backend context structure. 515 * @param pTargets The list of targets. 516 * @param cTargets The size of the list in @a pTargets. 504 517 */ 505 518 static CLIPX11FORMAT clipGetHtmlFormatFromTargets(CLIPBACKEND *pCtx, … … 507 520 size_t cTargets) 508 521 { 522 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT); 523 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT); 524 509 525 CLIPX11FORMAT bestHTMLFormat = NIL_CLIPX11FORMAT; 510 526 CLIPFORMAT enmBestHtmlTarget = INVALID; 511 AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);512 AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);513 527 for (unsigned i = 0; i < cTargets; ++i) 514 528 { … … 529 543 530 544 /** 531 * Go through an array of X11 clipboard targets to see if we can support any545 * Goes through an array of X11 clipboard targets to see if we can support any 532 546 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8 533 547 * better than plain text). 534 * @param pCtx the clipboard backend context structure 535 * @param pTargets the list of targets 536 * @param cTargets the size of the list in @a pTargets 548 * 549 * @param pCtx The clipboard backend context structure. 550 * @param pTargets The list of targets. 551 * @param cTargets The size of the list in @a pTargets. 537 552 */ 538 553 static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, … … 565 580 566 581 /** 567 * Update the context's information about targets currently supported by X11,582 * Updates the context's information about targets currently supported by X11, 568 583 * based on an array of X11 atoms. 569 * @param pCtx the context to be updated570 * @param p Targets the array of atoms describing the targets supported571 * @param cTargets the size of the array @a pTargets572 * /573 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets, 574 575 { 576 Log Rel2 (("%s: called\n", __FUNCTION__));584 * 585 * @param pCtx The context to be updated. 586 * @param pTargets The array of atoms describing the targets supported. 587 * @param cTargets The size of the array @a pTargets. 588 */ 589 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets, size_t cTargets) 590 { 591 LogFlowFuncEnter(); 577 592 #ifndef VBOX_AFTER_5_2 578 593 pCtx->fBusy = false; … … 585 600 } 586 601 #endif 587 if (pTargets == NULL) { 602 if (pTargets == NULL) 603 { 588 604 /* No data available */ 589 605 clipReportEmptyX11CB(pCtx); … … 595 611 596 612 /** 597 * Notif ythe VBox clipboard about available data formats, based on the613 * Notifies the VBox clipboard about available data formats, based on the 598 614 * "targets" information obtained from the X11 clipboard. 615 * 599 616 * @note Callback for XtGetSelectionValue 600 617 * @note This function is treated as API glue, and as such is not part of any … … 607 624 { 608 625 RT_NOREF(piFormat); 626 609 627 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClient); 610 628 Atom *pAtoms = (Atom *)pValue; 611 629 unsigned i, j; 612 LogRel2(("%s: pValue=%p, *pcLen=%u, *atomType=%d%s\n", __FUNCTION__, 613 pValue, *pcLen, *atomType, 614 *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : "")); 630 631 LogFlowFunc(("pValue=%p, *pcLen=%u, *atomType=%d%s\n", 632 pValue, *pcLen, *atomType, *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : "")); 633 615 634 CLIPX11FORMAT *pFormats = NULL; 616 if (*pcLen && pValue && (*atomType != XT_CONVERT_FAIL /* time out */)) 617 pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT)); 635 if ( *pcLen 636 && pValue 637 && (*atomType != XT_CONVERT_FAIL /* time out */)) 638 { 639 pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT)); 640 } 618 641 #if defined(DEBUG) && !defined(TESTCASE) 619 642 if (pValue) … … 623 646 { 624 647 char *pszName = XGetAtomName(XtDisplay(widget), pAtoms[i]); 625 LogRel2(("%s: found target %s\n", __FUNCTION__, 626 pszName)); 648 LogFunc(("Found target '%s'\n", pszName)); 627 649 XFree(pszName); 628 650 } 629 651 else 630 Log Rel2(("%s: found empty target\n", __FUNCTION__));652 LogFunc(("Found empty target\n")); 631 653 } 632 654 #endif … … 649 671 } 650 672 else 651 Log Rel2(("%s: reporting empty targets (none reported or allocation failure).\n",652 __FUNCTION__)); 673 LogFunc(("Reporting empty targets (none reported or allocation failure)\n")); 674 653 675 clipUpdateX11Targets(pCtx, pFormats, *pcLen); 654 676 RTMemFree(pFormats); 677 655 678 XtFree(reinterpret_cast<char *>(pValue)); 656 679 } … … 665 688 static void clipQueryX11CBFormats(CLIPBACKEND *pCtx) 666 689 { 667 Log Rel2 (("%s: requesting the targets that the X11 clipboard offers\n",668 __PRETTY_FUNCTION__)); 690 LogFlowFuncEnter(); 691 669 692 #ifndef VBOX_AFTER_5_2 670 693 if (pCtx->fBusy) … … 675 698 pCtx->fBusy = true; 676 699 #endif 700 677 701 #ifndef TESTCASE 678 702 XtGetSelectionValue(pCtx->widget, … … 688 712 #ifndef TESTCASE 689 713 690 typedef struct { 714 typedef struct 715 { 691 716 int type; /* event base */ 692 717 unsigned long serial; … … 702 727 703 728 /** 704 * Wait until an event arrives and handle it if it is an XFIXES selection729 * Waits until an event arrives and handle it if it is an XFIXES selection 705 730 * event, which Xt doesn't know about. 706 731 */ … … 714 739 715 740 if (XtAppPeekEvent(pCtx->appContext, &event.event)) 741 { 716 742 if ( (event.event.type == pCtx->fixesEventBase) 717 743 && (event.fixes.owner != XtWindow(pCtx->widget))) … … 723 749 clipReportEmptyX11CB(pCtx); 724 750 } 751 } 725 752 } 726 753 … … 732 759 { 733 760 RT_NOREF(hThreadSelf); 734 LogRel(("Shared clipboard: Starting shared clipboardthread\n"));761 LogRel(("Shared Clipboard: Starting event thread\n")); 735 762 736 763 CLIPBACKEND *pCtx = (CLIPBACKEND *)pvUser; … … 743 770 XtAppProcessEvent(pCtx->appContext, XtIMAll); 744 771 } 745 LogRel(("Shared clipboard: Shared clipboardthread terminated successfully\n"));772 LogRel(("Shared Clipboard: Event thread terminated successfully\n")); 746 773 return VINF_SUCCESS; 747 774 } … … 846 873 static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *) 847 874 { 875 LogFlowFuncEnter(); 876 848 877 CLIPBACKEND *pCtx = (CLIPBACKEND *)pUserData; 849 878 char acBuf[WAKE_UP_STRING_LEN]; 850 879 851 LogRel2(("clipDrainWakeupPipe: called\n"));852 880 while (read(pCtx->wakeupPipeRead, acBuf, sizeof(acBuf)) > 0) {} 853 881 } … … 874 902 if (NULL == pDisplay) 875 903 { 876 LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running.\n"));904 LogRel(("Shared Clipboard: Failed to connect to the X11 clipboard - the window system may not be running\n")); 877 905 rc = VERR_NOT_SUPPORTED; 878 906 } … … 882 910 rc = clipLoadXFixes(pDisplay, pCtx); 883 911 if (RT_FAILURE(rc)) 884 LogRel(("Shared clipboard: Failed to load the XFIXES extension.\n"));912 LogRel(("Shared Clipboard: Failed to load the XFIXES extension\n")); 885 913 } 886 914 #endif … … 893 921 if (NULL == pCtx->widget) 894 922 { 895 LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager.\n"));923 LogRel(("Shared Clipboard: Failed to construct the X11 window for the shared clipboard manager\n")); 896 924 rc = VERR_NO_MEMORY; 897 925 } … … 924 952 rc = RTErrConvertFromErrno(errno); 925 953 if (RT_FAILURE(rc)) 926 LogRel(("Shared clipboard: Failed to setup the termination mechanism.\n"));954 LogRel(("Shared Clipboard: Failed to setup the termination mechanism\n")); 927 955 } 928 956 else … … 931 959 clipUninit(pCtx); 932 960 if (RT_FAILURE(rc)) 933 LogRel(("Shared clipboard: Initialisation failed: %Rrc\n", rc));961 LogRel(("Shared Clipboard: Initialisation failed: %Rrc\n", rc)); 934 962 return rc; 935 963 } 936 964 937 965 /** 938 * Construct the X11 backend of the shared clipboard. 966 * Constructs the X11 backend of the shared clipboard. 967 * 939 968 * @note X11 backend code 940 969 */ … … 950 979 * This is important for VBoxHeadless. 951 980 */ 952 LogRel Func(("X11 DISPLAY variable not set -- disabling shared clipboard\n"));981 LogRel(("Shared Clipboard: X11 DISPLAY variable not set -- disabling shared clipboard\n")); 953 982 pCtx->fHaveX11 = false; 954 983 return pCtx; … … 957 986 pCtx->fHaveX11 = true; 958 987 959 LogRel(("Shared clipboard: Initializing X11 clipboard backend\n"));988 LogRel(("Shared Clipboard: Initializing X11 clipboard backend\n")); 960 989 if (pCtx) 961 990 pCtx->pFrontend = pFrontend; … … 964 993 965 994 /** 966 * Destruct the shared clipboard X11 backend. 995 * Destructs the shared clipboard X11 backend. 996 * 967 997 * @note X11 backend code 968 998 */ … … 984 1014 { 985 1015 int rc = VINF_SUCCESS; 986 LogFlowFunc(("\n")); 1016 987 1017 /* 988 1018 * Immediately return if we are not connected to the X server. … … 1004 1034 if (RT_FAILURE(rc)) 1005 1035 { 1006 LogRel(("Shared clipboard: Failed to start the shared clipboard thread.\n"));1036 LogRel(("Shared Clipboard: Failed to start the shared clipboard thread\n")); 1007 1037 clipUninit(pCtx); 1008 1038 } … … 1030 1060 return VINF_SUCCESS; 1031 1061 1032 LogRelFunc(("stopping the shared clipboard X11 backend\n")); 1062 LogRel(("Shared Clipboard: Stopping X11 backend\n")); 1063 1033 1064 /* Write to the "stop" pipe */ 1034 1065 clipQueueToEventThread(pCtx, clipStopEventThreadWorker, (XtPointer) pCtx); … … 1046 1077 #endif 1047 1078 if (RT_SUCCESS(rc)) 1079 { 1048 1080 AssertRC(rcThread); 1081 } 1049 1082 else 1050 LogRelFunc(("rc=%Rrc\n", rc)); 1083 LogRel(("Shared Clipboard: Stopping X11 backend failed with %Rrc\n", rc)); 1084 1051 1085 clipUninit(pCtx); 1052 LogFlowFunc(("returning %Rrc.\n", rc)); 1086 1053 1087 RT_NOREF_PV(rcThread); 1054 1088 return rc; … … 1056 1090 1057 1091 /** 1058 * Satisf ya request from X11 for clipboard targets supported by VBox.1059 * 1060 * @returns iprt status code1061 * @param atomTypeReturn The type of the data we are returning1062 * @param pValReturn A pointer to the data we are returning.This1063 * should be set to memory allocated by XtMalloc,1064 * which will be freed later by the Xt toolkit.1065 * @param pcLenReturn The length of the data we are returning1066 * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are1067 * returning1092 * Satisfies a request from X11 for clipboard targets supported by VBox. 1093 * 1094 * @returns VBox status code. 1095 * @param atomTypeReturn The type of the data we are returning. 1096 * @param pValReturn A pointer to the data we are returning. This 1097 * should be set to memory allocated by XtMalloc, 1098 * which will be freed later by the Xt toolkit. 1099 * @param pcLenReturn The length of the data we are returning. 1100 * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are 1101 * returning. 1068 1102 * @note X11 backend code, called by the XtOwnSelection callback. 1069 1103 */ … … 1073 1107 int *piFormatReturn) 1074 1108 { 1075 Atom *atomTargets = (Atom *)XtMalloc( (MAX_CLIP_X11_FORMATS + 3) 1076 * sizeof(Atom)); 1109 LogFlowFuncEnter(); 1110 1111 const unsigned cFixedTargets = 3; 1112 1113 Atom *atomTargets = (Atom *)XtMalloc((MAX_CLIP_X11_FORMATS + cFixedTargets) * sizeof(Atom)); 1077 1114 unsigned cTargets = 0; 1078 LogFlowFunc (("called\n"));1079 1115 CLIPX11FORMAT format = NIL_CLIPX11FORMAT; 1080 1116 do … … 1087 1123 } 1088 1124 } while (format != NIL_CLIPX11FORMAT); 1089 /* We always offer these */ 1090 atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS"); 1125 1126 /* We always offer these fixed targets. */ 1127 atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS"); 1091 1128 atomTargets[cTargets + 1] = clipGetAtom(pCtx, "MULTIPLE"); 1092 1129 atomTargets[cTargets + 2] = clipGetAtom(pCtx, "TIMESTAMP"); 1130 1093 1131 *atomTypeReturn = XA_ATOM; 1094 1132 *pValReturn = (XtPointer)atomTargets; 1095 *pcLenReturn = cTargets + 3;1133 *pcLenReturn = cTargets + cFixedTargets; 1096 1134 *piFormatReturn = 32; 1135 1097 1136 return VINF_SUCCESS; 1098 1137 } 1099 1138 1100 /** This is a wrapper around ClipRequestDataForX11Callback that will cache the 1139 /** 1140 * This is a wrapper around ClipRequestDataForX11Callback that will cache the 1101 1141 * data returned. 1102 1142 */ … … 1124 1164 rc = ClipRequestDataForX11Callback(pCtx->pFrontend, u32Format, 1125 1165 ppv, pcb); 1126 LogFlowFunc(("returning %Rrc\n", rc));1127 1166 if (RT_SUCCESS(rc)) 1128 1167 LogFlowFunc(("*ppv=%.*ls, *pcb=%u\n", *pcb, *ppv, *pcb)); 1168 1169 LogFlowFuncLeaveRC(rc); 1129 1170 return rc; 1130 1171 } 1131 1172 1132 1173 /** 1133 * Calculate a buffer size large enough to hold the source Windows format 1134 * text converted into Unix Utf8, including the null terminator 1135 * @returns iprt status code 1136 * @param pwsz the source text in UCS-2 with Windows EOLs 1137 * @param cwc the size in USC-2 elements of the source text, with or 1138 * without the terminator 1139 * @param pcbActual where to store the buffer size needed 1174 * Calculates a buffer size large enough to hold the source Windows format 1175 * text converted into Unix Utf8, including the null terminator. 1176 * 1177 * @returns VBox status code. 1178 * @param pwsz The source text in UCS-2 with Windows EOLs. 1179 * @param cwc The size in USC-2 elements of the source text, with or 1180 * without the terminator. 1181 * @param pcbActual Where to store the buffer size needed. 1140 1182 */ 1141 1183 static int clipWinTxtBufSizeForUtf8(PRTUTF16 pwsz, size_t cwc, … … 1150 1192 1151 1193 /** 1152 * Convert text from Windows format (UCS-2 with CRLF line endings) to standard 1153 * Utf-8. 1154 * 1155 * @returns iprt status code 1156 * 1157 * @param pwszSrc the text to be converted 1158 * @param cbSrc the length of @a pwszSrc in bytes 1159 * @param pszBuf where to write the converted string 1160 * @param cbBuf the size of the buffer pointed to by @a pszBuf 1161 * @param pcbActual where to store the size of the converted string. 1162 * optional. 1194 * Converts text from Windows format (UCS-2 with CRLF line endings) to standard Utf-8. 1195 * 1196 * @returns VBox status code. 1197 * @param pwszSrc The text to be converted. 1198 * @param cbSrc The length of @a pwszSrc in bytes. 1199 * @param pszBuf Where to write the converted string. 1200 * @param cbBuf The size of the buffer pointed to by @a pszBuf. 1201 * @param pcbActual Where to store the size of the converted string. 1202 * optional. 1163 1203 */ 1164 1204 static int clipWinTxtToUtf8(PRTUTF16 pwszSrc, size_t cbSrc, char *pszBuf, … … 1190 1230 if (pcbActual) 1191 1231 *pcbActual = cbDest + 1; 1192 LogFlowFunc(("returning %Rrc\n", rc)); 1232 1193 1233 if (RT_SUCCESS(rc)) 1194 LogFlowFunc (("converted string is %.*s. Returning.\n", cbDest, 1195 pszBuf)); 1234 LogFlowFunc (("converted string is %.*s. Returning.\n", cbDest, pszBuf)); 1235 1236 LogFlowFuncLeaveRC(rc); 1196 1237 return rc; 1197 1238 } 1198 1239 1199 1240 /** 1200 * Satisf ya request from X11 to convert the clipboard text to Utf-8. We1241 * Satisfies a request from X11 to convert the clipboard text to Utf-8. We 1201 1242 * return null-terminated text, but can cope with non-null-terminated input. 1202 1243 * 1203 * @returns iprt status code1204 * @param pDisplay an X11 display structure, needed for conversions1205 * performed by Xlib1206 * @param pv the text to be converted (UCS-2 with Windows EOLs)1207 * @param cb the length of the text in @cb in bytes1208 * @param atomTypeReturn where to store the atom for the type of the data1209 * we are returning1210 * @param pValReturn where to store the pointer to the data we are1211 * returning. This should be to memory allocated by1212 * XtMalloc, which will be freed by the Xt toolkit1213 * later.1214 * @param pcLenReturn where to store the length of the data we are1215 * returning1216 * @param piFormatReturn where to store the bit width (8, 16, 32) of the1217 * data we are returning1244 * @returns VBox status code. 1245 * @param pDisplay An X11 display structure, needed for conversions 1246 * performed by Xlib. 1247 * @param pv The text to be converted (UCS-2 with Windows EOLs). 1248 * @param cb The length of the text in @cb in bytes. 1249 * @param atomTypeReturn Where to store the atom for the type of the data 1250 * we are returning. 1251 * @param pValReturn Where to store the pointer to the data we are 1252 * returning. This should be to memory allocated by 1253 * XtMalloc, which will be freed by the Xt toolkit 1254 * later. 1255 * @param pcLenReturn Where to store the length of the data we are 1256 * returning. 1257 * @param piFormatReturn Where to store the bit width (8, 16, 32) of the 1258 * data we are returning. 1218 1259 */ 1219 1260 static int clipWinTxtToUtf8ForX11CB(Display *pDisplay, PRTUTF16 pwszSrc, … … 1248 1289 1249 1290 /** 1250 * Satisf ya request from X11 to convert the clipboard HTML fragment to Utf-8. We1291 * Satisfies a request from X11 to convert the clipboard HTML fragment to Utf-8. We 1251 1292 * return null-terminated text, but can cope with non-null-terminated input. 1252 1293 * 1253 * @returns iprt status code 1254 * @param pDisplay an X11 display structure, needed for conversions 1255 * performed by Xlib 1256 * @param pv the text to be converted (UTF8 with Windows EOLs) 1257 * @param cb the length of the text in @cb in bytes 1258 * @param atomTypeReturn where to store the atom for the type of the data 1259 * we are returning 1260 * @param pValReturn where to store the pointer to the data we are 1261 * returning. This should be to memory allocated by 1262 * XtMalloc, which will be freed by the Xt toolkit 1263 * later. 1264 * @param pcLenReturn where to store the length of the data we are 1265 * returning 1266 * @param piFormatReturn where to store the bit width (8, 16, 32) of the 1267 * data we are returning 1294 * @returns VBox status code. 1295 * @param pDisplay An X11 display structure, needed for conversions 1296 * performed by Xlib. 1297 * @param pv The text to be converted (UTF8 with Windows EOLs). 1298 * @param cb The length of the text in @cb in bytes. 1299 * @param atomTypeReturn Where to store the atom for the type of the data 1300 * we are returning. 1301 * @param pValReturn Where to store the pointer to the data we are 1302 * returning. This should be to memory allocated by 1303 * XtMalloc, which will be freed by the Xt toolkit later. 1304 * @param pcLenReturn Where to store the length of the data we are returning. 1305 * @param piFormatReturn Where to store the bit width (8, 16, 32) of the 1306 * data we are returning. 1268 1307 */ 1269 1308 static int clipWinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc, … … 1296 1335 /** 1297 1336 * Does this atom correspond to one of the two selection types we support? 1298 * @param widget a valid Xt widget 1299 * @param selType the atom in question 1337 * 1338 * @param widget A valid Xt widget. 1339 * @param selType The atom in question. 1300 1340 */ 1301 1341 static bool clipIsSupportedSelectionType(CLIPBACKEND *pCtx, Atom selType) … … 1306 1346 1307 1347 /** 1308 * Remove a trailing nul character from a string by adjusting the string1348 * Removes a trailing nul character from a string by adjusting the string 1309 1349 * length. Some X11 applications don't like zero-terminated text... 1310 * @param pText the text in question 1311 * @param pcText the length of the text, adjusted on return 1312 * @param format the format of the text 1350 * 1351 * @param pText The text in question. 1352 * @param pcText The length of the text, adjusted on return. 1353 * @param format The format of the text. 1313 1354 */ 1314 1355 static void clipTrimTrailingNul(XtPointer pText, unsigned long *pcText, … … 1318 1359 AssertPtrReturnVoid(pcText); 1319 1360 AssertReturnVoid((format == UTF8) || (format == TEXT) || (format == HTML)); 1361 1320 1362 if (((char *)pText)[*pcText - 1] == '\0') 1321 1363 --(*pcText); … … 1329 1371 { 1330 1372 int rc = VINF_SUCCESS; 1373 1331 1374 CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx, *atomTarget); 1332 1375 CLIPFORMAT format = clipRealFormatForX11Format(x11Format); 1376 1333 1377 if ( ((format == UTF8) || (format == TEXT)) 1334 1378 && (pCtx->vboxFormats & VBOX_SHCL_FMT_UNICODETEXT)) … … 1409 1453 else 1410 1454 rc = VERR_NOT_SUPPORTED; 1455 1456 LogFlowFuncLeaveRC(rc); 1411 1457 return rc; 1412 1458 } 1413 1459 1414 1460 /** 1415 * Return VBox's clipboard data for an X11 client. 1461 * Returns VBox's clipboard data for an X11 client. 1462 * 1416 1463 * @note X11 backend code, callback for XtOwnSelection 1417 1464 */ … … 1423 1470 int *piFormatReturn) 1424 1471 { 1472 LogFlowFuncEnter(); 1473 1425 1474 CLIPBACKEND *pCtx = clipLookupContext(widget); 1426 1475 int rc = VINF_SUCCESS; 1427 1476 1428 LogFlowFunc(("\n"));1429 1477 if (!pCtx) 1430 1478 return false; 1479 1431 1480 if (!clipIsSupportedSelectionType(pCtx, *atomSelection)) 1432 1481 return false; 1482 1433 1483 if (*atomTarget == clipGetAtom(pCtx, "TARGETS")) 1434 1484 rc = clipCreateX11Targets(pCtx, atomTypeReturn, pValReturn, … … 1437 1487 rc = clipConvertVBoxCBForX11(pCtx, atomTarget, atomTypeReturn, 1438 1488 pValReturn, pcLenReturn, piFormatReturn); 1489 1439 1490 LogFlowFunc(("returning, internal status code %Rrc\n", rc)); 1440 1491 return RT_SUCCESS(rc); … … 1461 1512 1462 1513 /** 1463 * Take possession of the X11 clipboard (and middle-button selection).1514 * Takes possession of the X11 clipboard (and middle-button selection). 1464 1515 */ 1465 1516 static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats) … … 1488 1539 * Worker function for ClipAnnounceFormatToX11 which runs on the 1489 1540 * event thread. 1490 * @param pUserData Pointer to a CLIPNEWVBOXFORMATS structure containing 1491 * information about the VBox formats available and the 1492 * clipboard context data. Must be freed by the worker. 1541 * 1542 * @param pUserData Pointer to a CLIPNEWVBOXFORMATS structure containing 1543 * information about the VBox formats available and the 1544 * clipboard context data. Must be freed by the worker. 1493 1545 */ 1494 1546 static void clipNewVBoxFormatsWorker(void *pUserData, … … 1497 1549 CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData; 1498 1550 CLIPBACKEND *pCtx = pFormats->pCtx; 1499 uint32_t u32Formats = pFormats->formats; 1551 1552 uint32_t fFormats = pFormats->formats; 1553 1500 1554 RTMemFree(pFormats); 1501 LogFlowFunc (("u32Formats=0x%x\n", u32Formats)); 1555 1556 LogFlowFunc (("fFormats=0x%x\n", fFormats)); 1557 1502 1558 clipInvalidateVBoxCBCache(pCtx); 1503 clipGrabX11CB(pCtx, u32Formats);1559 clipGrabX11CB(pCtx, fFormats); 1504 1560 clipResetX11Formats(pCtx); 1505 LogFlowFunc(("returning\n")); 1561 1562 LogFlowFuncLeave(); 1506 1563 } 1507 1564 … … 1509 1566 * VBox is taking possession of the shared clipboard. 1510 1567 * 1511 * @param u32Formats Clipboard formats that VBox is offering1568 * @param u32Formats Clipboard formats that VBox is offering. 1512 1569 * @note X11 backend code 1513 1570 */ … … 1540 1597 1541 1598 /** 1542 * Massage generic Utf16 with CR end-of-lines into the format Windows expects1599 * Massages generic Utf16 with CR end-of-lines into the format Windows expects 1543 1600 * and return the result in a RTMemAlloc allocated buffer. 1544 1601 * 1545 * @returns IPRT status code1546 * @param pwcSrc The source Utf161547 * @param cwcSrc The number of 16bit elements in @a pwcSrc, not counting1548 * the terminating zero1549 * @param ppwszDest Where to store the buffer address1550 * @param pcbDest On success, where to store the number of bytes written.1551 * Undefined otherwise. Optional1602 * @returns VBox status code. 1603 * @param pwcSrc The source as Utf16. 1604 * @param cwcSrc The number of 16bit elements in @a pwcSrc, not counting 1605 * the terminating zero. 1606 * @param ppwszDest Where to store the buffer address. 1607 * @param pcbDest On success, where to store the number of bytes written. 1608 * Undefined otherwise. Optional. 1552 1609 */ 1553 1610 static int clipUtf16ToWinTxt(RTUTF16 *pwcSrc, size_t cwcSrc, … … 1592 1649 1593 1650 /** 1594 * Convert Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it1651 * Converts Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it 1595 1652 * and return the result in a RTMemAlloc allocated buffer. 1596 1653 * 1597 * @returns IPRT status code1598 * @param pcSrc The source Utf-81599 * @param cbSrc The size of the source in bytes, not counting the1600 * terminating zero1601 * @param ppwszDest Where to store the buffer address1602 * @param pcbDest On success, where to store the number of bytes written.1603 * Undefined otherwise. Optional1654 * @returns VBox status code. 1655 * @param pcSrc The source Utf-8. 1656 * @param cbSrc The size of the source in bytes, not counting the 1657 * terminating zero. 1658 * @param ppwszDest Where to store the buffer address. 1659 * @param pcbDest On success, where to store the number of bytes written. 1660 * Undefined otherwise. Optional. 1604 1661 */ 1605 1662 static int clipUtf8ToWinTxt(const char *pcSrc, unsigned cbSrc, … … 1628 1685 1629 1686 /** 1630 * Convert Latin-1 text with CR end-of-lines into Utf-16 as Windows expects1687 * Converts Latin-1 text with CR end-of-lines into Utf-16 as Windows expects 1631 1688 * it and return the result in a RTMemAlloc allocated buffer. 1632 1689 * 1633 * @returns IPRT status code1634 * @param pcSrc The source text1635 * @param cbSrc The size of the source in bytes, not counting the1636 * terminating zero1637 * @param ppwszDest Where to store the buffer address1638 * @param pcbDest On success, where to store the number of bytes written.1639 * Undefined otherwise. Optional1690 * @returns VBox status code. 1691 * @param pcSrc The source text. 1692 * @param cbSrc The size of the source in bytes, not counting the 1693 * terminating zero. 1694 * @param ppwszDest Where to store the buffer address. 1695 * @param pcbDest On success, where to store the number of bytes written. 1696 * Undefined otherwise. Optional. 1640 1697 */ 1641 1698 static int clipLatin1ToWinTxt(char *pcSrc, unsigned cbSrc, … … 1702 1759 1703 1760 /** 1704 * Convert Utf16 text into UTF8 as Windows expects1761 * Converts Utf16 text into UTF8 as Windows expects 1705 1762 * it and return the result in a RTMemAlloc allocated buffer. 1706 1763 * 1707 * @returns IPRT status code1708 * @param pcSrc The source text1709 * @param cbSrc The size of the source in bytes, not counting the1710 * terminating zero1711 * @param ppwszDest Where to store the buffer address1712 * @param pcbDest On success, where to store the number of bytes written.1713 * Undefined otherwise. Optional1764 * @returns VBox status code. 1765 * @param pcSrc The source text. 1766 * @param cbSrc The size of the source in bytes, not counting the 1767 * terminating zero. 1768 * @param ppwszDest Where to store the buffer address. 1769 * @param pcbDest On success, where to store the number of bytes written. 1770 * Undefined otherwise. Optional. 1714 1771 */ 1715 1772 static int clipUTF16ToWinHTML(RTUTF16 *pwcBuf, size_t cb, char **ppszOut, uint32_t *pcOut) … … 1797 1854 1798 1855 /** 1799 * Convert the data obtained from the X11 clipboard to the required format,1856 * Converts the data obtained from the X11 clipboard to the required format, 1800 1857 * place it in the buffer supplied and signal that data has arrived. 1801 * Convert the text obtained UTF-16LE with Windows EOLs. 1802 * Convert full BMP data to DIB format. 1858 * 1859 * Converts the text obtained UTF-16LE with Windows EOLs. 1860 * Converts full BMP data to DIB format. 1861 * 1803 1862 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1804 1863 * the X11 clipboard contains a format we understand. … … 1944 2003 #ifndef TESTCASE 1945 2004 /** 1946 * Convert the data obtained from the X11 clipboard to the required format,2005 * Converts the data obtained from the X11 clipboard to the required format, 1947 2006 * place it in the buffer supplied and signal that data has arrived. 1948 * Convert the text obtained UTF-16LE with Windows EOLs. 1949 * Convert full BMP data to DIB format. 2007 * 2008 * Converts the text obtained UTF-16LE with Windows EOLs. 2009 * Converts full BMP data to DIB format. 2010 * 1950 2011 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1951 2012 * the X11 clipboard contains a format we understand. … … 2065 2126 * Called when VBox wants to read the X11 clipboard. 2066 2127 * 2067 * @returns iprt status code2068 * @param pCtx Context data for the clipboard backend2069 * @param u32Format The format that the VBox would like to receive the data2070 * in2071 * @param pv Where to write the data to2072 * @param cb The size of the buffer to write the data to2073 * @param pcbActual Where to write the actual size of the written data2074 * @note We allocate a request structure which must be freed by the worker 2128 * @returns VBox status code. 2129 * @param pCtx Context data for the clipboard backend. 2130 * @param u32Format The format that the VBox would like to receive the data in. 2131 * @param pv Where to write the data to. 2132 * @param cb The size of the buffer to write the data to. 2133 * @param pcbActual Where to write the actual size of the written data. 2134 * 2135 * @note We allocate a request structure which must be freed by the worker. 2075 2136 */ 2076 2137 int ClipRequestDataFromX11(CLIPBACKEND *pCtx, uint32_t u32Format, CLIPREADCBREQ *pReq)
Note:
See TracChangeset
for help on using the changeset viewer.