Changeset 78440 in vbox for trunk/src/VBox
- Timestamp:
- May 7, 2019 5:44:31 PM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk
r78307 r78440 52 52 VBoxClipboard.cpp \ 53 53 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp 54 ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 55 VBoxTray_SOURCES += \ 56 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardURIList.cpp \ 57 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardURIObject.cpp \ 58 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardPath.cpp \ 59 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp \ 60 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardEnumFormatEtcImpl-win.cpp \ 61 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp 62 endif 54 63 endif 55 64 ifdef VBOX_WITH_DRAG_AND_DROP -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
r78317 r78440 174 174 { 175 175 /* Insert the requested clipboard format data into the clipboard. */ 176 uint32_t u32Format = 0; 177 UINT format = (UINT)wParam; 178 179 LogFlowFunc(("WM_RENDERFORMAT, format = %x\n", format)); 180 switch (format) 176 uint32_t fFormat = VBOX_SHARED_CLIPBOARD_FMT_NONE; 177 178 const UINT cfFormat = (UINT)wParam; 179 switch (cfFormat) 181 180 { 182 181 case CF_UNICODETEXT: 183 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;182 fFormat = VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT; 184 183 break; 185 184 186 185 case CF_DIB: 187 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_BITMAP;186 fFormat = VBOX_SHARED_CLIPBOARD_FMT_BITMAP; 188 187 break; 189 188 189 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 190 case CF_HDROP: 191 fFormat = VBOX_SHARED_CLIPBOARD_FMT_URI_LIST; 192 break; 193 #endif 190 194 default: 191 if ( format >= 0xC000)195 if (cfFormat >= 0xC000) /** @todo r=andy Explain. */ 192 196 { 193 TCHAR szFormatName[256]; 194 195 int cActual = GetClipboardFormatName( format, szFormatName, sizeof(szFormatName) / sizeof(TCHAR));197 TCHAR szFormatName[256]; /** @todo r=andy Do we need Unicode support here as well? */ 198 199 int cActual = GetClipboardFormatName(cfFormat, szFormatName, sizeof(szFormatName) / sizeof(TCHAR)); 196 200 if (cActual) 197 201 { 198 202 if (strcmp(szFormatName, "HTML Format") == 0) 199 { 200 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_HTML; 201 } 203 fFormat = VBOX_SHARED_CLIPBOARD_FMT_HTML; 202 204 } 203 205 } … … 205 207 } 206 208 207 if (u32Format == 0) 209 LogFunc(("WM_RENDERFORMAT: format=%u -> fFormat=0x%x\n", cfFormat, fFormat)); 210 211 if (fFormat == VBOX_SHARED_CLIPBOARD_FMT_NONE) 208 212 { 209 213 /* Unsupported clipboard format is requested. */ 210 Log FlowFunc(("Unsupported clipboard format requested: %ld\n", u32Format));214 LogRel(("Clipboard: Unsupported clipboard format requested (0x%x)\n", fFormat)); 211 215 VBoxClipboardWinClear(); 212 216 } 217 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 218 else if (fFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 219 { 220 221 } 222 #endif 213 223 else 214 224 { 215 const uint32_t cbPrealloc = 4096; /** @todo r=andy Make it dynamic for supporting larger text buffers! */225 const uint32_t cbPrealloc = _4K; 216 226 uint32_t cb = 0; 217 227 … … 228 238 { 229 239 /* Read the host data to the preallocated buffer. */ 230 int vboxrc = VbglR3ClipboardReadData(pCtx->u32ClientID, u32Format, pMem, cbPrealloc, &cb);240 int vboxrc = VbglR3ClipboardReadData(pCtx->u32ClientID, fFormat, pMem, cbPrealloc, &cb); 231 241 LogFlowFunc(("VbglR3ClipboardReadData returned with rc = %Rrc\n", vboxrc)); 232 242 … … 259 269 /* Read the host data to the preallocated buffer. */ 260 270 uint32_t cbNew = 0; 261 vboxrc = VbglR3ClipboardReadData(pCtx->u32ClientID, u32Format, pMem, cb, &cbNew);271 vboxrc = VbglR3ClipboardReadData(pCtx->u32ClientID, fFormat, pMem, cb, &cbNew); 262 272 LogFlowFunc(("VbglR3ClipboardReadData returned with rc = %Rrc, cb = %d, cbNew = %d\n", vboxrc, cb, cbNew)); 263 273 … … 287 297 * must have the exact string size. 288 298 */ 289 if ( u32Format == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)299 if (fFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 290 300 { 291 301 size_t cbActual = 0; … … 319 329 /* 'hMem' contains the host clipboard data. 320 330 * size is 'cb' and format is 'format'. */ 321 HANDLE hClip = SetClipboardData( format, hMem);331 HANDLE hClip = SetClipboardData(cfFormat, hMem); 322 332 LogFlowFunc(("WM_RENDERFORMAT hClip = %p\n", hClip)); 323 333 … … 362 372 { 363 373 /* Announce available formats. Do not insert data, they will be inserted in WM_RENDER*. */ 364 uint32_t u32Formats = (uint32_t)lParam;365 366 LogFlowFunc(("VBOX_WM_SHCLPB_SET_FORMATS: u32Formats=0x%x\n", u32Formats));374 VBOXCLIPBOARDFORMATS fFormats = (uint32_t)lParam; 375 376 LogFlowFunc(("VBOX_WM_SHCLPB_SET_FORMATS: fFormats=0x%x\n", fFormats)); 367 377 368 378 int vboxrc = VBoxClipboardWinOpen(hwnd); … … 373 383 HANDLE hClip = NULL; 374 384 375 if ( u32Formats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)385 if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 376 386 hClip = SetClipboardData(CF_UNICODETEXT, NULL); 377 387 378 if ( u32Formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)388 if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 379 389 hClip = SetClipboardData(CF_DIB, NULL); 380 390 381 if ( u32Formats & VBOX_SHARED_CLIPBOARD_FMT_HTML)391 if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_HTML) 382 392 { 383 393 UINT format = RegisterClipboardFormat("HTML Format"); … … 387 397 388 398 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 389 if ( u32Formats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)399 if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 390 400 hClip = SetClipboardData(CF_HDROP, NULL); 391 401 #endif 402 403 /** @todo Implement more flexible clipboard precedence for supported formats. */ 404 405 if (hClip == NULL) 406 LogRel(("Clipboard: Unsupported format(s) from host (0x%x), ignoring\n", fFormats)); 407 392 408 VBoxClipboardWinClose(); 393 409 … … 479 495 if (hDrop) 480 496 { 481 vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST,482 ); 497 /* vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST, 498 );*/ 483 499 GlobalUnlock(hClip); 484 500 } … … 681 697 break; 682 698 683 LogF lowFunc(("Error getting host message, rc=%Rrc\n", rc));699 LogFunc(("Error getting host message, rc=%Rrc\n", rc)); 684 700 685 701 if (*pfShutdown) … … 701 717 * respond to WM_RENDERFORMAT message. */ 702 718 ::PostMessage(pWinCtx->hWnd, VBOX_CLIPBOARD_WM_SET_FORMATS, 0, u32Formats); 703 }704 719 break; 720 } 705 721 706 722 case VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA: … … 708 724 /* The host needs data in the specified format. */ 709 725 ::PostMessage(pWinCtx->hWnd, VBOX_CLIPBOARD_WM_READ_DATA, 0, u32Formats); 710 }711 726 break; 727 } 712 728 713 729 case VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT: … … 716 732 LogRel(("Clipboard: Terminating ...\n")); 717 733 ASMAtomicXchgBool(pfShutdown, true); 718 }719 734 break; 735 } 720 736 721 737 default: … … 725 741 /* Wait a bit before retrying. */ 726 742 RTThreadSleep(1000); 727 }728 743 break; 744 } 729 745 } 730 746 } -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp
r78393 r78440 22 22 #include <iprt/thread.h> 23 23 24 #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD 24 25 #include <VBox/log.h> 26 25 27 #include <VBox/GuestHost/SharedClipboard.h> 26 28 #include <VBox/GuestHost/SharedClipboard-win.h> … … 275 277 AssertPtrReturn(puFormats, VERR_INVALID_POINTER); 276 278 277 if (!pCtx) 278 { 279 *puFormats = 0; 280 return VINF_SUCCESS; 281 } 282 283 uint32_t uFormats = 0; 279 uint32_t uFormats = VBOX_SHARED_CLIPBOARD_FMT_NONE; 284 280 285 281 /* Query list of available formats and report to host. */ … … 336 332 } 337 333 else 334 { 335 LogFlowFunc(("uFormats = 0x%08X\n", uFormats)); 338 336 *puFormats = uFormats; 339 340 return rc; 341 } 342 337 } 338 339 return rc; 340 } 341 -
trunk/src/VBox/HostServices/SharedClipboard/Makefile.kmk
r78307 r78440 43 43 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp \ 44 44 darwin-pasteboard.cpp 45 ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 46 VBoxSharedClipboard_SOURCES += \ 47 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardURIList.cpp \ 48 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardURIObject.cpp \ 49 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardPath.cpp 50 endif 45 51 if1of ($(KBUILD_TARGET), linux solaris freebsd) ## @todo X11 46 52 ifndef VBOX_HEADLESS -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp
r78317 r78440 25 25 #include <VBox/HostServices/VBoxClipboardSvc.h> 26 26 #include <VBox/GuestHost/SharedClipboard-win.h> 27 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 28 # include <VBox/GuestHost/SharedClipboard-uri.h> 29 #endif 27 30 28 31 #include <iprt/alloc.h> … … 30 33 #include <iprt/asm.h> 31 34 #include <iprt/assert.h> 35 #include <iprt/ldr.h> 36 #include <iprt/semaphore.h> 32 37 #include <iprt/thread.h> 33 #include <iprt/ldr.h>34 38 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 35 39 # include <iprt/utf16.h> … … 58 62 RTTHREAD hThread; 59 63 /** Event which gets triggered if the host clipboard needs to render its data. */ 60 HANDLEhRenderEvent;64 RTSEMEVENT hRenderEvent; 61 65 /** Structure for keeping and communicating with client data (from the guest). */ 62 66 PVBOXCLIPBOARDCLIENTDATA pClient; … … 115 119 void *pvDst, uint32_t cbDst, uint32_t *pcbActualDst) 116 120 { 117 LogFlow (("vboxClipboardGetDatacbSrc = %d, cbDst = %d\n", cbSrc, cbDst));121 LogFlowFunc(("cbSrc = %d, cbDst = %d\n", cbSrc, cbDst)); 118 122 119 123 if ( u32Format == VBOX_SHARED_CLIPBOARD_FMT_HTML … … 139 143 *pcbActualDst = 0; 140 144 } 141 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST142 if (u32Format == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)143 {144 /* Convert data to URI list. */145 }146 #endif147 145 else 148 146 { … … 163 161 } 164 162 165 static int vboxClipboardReadDataFromClient(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format)163 static int vboxClipboardReadDataFromClient(VBOXCLIPBOARDCONTEXT *pCtx, VBOXCLIPBOARDFORMAT fFormat) 166 164 { 167 165 Assert(pCtx->pClient); … … 169 167 Assert(pCtx->pClient->data.pv == NULL && pCtx->pClient->data.cb == 0 && pCtx->pClient->data.u32Format == 0); 170 168 171 LogFlow(("vboxClipboardReadDataFromClient u32Format = %02X\n", u32Format)); 172 173 ResetEvent(pCtx->hRenderEvent); 174 175 vboxSvcClipboardReportMsg(pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, u32Format); 176 177 DWORD ret = WaitForSingleObject(pCtx->hRenderEvent, INFINITE); 178 LogFlow(("vboxClipboardReadDataFromClient wait completed, ret 0x%08X, err %d\n", 179 ret, GetLastError())); NOREF(ret); 180 181 return VINF_SUCCESS; 169 LogFlowFunc(("fFormat=%02X\n", fFormat)); 170 171 vboxSvcClipboardReportMsg(pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, fFormat); 172 173 return RTSemEventWait(pCtx->hRenderEvent, 30 * 1000 /* Timeout in ms */); 182 174 } 183 175 … … 193 185 case WM_CLIPBOARDUPDATE: 194 186 { 195 Log (("WM_CLIPBOARDUPDATE\n"));187 LogFunc(("WM_CLIPBOARDUPDATE\n")); 196 188 197 189 if (GetClipboardOwner() != hwnd) … … 205 197 case WM_CHANGECBCHAIN: 206 198 { 207 Log (("WM_CHANGECBCHAIN\n"));199 LogFunc(("WM_CHANGECBCHAIN\n")); 208 200 209 201 if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI)) … … 240 232 case WM_DRAWCLIPBOARD: 241 233 { 242 Log (("WM_DRAWCLIPBOARD\n"));234 LogFunc(("WM_DRAWCLIPBOARD\n")); 243 235 244 236 if (GetClipboardOwner() != hwnd) … … 251 243 if (pWinCtx->hWndNextInChain) 252 244 { 253 Log (("WM_DRAWCLIPBOARD next %p\n", pWinCtx->hWndNextInChain));245 LogFunc(("WM_DRAWCLIPBOARD next %p\n", pWinCtx->hWndNextInChain)); 254 246 /* Pass the message to next windows in the clipboard chain. */ 255 247 DWORD_PTR dwResult; … … 290 282 { 291 283 /* Insert the requested clipboard format data into the clipboard. */ 292 uint32_t u32Format = 0;284 VBOXCLIPBOARDFORMAT fFormat = VBOX_SHARED_CLIPBOARD_FMT_NONE; 293 285 294 286 UINT format = (UINT)wParam; 295 287 296 Log (("WM_RENDERFORMAT: Format %u\n", format));288 LogFunc(("WM_RENDERFORMAT: Format %u\n", format)); 297 289 298 290 switch (format) 299 291 { 300 292 case CF_UNICODETEXT: 301 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;293 fFormat |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT; 302 294 break; 303 295 304 296 case CF_DIB: 305 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_BITMAP;297 fFormat |= VBOX_SHARED_CLIPBOARD_FMT_BITMAP; 306 298 break; 307 299 … … 314 306 { 315 307 if (RTStrCmp(szFormatName, "HTML Format") == 0) 316 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_HTML;308 fFormat |= VBOX_SHARED_CLIPBOARD_FMT_HTML; 317 309 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 318 310 if ( RTStrCmp(szFormatName, CFSTR_FILEDESCRIPTOR) == 0 319 311 || RTStrCmp(szFormatName, CFSTR_FILECONTENTS) == 0) 320 u32Format |= VBOX_SHARED_CLIPBOARD_FMT_URI_LIST;312 fFormat |= VBOX_SHARED_CLIPBOARD_FMT_URI_LIST; 321 313 #endif 322 314 } … … 325 317 } 326 318 327 if (u32Format == 0 || pCtx->pClient == NULL) 319 if ( fFormat == VBOX_SHARED_CLIPBOARD_FMT_NONE 320 || pCtx->pClient == NULL) 328 321 { 329 322 /* Unsupported clipboard format is requested. */ 330 Log (("WM_RENDERFORMAT unsupported format requested or client is not active.\n"));331 EmptyClipboard 323 LogFunc(("WM_RENDERFORMAT unsupported format requested or client is not active\n")); 324 EmptyClipboard(); 332 325 } 333 326 else 334 327 { 335 int vboxrc = vboxClipboardReadDataFromClient(pCtx, u32Format);328 int vboxrc = vboxClipboardReadDataFromClient(pCtx, fFormat); 336 329 337 330 LogFunc(("vboxClipboardReadDataFromClient vboxrc = %d, pv %p, cb %d, u32Format %d\n", … … 341 334 && pCtx->pClient->data.pv != NULL 342 335 && pCtx->pClient->data.cb > 0 343 && pCtx->pClient->data.u32Format == u32Format)336 && pCtx->pClient->data.u32Format == fFormat) 344 337 { 345 338 HANDLE hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, pCtx->pClient->data.cb); … … 355 348 if (pMem) 356 349 { 357 Log (("WM_RENDERFORMAT setting data\n"));350 LogFunc(("WM_RENDERFORMAT setting data\n")); 358 351 359 352 if (pCtx->pClient->data.pv) … … 401 394 case WM_RENDERALLFORMATS: 402 395 { 403 Log (("WM_RENDERALLFORMATS\n"));396 LogFunc(("WM_RENDERALLFORMATS\n")); 404 397 405 398 /* Do nothing. The clipboard formats will be unavailable now, because the … … 414 407 else 415 408 { 416 LogFlow (("vboxClipboardWndProc:WM_RENDERALLFORMATS: error in open clipboard. hwnd: %x, rc: %Rrc\n", hwnd, vboxrc));409 LogFlowFunc(("WM_RENDERALLFORMATS: error in open clipboard. hwnd: %x, rc: %Rrc\n", hwnd, vboxrc)); 417 410 } 418 411 } break; … … 425 418 * because host clipboard has more priority. 426 419 */ 427 Log (("VBOX_CLIPBOARD_WM_SET_FORMATS ignored\n"));420 LogFunc(("VBOX_CLIPBOARD_WM_SET_FORMATS ignored\n")); 428 421 break; 429 422 } … … 432 425 uint32_t u32Formats = (uint32_t)lParam; 433 426 434 Log (("VBOX_CLIPBOARD_WM_SET_FORMATS: u32Formats=%02X\n", u32Formats));427 LogFunc(("VBOX_CLIPBOARD_WM_SET_FORMATS: u32Formats=%02X\n", u32Formats)); 435 428 436 429 int vboxrc = VBoxClipboardWinOpen(hwnd); … … 439 432 VBoxClipboardWinClear(); 440 433 441 Log (("VBOX_CLIPBOARD_WM_SET_FORMATS emptied clipboard\n"));434 LogFunc(("VBOX_CLIPBOARD_WM_SET_FORMATS emptied clipboard\n")); 442 435 443 436 HANDLE hClip = NULL; … … 486 479 default: 487 480 { 488 Log (("WM_ %p\n", msg));481 LogFunc(("WM_ %p\n", msg)); 489 482 rc = DefWindowProc(hwnd, msg, wParam, lParam); 490 483 } 491 484 } 492 485 493 Log (("WM_ rc %d\n", rc));486 LogFunc(("WM_ rc %d\n", rc)); 494 487 return rc; 495 488 } … … 497 490 DECLCALLBACK(int) VBoxClipboardThread(RTTHREAD hThreadSelf, void *pvUser) 498 491 { 499 RT_NOREF2(hThreadSelf, pvUser); 492 RT_NOREF(hThreadSelf, pvUser); 493 500 494 /* Create a window and make it a clipboard viewer. */ 501 495 int rc = VINF_SUCCESS; 502 496 503 LogFlow (("VBoxClipboardThread\n"));497 LogFlowFuncEnter(); 504 498 505 499 const PVBOXCLIPBOARDCONTEXT pCtx = &g_ctx; … … 522 516 if (atomWindowClass == 0) 523 517 { 524 Log (("Failed to register window class\n"));518 LogFunc(("Failed to register window class\n")); 525 519 rc = VERR_NOT_SUPPORTED; 526 520 } … … 534 528 if (pWinCtx->hWnd == NULL) 535 529 { 536 Log (("Failed to create window\n"));530 LogFunc(("Failed to create window\n")); 537 531 rc = VERR_NOT_SUPPORTED; 538 532 } … … 559 553 */ 560 554 Assert(msgret >= 0); 561 Log (("VBoxClipboardThreadMessage loop finished. GetMessage returned %d, message id: %d \n", msgret, msg.message));555 LogFunc(("Message loop finished. GetMessage returned %d, message id: %d \n", msgret, msg.message)); 562 556 } 563 557 } … … 578 572 * formats to the guest. 579 573 * 580 * @returns VBox status code .574 * @returns VBox status code, VINF_NO_CHANGE if no synchronization was required. 581 575 * @param pCtx Clipboard context to synchronize. 582 576 */ … … 585 579 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 586 580 587 if (pCtx->pClient == NULL) /* If we don't have any client data (yet), bail out. */ 588 return VINF_SUCCESS; 589 590 uint32_t uFormats; 591 int rc = VBoxClipboardWinGetFormats(&pCtx->Win, &uFormats); 592 if (RT_SUCCESS(rc)) 593 vboxSvcClipboardReportMsg(pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_REPORT_FORMATS, uFormats); 594 581 int rc; 582 583 if (pCtx->pClient) 584 { 585 uint32_t uFormats; 586 rc = VBoxClipboardWinGetFormats(&pCtx->Win, &uFormats); 587 if (RT_SUCCESS(rc)) 588 vboxSvcClipboardReportMsg(pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_REPORT_FORMATS, uFormats); 589 } 590 else /* If we don't have any client data (yet), bail out. */ 591 rc = VINF_NO_CHANGE; 592 593 LogFlowFuncLeaveRC(rc); 595 594 return rc; 596 595 } … … 601 600 int vboxClipboardInit(void) 602 601 { 603 int rc = VINF_SUCCESS; 604 605 RT_ZERO(g_ctx); 602 RT_ZERO(g_ctx); /* Be careful not messing up non-POD types! */ 606 603 607 604 /* Check that new Clipboard API is available. */ 608 605 VBoxClipboardWinCheckAndInitNewAPI(&g_ctx.Win.newAPI); 609 606 610 g_ctx.hRenderEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 611 612 rc = RTThreadCreate(&g_ctx.hThread, VBoxClipboardThread, NULL, _64K /* Stack size */, 613 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 607 int rc = RTSemEventCreate(&g_ctx.hRenderEvent); 608 if (RT_SUCCESS(rc)) 609 { 610 rc = RTThreadCreate(&g_ctx.hThread, VBoxClipboardThread, NULL, _64K /* Stack size */, 611 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 612 } 614 613 615 614 if (RT_FAILURE(rc)) 616 { 617 CloseHandle(g_ctx.hRenderEvent); 618 } 615 RTSemEventDestroy(g_ctx.hRenderEvent); 619 616 620 617 return rc; … … 623 620 void vboxClipboardDestroy(void) 624 621 { 625 Log (("vboxClipboardDestroy\n"));622 LogFlowFuncEnter(); 626 623 627 624 if (g_ctx.Win.hWnd) … … 630 627 } 631 628 632 CloseHandle(g_ctx.hRenderEvent); 629 int rc = RTSemEventDestroy(g_ctx.hRenderEvent); 630 AssertRC(rc); 633 631 634 632 /* Wait for the window thread to terminate. */ 635 RTThreadWait(g_ctx.hThread, RT_INDEFINITE_WAIT, NULL); 633 rc = RTThreadWait(g_ctx.hThread, 30 * 1000 /* Timeout in ms */, NULL); 634 if (RT_FAILURE(rc)) 635 LogRel(("Shared Clipboard: Waiting for window thread termination failed with rc=%Rrc\n", rc)); 636 636 637 637 g_ctx.hThread = NIL_RTTHREAD; … … 640 640 int vboxClipboardConnect(VBOXCLIPBOARDCLIENTDATA *pClient, bool fHeadless) 641 641 { 642 NOREF(fHeadless); 643 Log(("vboxClipboardConnect\n")); 642 RT_NOREF(fHeadless); 643 644 LogFlowFuncEnter(); 644 645 645 646 if (g_ctx.pClient != NULL) … … 667 668 void vboxClipboardDisconnect(VBOXCLIPBOARDCLIENTDATA *pClient) 668 669 { 669 RT_NOREF1(pClient); 670 Log(("vboxClipboardDisconnect\n")); 670 RT_NOREF(pClient); 671 672 LogFlowFuncEnter(); 671 673 672 674 g_ctx.pClient = NULL; … … 684 686 } 685 687 686 int DumpHtml(const char *pszSrc, size_t cb) 688 #ifdef VBOX_STRICT 689 static int vboxClipboardDbgDumpHtml(const char *pszSrc, size_t cb) 687 690 { 688 691 size_t cchIgnored = 0; … … 701 704 } 702 705 else 703 Log (("Error in copying string.\n"));704 Log (("Removed \\r\\n: %s\n", pszBuf));706 LogFunc(("Error in copying string\n")); 707 LogFunc(("Removed \\r\\n: %s\n", pszBuf)); 705 708 RTMemFree(pszBuf); 706 709 } … … 708 711 { 709 712 rc = VERR_NO_MEMORY; 710 Log (("Not enough memory to allocate buffer.\n"));713 LogFunc(("Not enough memory to allocate buffer\n")); 711 714 } 712 715 } 713 716 return rc; 714 717 } 718 #endif 715 719 716 720 int vboxClipboardReadData(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual) … … 719 723 AssertPtrReturn(pClient->pCtx, VERR_INVALID_POINTER); 720 724 721 LogFlow (("vboxClipboardReadData: u32Format =%02X\n", u32Format));725 LogFlowFunc(("u32Format=%02X\n", u32Format)); 722 726 723 727 HANDLE hClip = NULL; … … 731 735 if (RT_SUCCESS(rc)) 732 736 { 733 LogFunc(("Clipboard opened .\n"));737 LogFunc(("Clipboard opened\n")); 734 738 735 739 if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 736 740 { 737 741 hClip = GetClipboardData(CF_DIB); 738 739 742 if (hClip != NULL) 740 743 { … … 759 762 { 760 763 hClip = GetClipboardData(CF_UNICODETEXT); 761 762 764 if (hClip != NULL) 763 765 { … … 782 784 { 783 785 UINT format = RegisterClipboardFormat("HTML Format"); 784 785 786 if (format != 0) 786 787 { 787 788 hClip = GetClipboardData(format); 788 789 789 if (hClip != NULL) 790 790 { 791 791 LPVOID lp = GlobalLock(hClip); 792 793 792 if (lp != NULL) 794 793 { … … 797 796 vboxClipboardGetData(VBOX_SHARED_CLIPBOARD_FMT_HTML, lp, GlobalSize(hClip), 798 797 pv, cb, pcbActual); 799 LogRelFlowFunc(("Raw HTML clipboard data from host :")); 800 DumpHtml((char *)pv, cb); 798 #ifdef VBOX_STRICT 799 LogFlowFunc(("Raw HTML clipboard data from host:")); 800 vboxClipboardDbgDumpHtml((char *)pv, cb); 801 #endif 801 802 GlobalUnlock(hClip); 802 803 } … … 811 812 else if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 812 813 { 813 #if 0 814 UINT format = RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR); 815 if (format) 816 { 817 hClip = GetClipboardData(format); 818 if (hClip != NULL) 814 hClip = GetClipboardData(CF_HDROP); 815 if (hClip != NULL) 816 { 817 LPVOID lp = GlobalLock(hClip); 818 if (lp) 819 819 { 820 LPVOID lp = GlobalLock(hClip); 821 822 if (lp != NULL) 820 /* Convert to a string list, separated by \r\n. */ 821 DROPFILES *pDropFiles = (DROPFILES *)hClip; 822 AssertPtr(pDropFiles); 823 824 /* Do we need to do Unicode stuff? */ 825 const bool fUnicode = RT_BOOL(pDropFiles->fWide); 826 827 /* Get the offset of the file list. */ 828 Assert(pDropFiles->pFiles >= sizeof(DROPFILES)); 829 830 /* Note: This is *not* pDropFiles->pFiles! DragQueryFile only 831 * will work with the plain storage medium pointer! */ 832 HDROP hDrop = (HDROP)(hClip); 833 834 /* First, get the file count. */ 835 /** @todo Does this work on Windows 2000 / NT4? */ 836 char *pszFiles = NULL; 837 uint32_t cchFiles = 0; 838 UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, NULL /* lpszFile */, 0 /* cchFile */); 839 840 LogRel(("Shared Clipboard: Got %RU16 file(s), fUnicode=%RTbool\n", cFiles, fUnicode)); 841 842 for (UINT i = 0; i < cFiles; i++) 823 843 { 824 LogFunc(("CF_HTML\n")); 825 826 vboxClipboardGetData(VBOX_SHARED_CLIPBOARD_FMT_HTML, lp, GlobalSize(hClip), 827 pv, cb, pcbActual); 828 LogRelFlowFunc(("Raw HTML clipboard data from host :")); 829 DumpHtml((char *)pv, cb); 830 GlobalUnlock(hClip); 831 } 832 else 833 { 834 hClip = NULL; 835 } 836 } 837 } 838 #else 839 /* Convert to a string list, separated by \r\n. */ 840 DROPFILES *pDropFiles = (DROPFILES *)hClip; 841 AssertPtr(pDropFiles); 842 843 /* Do we need to do Unicode stuff? */ 844 const bool fUnicode = RT_BOOL(pDropFiles->fWide); 845 846 /* Get the offset of the file list. */ 847 Assert(pDropFiles->pFiles >= sizeof(DROPFILES)); 848 849 /* Note: This is *not* pDropFiles->pFiles! DragQueryFile only 850 * will work with the plain storage medium pointer! */ 851 HDROP hDrop = (HDROP)(hClip); 852 853 /* First, get the file count. */ 854 /** @todo Does this work on Windows 2000 / NT4? */ 855 char *pszFiles = NULL; 856 uint32_t cchFiles = 0; 857 UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, NULL /* lpszFile */, 0 /* cchFile */); 858 859 LogRel(("DnD: Got %RU16 file(s), fUnicode=%RTbool\n", cFiles, fUnicode)); 860 861 for (UINT i = 0; i < cFiles; i++) 862 { 863 UINT cchFile = DragQueryFile(hDrop, i /* File index */, NULL /* Query size first */, 0 /* cchFile */); 864 Assert(cchFile); 865 866 if (RT_FAILURE(rc)) 867 break; 868 869 char *pszFileUtf8 = NULL; /* UTF-8 version. */ 870 UINT cchFileUtf8 = 0; 871 if (fUnicode) 872 { 873 /* Allocate enough space (including terminator). */ 874 WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cchFile + 1) * sizeof(WCHAR)); 875 if (pwszFile) 876 { 877 const UINT cwcFileUtf16 = DragQueryFileW(hDrop, i /* File index */, 878 pwszFile, cchFile + 1 /* Include terminator */); 879 880 AssertMsg(cwcFileUtf16 == cchFile, ("cchFileUtf16 (%RU16) does not match cchFile (%RU16)\n", 881 cwcFileUtf16, cchFile)); 882 RT_NOREF(cwcFileUtf16); 883 884 rc = RTUtf16ToUtf8(pwszFile, &pszFileUtf8); 844 UINT cchFile = DragQueryFile(hDrop, i /* File index */, NULL /* Query size first */, 0 /* cchFile */); 845 Assert(cchFile); 846 847 if (RT_FAILURE(rc)) 848 break; 849 850 char *pszFileUtf8 = NULL; /* UTF-8 version. */ 851 UINT cchFileUtf8 = 0; 852 if (fUnicode) 853 { 854 /* Allocate enough space (including terminator). */ 855 WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cchFile + 1) * sizeof(WCHAR)); 856 if (pwszFile) 857 { 858 const UINT cwcFileUtf16 = DragQueryFileW(hDrop, i /* File index */, 859 pwszFile, cchFile + 1 /* Include terminator */); 860 861 AssertMsg(cwcFileUtf16 == cchFile, ("cchFileUtf16 (%RU16) does not match cchFile (%RU16)\n", 862 cwcFileUtf16, cchFile)); 863 RT_NOREF(cwcFileUtf16); 864 865 rc = RTUtf16ToUtf8(pwszFile, &pszFileUtf8); 866 if (RT_SUCCESS(rc)) 867 { 868 cchFileUtf8 = (UINT)strlen(pszFileUtf8); 869 Assert(cchFileUtf8); 870 } 871 872 RTMemFree(pwszFile); 873 } 874 else 875 rc = VERR_NO_MEMORY; 876 } 877 else /* ANSI */ 878 { 879 /* Allocate enough space (including terminator). */ 880 pszFileUtf8 = (char *)RTMemAlloc((cchFile + 1) * sizeof(char)); 881 if (pszFileUtf8) 882 { 883 cchFileUtf8 = DragQueryFileA(hDrop, i /* File index */, 884 pszFileUtf8, cchFile + 1 /* Include terminator */); 885 886 AssertMsg(cchFileUtf8 == cchFile, ("cchFileUtf8 (%RU16) does not match cchFile (%RU16)\n", 887 cchFileUtf8, cchFile)); 888 } 889 else 890 rc = VERR_NO_MEMORY; 891 } 892 885 893 if (RT_SUCCESS(rc)) 886 894 { 887 cchFileUtf8 = (UINT)strlen(pszFileUtf8); 888 Assert(cchFileUtf8); 895 LogFlowFunc(("\tFile: %s (cchFile=%RU16)\n", pszFileUtf8, cchFileUtf8)); 896 897 LogRel2(("Shared Clipboard: Adding host file '%s'\n", pszFileUtf8)); 898 899 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFileUtf8, cchFileUtf8); 900 if (RT_SUCCESS(rc)) 901 cchFiles += cchFileUtf8; 889 902 } 890 891 RTMemFree(pwszFile); 903 else 904 LogRel(("Shared Clipboard: Error handling file entry #%u, rc=%Rrc\n", i, rc)); 905 906 if (pszFileUtf8) 907 RTStrFree(pszFileUtf8); 908 909 if (RT_FAILURE(rc)) 910 break; 911 912 /* Add separation between filenames. 913 * Note: Also do this for the last element of the list. */ 914 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, "\r\n", 2 /* Bytes */); 915 if (RT_SUCCESS(rc)) 916 cchFiles += 2; /* Include \r\n */ 892 917 } 893 else 894 rc = VERR_NO_MEMORY; 918 919 if (RT_SUCCESS(rc)) 920 { 921 cchFiles += 1; /* Add string termination. */ 922 uint32_t cbFiles = cchFiles * sizeof(char); 923 924 LogFlowFunc(("cFiles=%u, cchFiles=%RU32, cbFiles=%RU32, pszFiles=0x%p\n", 925 cFiles, cchFiles, cbFiles, pszFiles)); 926 927 /* Translate the list into URI elements. */ 928 SharedClipboardURIList lstURI; 929 rc = lstURI.AppendNativePathsFromList(pszFiles, cbFiles, 930 SHAREDCLIPBOARDURILIST_FLAGS_ABSOLUTE_PATHS); 931 if (RT_SUCCESS(rc)) 932 { 933 RTCString strRoot = lstURI.GetRootEntries(); 934 size_t cbRoot = strRoot.length() + 1; /* Include termination */ 935 936 if (cbRoot > cb) /** @todo Add overflow handling! */ 937 cbRoot = cb; /* Never copy more than the available buffer supplies. */ 938 939 memcpy(pv, strRoot.c_str(), cbRoot); 940 941 *pcbActual = (uint32_t)cbRoot; 942 } 943 } 944 945 LogFlowFunc(("Building CF_HDROP list rc=%Rrc, pszFiles=0x%p, cFiles=%RU16, cchFiles=%RU32\n", 946 rc, pszFiles, cFiles, cchFiles)); 947 948 if (pszFiles) 949 RTStrFree(pszFiles); 950 951 GlobalUnlock(hClip); 895 952 } 896 else /* ANSI */ 897 { 898 /* Allocate enough space (including terminator). */ 899 pszFileUtf8 = (char *)RTMemAlloc((cchFile + 1) * sizeof(char)); 900 if (pszFileUtf8) 901 { 902 cchFileUtf8 = DragQueryFileA(hDrop, i /* File index */, 903 pszFileUtf8, cchFile + 1 /* Include terminator */); 904 905 AssertMsg(cchFileUtf8 == cchFile, ("cchFileUtf8 (%RU16) does not match cchFile (%RU16)\n", 906 cchFileUtf8, cchFile)); 907 } 908 else 909 rc = VERR_NO_MEMORY; 910 } 911 912 if (RT_SUCCESS(rc)) 913 { 914 LogFlowFunc(("\tFile: %s (cchFile=%RU16)\n", pszFileUtf8, cchFileUtf8)); 915 916 LogRel(("DnD: Adding guest file '%s'\n", pszFileUtf8)); 917 918 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFileUtf8, cchFileUtf8); 919 if (RT_SUCCESS(rc)) 920 cchFiles += cchFileUtf8; 921 } 922 else 923 LogRel(("DnD: Error handling file entry #%u, rc=%Rrc\n", i, rc)); 924 925 if (pszFileUtf8) 926 RTStrFree(pszFileUtf8); 927 928 if (RT_FAILURE(rc)) 929 break; 930 931 /* Add separation between filenames. 932 * Note: Also do this for the last element of the list. */ 933 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, "\r\n", 2 /* Bytes */); 934 if (RT_SUCCESS(rc)) 935 cchFiles += 2; /* Include \r\n */ 936 } 937 938 if (RT_SUCCESS(rc)) 939 { 940 cchFiles += 1; /* Add string termination. */ 941 uint32_t cbFiles = cchFiles * sizeof(char); 942 943 LogFlowFunc(("cFiles=%u, cchFiles=%RU32, cbFiles=%RU32, pszFiles=0x%p\n", 944 cFiles, cchFiles, cbFiles, pszFiles)); 945 946 /* Translate the list into URI elements. */ 947 DnDURIList lstURI; 948 rc = lstURI.AppendNativePathsFromList(pszFiles, cbFiles, 949 DNDURILIST_FLAGS_ABSOLUTE_PATHS); 950 if (RT_SUCCESS(rc)) 951 { 952 RTCString strRoot = lstURI.GetRootEntries(); 953 size_t cbRoot = strRoot.length() + 1; /* Include termination */ 954 955 mpvData = RTMemAlloc(cbRoot); 956 if (mpvData) 957 { 958 memcpy(mpvData, strRoot.c_str(), cbRoot); 959 mcbData = cbRoot; 960 } 961 else 962 rc = VERR_NO_MEMORY; 963 } 964 } 965 966 LogFlowFunc(("Building CF_HDROP list rc=%Rrc, pszFiles=0x%p, cFiles=%RU16, cchFiles=%RU32\n", 967 rc, pszFiles, cFiles, cchFiles)); 968 969 if (pszFiles) 970 RTStrFree(pszFiles); 971 break; 972 #endif /* 0 */ 953 } 973 954 } 974 955 #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */ 975 956 VBoxClipboardWinClose(); 976 957 } 977 else978 {979 LogFunc(("vboxClipboardReadData: failed to open clipboard, rc: %Rrc\n", rc));980 }981 958 982 959 if (hClip == NULL) 983 960 { 984 961 /* Reply with empty data. */ 985 vboxClipboardGetData(0, NULL, 0, 986 pv, cb, pcbActual); 987 } 988 989 return VINF_SUCCESS; 962 vboxClipboardGetData(0, NULL, 0, pv, cb, pcbActual); 963 } 964 965 return VINF_SUCCESS; /** @todo r=andy Return rc here? */ 990 966 } 991 967 992 968 void vboxClipboardWriteData(VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format) 993 969 { 994 LogFlow (("vboxClipboardWriteData\n"));970 LogFlowFuncEnter(); 995 971 996 972 /* … … 1032 1008 } 1033 1009 1034 SetEvent(pClient->pCtx->hRenderEvent); 1010 AssertPtr(pClient->pCtx); 1011 int rc = RTSemEventSignal(pClient->pCtx->hRenderEvent); 1012 AssertRC(rc); 1013 1014 /** @todo Return rc. */ 1035 1015 } 1036 1016 … … 1127 1107 else 1128 1108 { 1129 LogRelFlowFunc(("Error: Unknown CF_HTML format. Expected EndFragment .\n"));1109 LogRelFlowFunc(("Error: Unknown CF_HTML format. Expected EndFragment\n")); 1130 1110 rc = VERR_NO_MEMORY; 1131 1111 } … … 1139 1119 else 1140 1120 { 1141 LogRelFlowFunc(("Error: Unknown CF_HTML format. Expected EndFragment. rc = %Rrc .\n", rc));1121 LogRelFlowFunc(("Error: Unknown CF_HTML format. Expected EndFragment. rc = %Rrc\n", rc)); 1142 1122 rc = VERR_INVALID_PARAMETER; 1143 1123 } … … 1145 1125 else 1146 1126 { 1147 LogRelFlowFunc(("Error: Unknown CF_HTML format. Expected StartFragment. rc = %Rrc .\n", rc));1127 LogRelFlowFunc(("Error: Unknown CF_HTML format. Expected StartFragment. rc = %Rrc\n", rc)); 1148 1128 rc = VERR_INVALID_PARAMETER; 1149 1129 } … … 1190 1170 if (!RT_SUCCESS(rc)) 1191 1171 { 1192 LogRelFlowFunc(("Error: invalid source fragment. rc = %Rrc .\n"));1172 LogRelFlowFunc(("Error: invalid source fragment. rc = %Rrc\n")); 1193 1173 return VERR_INVALID_PARAMETER; 1194 1174 } … … 1230 1210 if (pszResult == NULL) 1231 1211 { 1232 LogRelFlowFunc(("Error: Cannot allocate memory for result buffer. rc = %Rrc .\n"));1212 LogRelFlowFunc(("Error: Cannot allocate memory for result buffer. rc = %Rrc\n")); 1233 1213 return VERR_NO_MEMORY; 1234 1214 } … … 1259 1239 return VINF_SUCCESS; 1260 1240 } 1241
Note:
See TracChangeset
for help on using the changeset viewer.