Changeset 83628 in vbox for trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
- Timestamp:
- Apr 8, 2020 6:49:21 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 137067
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
r83621 r83628 284 284 285 285 /** 286 * Takes the ownership of the pasteboard. 287 * 288 * This is called when the other end reports available formats. 289 * 290 * @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). 295 * 296 * @todo Add fFormats so we can make promises about available formats at once 297 * without needing to request any data first. That might help on 298 * flavor priority. 299 */ 300 int takePasteboardOwnership(PasteboardRef hPasteboard, uint64_t idOwnership, 301 const char *pszOwnershipFlavor, const char *pszOwnershipValue) 302 { 303 /* 304 * Clear the pasteboard and take ownership over it. 305 */ 306 OSStatus orc = PasteboardClear(hPasteboard); 307 if (orc == 0) 308 { 309 /* For good measure. */ 310 PasteboardSynchronize(hPasteboard); 311 312 /* 313 * Put the ownership flavor and value onto the clipboard. 314 */ 315 CFDataRef hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pszOwnershipValue, strlen(pszOwnershipValue)); 316 if (hData) 317 { 318 CFStringRef hFlavor = CFStringCreateWithCString(kCFAllocatorDefault, pszOwnershipFlavor, kCFStringEncodingUTF8); 319 if (hFlavor) 320 { 321 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, 322 hFlavor, hData, kPasteboardFlavorNoFlags); 323 if (orc == 0) 324 Log(("takePasteboardOwnership: idOwnership=%RX64 flavor=%s value=%s\n", 325 idOwnership, pszOwnershipFlavor, pszOwnershipValue)); 326 else 327 Log(("takePasteboardOwnership: PasteboardPutItemFlavor -> %d (%#x)!\n", orc, orc)); 328 CFRelease(hFlavor); 329 } 330 else 331 Log(("takePasteboardOwnership: CFStringCreateWithCString failed!\n")); 332 CFRelease(hData); 333 } 334 else 335 Log(("takePasteboardOwnership: CFDataCreate failed!\n")); 336 } 337 else 338 Log(("takePasteboardOwnership: PasteboardClear failed -> %d (%#x)\n", orc, orc)); 339 return orc == 0 ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 340 } 341 342 /** 286 343 * Write clipboard content to the host clipboard from the internal clipboard 287 344 * structure. 288 345 * 289 346 * @param pPasteboard Reference to the global pasteboard. 347 * @param idOwnership The ownership ID. 290 348 * @param pv The source buffer. 291 349 * @param cb The size of the source buffer. … … 294 352 * @returns IPRT status code. 295 353 */ 296 int writeToPasteboard(PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat)354 int writeToPasteboard(PasteboardRef pPasteboard, uint64_t idOwnership, void *pv, uint32_t cb, uint32_t fFormat) 297 355 { 298 356 Log(("writeToPasteboard: fFormat = %02X\n", fFormat)); 299 300 /* Clear the pasteboard */301 if (PasteboardClear(pPasteboard))302 return VERR_NOT_SUPPORTED;303 357 304 358 /* Make sure all is in sync */ … … 342 396 343 397 CFDataRef textData = NULL; 344 /* Item id is 1. Nothing special here. */345 PasteboardItemID itemId = (PasteboardItemID)1;346 398 /* Create a CData object which we could pass to the pasteboard */ 347 399 if ((textData = CFDataCreate(kCFAllocatorDefault, … … 349 401 { 350 402 /* Put the Utf-16 version to the pasteboard */ 351 PasteboardPutItemFlavor(pPasteboard, itemId, 352 kUTTypeUTF16PlainText, 353 textData, 0); 403 PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeUTF16PlainText, textData, 0); 354 404 } 355 405 /* Create a Utf-8 version */ … … 363 413 { 364 414 /* Put the Utf-8 version to the pasteboard */ 365 PasteboardPutItemFlavor(pPasteboard, itemId, 366 kUTTypeUTF8PlainText, 367 textData, 0); 415 PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeUTF8PlainText, textData, 0); 368 416 } 369 417 RTStrFree(pszDestText); … … 380 428 size_t cbBmpSize; 381 429 CFDataRef bmpData = NULL; 382 /* Item id is 1. Nothing special here. */383 PasteboardItemID itemId = (PasteboardItemID)1;384 430 385 431 rc = ShClDibToBmp(pv, cb, &pBmp, &cbBmpSize); … … 391 437 { 392 438 /* Put the Utf-8 version to the pasteboard */ 393 PasteboardPutItemFlavor(pPasteboard, itemId, 394 kUTTypeBMP, 395 bmpData, 0); 439 PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeBMP, bmpData, 0); 396 440 } 397 441 RTMemFree(pBmp);
Note:
See TracChangeset
for help on using the changeset viewer.