- Timestamp:
- Apr 8, 2020 11:04:54 PM (5 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedClipboard
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp
r83628 r83632 50 50 /** Random 64-bit number embedded into szGuestOwnershipFlavor. */ 51 51 uint64_t idGuestOwnership; 52 /** Ownership flavor CFStringRef returned by takePasteboardOwnership(). 53 * This is the same a szGuestOwnershipFlavor only in core foundation terms. */ 54 void *hStrOwnershipFlavor; 52 55 /** The guest ownership flavor (type) string. */ 53 56 char szGuestOwnershipFlavor[64]; … … 67 70 * @returns IPRT status code (ignored). 68 71 * @param pCtx The context. 72 * 73 * @note Call must own lock. 69 74 */ 70 75 static int vboxClipboardChanged(SHCLCONTEXT *pCtx) … … 73 78 return VINF_SUCCESS; 74 79 80 /* Retrieve the formats currently in the clipboard and supported by vbox */ 75 81 uint32_t fFormats = 0; 76 bool fChanged = false;77 /* Retrieve the formats currently in the clipboard and supported by vbox */78 int rc = queryNewPasteboardFormats(pCtx->hPasteboard,&fFormats, &fChanged);82 bool fChanged = false; 83 int rc = queryNewPasteboardFormats(pCtx->hPasteboard, pCtx->idGuestOwnership, pCtx->hStrOwnershipFlavor, 84 &fFormats, &fChanged); 79 85 if ( RT_SUCCESS(rc) 80 86 && fChanged) … … 197 203 LogFlowFunc(("fFormats=%02X\n", fFormats)); 198 204 205 /** @todo r=bird: BUGBUG: The following is probably a mistake. */ 199 206 if (fFormats == VBOX_SHCL_FMT_NONE) 200 207 { … … 226 233 RTStrPrintf(szValue, sizeof(szValue), "%#x", fFormats); 227 234 228 takePasteboardOwnership(pCtx->hPasteboard, pCtx->idGuestOwnership, pCtx->szGuestOwnershipFlavor, szValue); 235 takePasteboardOwnership(pCtx->hPasteboard, pCtx->idGuestOwnership, pCtx->szGuestOwnershipFlavor, szValue, 236 &pCtx->hStrOwnershipFlavor); 229 237 230 238 ShClSvcUnlock(); -
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
r83631 r83632 75 75 * that is supported by vbox and return it. 76 76 * 77 * @param pPasteboard Reference to the global pasteboard. 78 * @param pfFormats Pointer for the bit combination of the 79 * supported types. 80 * @param pfChanged True if something has changed after the 81 * last call. 82 * 83 * @returns IPRT status code. (Always VINF_SUCCESS atm.) 84 */ 85 int queryNewPasteboardFormats(PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged) 77 * @param hPasteboard Reference to the global pasteboard. 78 * @param idOwnership Our ownership ID. 79 * @param hStrOwnershipFlavor The ownership flavor string reference returned 80 * by takePasteboardOwnership(). 81 * @param pfFormats Pointer for the bit combination of the 82 * supported types. 83 * @param pfChanged True if something has changed after the 84 * last call. 85 * 86 * @returns VINF_SUCCESS. 87 */ 88 int queryNewPasteboardFormats(PasteboardRef hPasteboard, uint64_t idOwnership, void *hStrOwnershipFlavor, 89 uint32_t *pfFormats, bool *pfChanged) 86 90 { 87 OSStatus err = noErr; 91 OSStatus orc; 92 88 93 *pfFormats = 0; 89 94 *pfChanged = true; … … 91 96 PasteboardSyncFlags syncFlags; 92 97 /* Make sure all is in sync */ 93 syncFlags = PasteboardSynchronize( pPasteboard);98 syncFlags = PasteboardSynchronize(hPasteboard); 94 99 /* If nothing changed return */ 95 100 if (!(syncFlags & kPasteboardModified)) … … 101 106 102 107 /* Are some items in the pasteboard? */ 103 ItemCount itemCount; 104 err = PasteboardGetItemCount(pPasteboard, &itemCount); 105 if (itemCount < 1) 106 { 107 Log(("queryNewPasteboardFormats: changed: No items on the pasteboard\n")); 108 return VINF_SUCCESS; 109 } 110 111 /* The id of the first element in the pasteboard */ 112 int rc = VINF_SUCCESS; 113 PasteboardItemID itemID; 114 if (!(err = PasteboardGetItemIdentifier(pPasteboard, 1, &itemID))) 115 { 116 /* Retrieve all flavors in the pasteboard, maybe there 117 * is something we can use. */ 118 CFArrayRef flavorTypeArray; 119 if (!(err = PasteboardCopyItemFlavors(pPasteboard, itemID, &flavorTypeArray))) 120 { 121 CFIndex flavorCount; 122 flavorCount = CFArrayGetCount(flavorTypeArray); 123 for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++) 124 { 125 CFStringRef flavorType; 126 flavorType = static_cast <CFStringRef>(CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex)); 127 /* Currently only unicode supported */ 128 if ( UTTypeConformsTo(flavorType, kUTTypeUTF8PlainText) 129 || UTTypeConformsTo(flavorType, kUTTypeUTF16PlainText)) 130 { 131 Log(("queryNewPasteboardFormats: Unicode flavor detected.\n")); 132 *pfFormats |= VBOX_SHCL_FMT_UNICODETEXT; 133 } 134 else if (UTTypeConformsTo(flavorType, kUTTypeBMP)) 135 { 136 Log(("queryNewPasteboardFormats: BMP flavor detected.\n")); 137 *pfFormats |= VBOX_SHCL_FMT_BITMAP; 138 } 139 } 140 CFRelease(flavorTypeArray); 141 } 142 } 143 144 Log(("queryNewPasteboardFormats: changed: *pfFormats=%#x\n", *pfFormats)); 145 return rc; 108 ItemCount cItems = 0; 109 orc = PasteboardGetItemCount(hPasteboard, &cItems); 110 if (orc == 0) 111 { 112 if (cItems < 1) 113 Log(("queryNewPasteboardFormats: changed: No items on the pasteboard\n")); 114 else 115 { 116 /* The id of the first element in the pasteboard */ 117 PasteboardItemID idItem = 0; 118 orc = PasteboardGetItemIdentifier(hPasteboard, 1, &idItem); 119 if (orc == 0) 120 { 121 /* 122 * Retrieve all flavors on the pasteboard, maybe there 123 * is something we can use. Or maybe we're the owner. 124 */ 125 CFArrayRef hFlavors = 0; 126 orc = PasteboardCopyItemFlavors(hPasteboard, idItem, &hFlavors); 127 if (orc == 0) 128 { 129 CFIndex cFlavors = CFArrayGetCount(hFlavors); 130 for (CFIndex idxFlavor = 0; idxFlavor < cFlavors; idxFlavor++) 131 { 132 CFStringRef hStrFlavor = (CFStringRef)CFArrayGetValueAtIndex(hFlavors, idxFlavor); 133 if ( idItem == (PasteboardItemID)idOwnership 134 && hStrOwnershipFlavor 135 && CFStringCompare(hStrFlavor, (CFStringRef)hStrOwnershipFlavor, 0) == kCFCompareEqualTo) 136 { 137 /* We made the changes ourselves. */ 138 Log2(("queryNewPasteboardFormats: no-changed: our clipboard!\n")); 139 *pfChanged = false; 140 *pfFormats = 0; 141 break; 142 } 143 144 if (UTTypeConformsTo(hStrFlavor, kUTTypeBMP)) 145 { 146 Log(("queryNewPasteboardFormats: BMP flavor detected.\n")); 147 *pfFormats |= VBOX_SHCL_FMT_BITMAP; 148 } 149 else if ( UTTypeConformsTo(hStrFlavor, kUTTypeUTF8PlainText) 150 || UTTypeConformsTo(hStrFlavor, kUTTypeUTF16PlainText)) 151 { 152 Log(("queryNewPasteboardFormats: Unicode flavor detected.\n")); 153 *pfFormats |= VBOX_SHCL_FMT_UNICODETEXT; 154 } 155 #ifdef LOG_ENABLED 156 else if (LogIs2Enabled()) 157 { 158 if (CFStringGetCharactersPtr(hStrFlavor)) 159 Log2(("queryNewPasteboardFormats: Unknown flavor: %ls.\n", CFStringGetCharactersPtr(hStrFlavor))); 160 else if (CFStringGetCStringPtr(hStrFlavor, kCFStringEncodingUTF8)) 161 Log2(("queryNewPasteboardFormats: Unknown flavor: %s.\n", 162 CFStringGetCStringPtr(hStrFlavor, kCFStringEncodingUTF8))); 163 else 164 Log2(("queryNewPasteboardFormats: Unknown flavor: ???\n")); 165 } 166 #endif 167 } 168 169 CFRelease(hFlavors); 170 } 171 else 172 Log(("queryNewPasteboardFormats: PasteboardCopyItemFlavors failed - %d (%#x)\n", orc, orc)); 173 } 174 else 175 Log(("queryNewPasteboardFormats: PasteboardGetItemIdentifier failed - %d (%#x)\n", orc, orc)); 176 177 if (*pfChanged) 178 Log(("queryNewPasteboardFormats: changed: *pfFormats=%#x\n", *pfFormats)); 179 } 180 } 181 else 182 Log(("queryNewPasteboardFormats: PasteboardGetItemCount failed - %d (%#x)\n", orc, orc)); 183 return VINF_SUCCESS; 146 184 } 147 185 … … 289 327 * 290 328 * @returns VBox status code. 291 * @param hPasteboard The pastboard handle (reference). 292 * @param idOwnership The ownership ID to use now. 293 * @param pszOwnershipFlavor The ownership indicator flavor 294 * @param pszOwnershipValue The ownership value (stringified format mask). 329 * @param hPasteboard The pastboard handle (reference). 330 * @param idOwnership The ownership ID to use now. 331 * @param pszOwnershipFlavor The ownership indicator flavor 332 * @param pszOwnershipValue The ownership value (stringified format mask). 333 * @param phStrOwnershipFlavor Pointer to a CFStringRef variable holding 334 * the current ownership flavor string. This 335 * will always be released, and set again on 336 * success. 295 337 * 296 338 * @todo Add fFormats so we can make promises about available formats at once … … 298 340 * flavor priority. 299 341 */ 300 int takePasteboardOwnership(PasteboardRef hPasteboard, uint64_t idOwnership, 301 const char *pszOwnership Flavor, const char *pszOwnershipValue)342 int takePasteboardOwnership(PasteboardRef hPasteboard, uint64_t idOwnership, const char *pszOwnershipFlavor, 343 const char *pszOwnershipValue, void **phStrOwnershipFlavor) 302 344 { 345 /* 346 * Release the old string. 347 */ 348 if (*phStrOwnershipFlavor) 349 { 350 CFStringRef hOldFlavor = (CFStringRef)*phStrOwnershipFlavor; 351 CFRelease(hOldFlavor); 352 *phStrOwnershipFlavor = NULL; 353 } 354 303 355 /* 304 356 * Clear the pasteboard and take ownership over it. … … 322 374 hFlavor, hData, kPasteboardFlavorNoFlags); 323 375 if (orc == 0) 376 { 377 *phStrOwnershipFlavor = (void *)hFlavor; 324 378 Log(("takePasteboardOwnership: idOwnership=%RX64 flavor=%s value=%s\n", 325 379 idOwnership, pszOwnershipFlavor, pszOwnershipValue)); 380 } 326 381 else 382 { 327 383 Log(("takePasteboardOwnership: PasteboardPutItemFlavor -> %d (%#x)!\n", orc, orc)); 328 CFRelease(hFlavor); 384 CFRelease(hFlavor); 385 } 329 386 } 330 387 else … … 414 471 rc = VERR_GENERAL_FAILURE; 415 472 } 416 else417 {418 Log(("writeToPasteboard: CFDataCreate/UTF16 failed!\n"));419 rc = VERR_NO_MEMORY;420 }421 473 CFRelease(hData); 474 } 475 else 476 { 477 Log(("writeToPasteboard: CFDataCreate/UTF16 failed!\n")); 478 rc = VERR_NO_MEMORY; 422 479 } 423 480 } -
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.h
r83630 r83632 27 27 void destroyPasteboard(PasteboardRef *pPasteboardRef); 28 28 29 int queryNewPasteboardFormats(PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged); 29 int queryNewPasteboardFormats(PasteboardRef hPasteboard, uint64_t idOwnership, void *hStrOwnershipFlavor, 30 uint32_t *pfFormats, bool *pfChanged); 30 31 int readFromPasteboard(PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual); 31 int takePasteboardOwnership(PasteboardRef pPasteboard, uint64_t idOwnership, 32 const char *pszOwnership Flavor, const char *pszOwnershipValue);32 int takePasteboardOwnership(PasteboardRef pPasteboard, uint64_t idOwnership, const char *pszOwnershipFlavor, 33 const char *pszOwnershipValue, void **phStrOwnershipFlavor); 33 34 int writeToPasteboard(PasteboardRef hPasteboard, uint64_t idOwnership, void const *pv, uint32_t cb, uint32_t fFormat); 34 35
Note:
See TracChangeset
for help on using the changeset viewer.