- Timestamp:
- May 18, 2019 3:48:41 PM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
r78501 r78581 39 39 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 40 40 /** !!! HACK ALERT !!! Dynamically resolve functions! */ 41 # ifdef _WIN32_IE42 # undef _WIN32_IE43 # define _WIN32_IE 0x050144 # endif45 # include <iprt/win/shlobj.h>46 # include <iprt/win/shlwapi.h>41 # ifdef _WIN32_IE 42 # undef _WIN32_IE 43 # define _WIN32_IE 0x0501 44 # endif 45 # include <iprt/win/shlobj.h> 46 # include <iprt/win/shlwapi.h> 47 47 #endif 48 48 … … 73 73 74 74 75 static LRESULT vboxClipboard ProcessMsg(PVBOXCLIPBOARDCONTEXT pCtx, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)75 static LRESULT vboxClipboardWinProcessMsg(PVBOXCLIPBOARDCONTEXT pCtx, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 76 76 { 77 77 AssertPtr(pCtx); … … 83 83 switch (msg) 84 84 { 85 86 85 case WM_CLIPBOARDUPDATE: 86 { 87 87 if (GetClipboardOwner() != hwnd) 88 88 { … … 98 98 else 99 99 LogFlowFunc(("WM_CLIPBOARDUPDATE: No change (VBoxTray is owner)\n")); 100 101 102 103 104 100 } 101 break; 102 103 case WM_CHANGECBCHAIN: 104 { 105 105 if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI)) 106 106 { … … 132 132 } 133 133 } 134 135 136 137 138 139 140 141 142 134 } 135 break; 136 137 case WM_DRAWCLIPBOARD: 138 { 139 LogFlowFunc(("WM_DRAWCLIPBOARD, hwnd %p\n", pWinCtx->hWnd)); 140 141 if (GetClipboardOwner() != hwnd) 142 { 143 143 /* Clipboard was updated by another application. */ 144 144 /* WM_DRAWCLIPBOARD always expects a return code of 0, so don't change "rc" here. */ … … 147 147 if (RT_SUCCESS(rc)) 148 148 rc = VbglR3ClipboardReportFormats(pCtx->u32ClientID, fFormats); 149 150 151 152 149 } 150 151 if (pWinCtx->hWndNextInChain) 152 { 153 153 /* Pass the message to next windows in the clipboard chain. */ 154 154 SendMessageTimeout(pWinCtx->hWndNextInChain, msg, wParam, lParam, 0, VBOX_CLIPBOARD_CBCHAIN_TIMEOUT_MS, NULL); 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 155 } 156 } 157 break; 158 159 case WM_TIMER: 160 { 161 if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI)) 162 break; 163 164 HWND hViewer = GetClipboardViewer(); 165 166 /* Re-register ourselves in the clipboard chain if our last ping 167 * timed out or there seems to be no valid chain. */ 168 if (!hViewer || pWinCtx->oldAPI.fCBChainPingInProcess) 169 { 170 VBoxClipboardWinRemoveFromCBChain(pWinCtx); 171 VBoxClipboardWinAddToCBChain(pWinCtx); 172 } 173 174 /* Start a new ping by passing a dummy WM_CHANGECBCHAIN to be 175 * processed by ourselves to the chain. */ 176 pWinCtx->oldAPI.fCBChainPingInProcess = TRUE; 177 178 hViewer = GetClipboardViewer(); 179 if (hViewer) 180 SendMessageCallback(hViewer, WM_CHANGECBCHAIN, (WPARAM)pWinCtx->hWndNextInChain, (LPARAM)pWinCtx->hWndNextInChain, 181 VBoxClipboardWinChainPingProc, (ULONG_PTR)pWinCtx); 182 } 183 break; 184 185 case WM_CLOSE: 186 { 187 /* Do nothing. Ignore the message. */ 188 } 189 break; 190 191 case WM_RENDERFORMAT: 192 { 193 LogFunc(("WM_RENDERFORMAT\n")); 194 195 /* Insert the requested clipboard format data into the clipboard. */ 196 const UINT cfFormat = (UINT)wParam; 197 198 const VBOXCLIPBOARDFORMAT fFormat = VBoxClipboardWinClipboardFormatToVBox(cfFormat); 199 200 LogFunc(("WM_RENDERFORMAT: cfFormat=%u -> fFormat=0x%x\n", cfFormat, fFormat)); 201 202 if (fFormat == VBOX_SHARED_CLIPBOARD_FMT_NONE) 203 { 204 LogFunc(("WM_RENDERFORMAT: Unsupported format requested\n")); 205 VBoxClipboardWinClear(); 206 } 207 else 208 { 209 const uint32_t cbPrealloc = _4K; 210 uint32_t cb = 0; 211 212 /* Preallocate a buffer, most of small text transfers will fit into it. */ 213 HANDLE hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbPrealloc); 214 LogFlowFunc(("Preallocated handle hMem = %p\n", hMem)); 215 216 if (hMem) 217 { 218 void *pMem = GlobalLock(hMem); 219 LogFlowFunc(("Locked pMem = %p, GlobalSize = %ld\n", pMem, GlobalSize(hMem))); 220 221 if (pMem) 222 { 223 /* Read the host data to the preallocated buffer. */ 224 int rc = VbglR3ClipboardReadData(pCtx->u32ClientID, fFormat, pMem, cbPrealloc, &cb); 225 LogFlowFunc(("VbglR3ClipboardReadData returned with rc = %Rrc\n", rc)); 226 227 if (RT_SUCCESS(rc)) 228 { 229 if (cb == 0) 230 { 231 /* 0 bytes returned means the clipboard is empty. 232 * Deallocate the memory and set hMem to NULL to get to 233 * the clipboard empty code path. */ 234 GlobalUnlock(hMem); 235 GlobalFree(hMem); 236 hMem = NULL; 237 } 238 else if (cb > cbPrealloc) 239 { 240 GlobalUnlock(hMem); 241 242 /* The preallocated buffer is too small, adjust the size. */ 243 hMem = GlobalReAlloc(hMem, cb, 0); 244 LogFlowFunc(("Reallocated hMem = %p\n", hMem)); 245 246 if (hMem) 247 { 248 pMem = GlobalLock(hMem); 249 LogFlowFunc(("Locked pMem = %p, GlobalSize = %ld\n", pMem, GlobalSize(hMem))); 250 251 if (pMem) 252 { 253 /* Read the host data to the preallocated buffer. */ 254 uint32_t cbNew = 0; 255 rc = VbglR3ClipboardReadData(pCtx->u32ClientID, fFormat, pMem, cb, &cbNew); 256 LogFlowFunc(("VbglR3ClipboardReadData returned with rc = %Rrc, cb = %d, cbNew = %d\n", 257 rc, cb, cbNew)); 258 259 if (RT_SUCCESS(rc) 260 && cbNew <= cb) 261 { 262 cb = cbNew; 263 } 264 else 265 { 266 GlobalUnlock(hMem); 267 GlobalFree(hMem); 268 hMem = NULL; 269 } 270 } 271 else 272 { 273 GlobalFree(hMem); 274 hMem = NULL; 275 } 276 } 277 } 278 279 if (hMem) 280 { 281 /* pMem is the address of the data. cb is the size of returned data. */ 282 /* Verify the size of returned text, the memory block for clipboard 283 * must have the exact string size. 284 */ 285 if (fFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 286 { 287 size_t cbActual = 0; 288 HRESULT hrc = StringCbLengthW((LPWSTR)pMem, cb, &cbActual); 289 if (FAILED(hrc)) 290 { 291 /* Discard invalid data. */ 292 GlobalUnlock(hMem); 293 GlobalFree(hMem); 294 hMem = NULL; 295 } 296 else 297 { 298 /* cbActual is the number of bytes, excluding those used 299 * for the terminating null character. 300 */ 301 cb = (uint32_t)(cbActual + 2); 302 } 303 } 304 } 305 306 if (hMem) 307 { 308 GlobalUnlock(hMem); 309 310 hMem = GlobalReAlloc(hMem, cb, 0); 311 LogFlowFunc(("Reallocated hMem = %p\n", hMem)); 312 313 if (hMem) 314 { 315 /* 'hMem' contains the host clipboard data. 316 * size is 'cb' and format is 'format'. */ 317 HANDLE hClip = SetClipboardData(cfFormat, hMem); 318 LogFlowFunc(("WM_RENDERFORMAT hClip = %p\n", hClip)); 319 320 if (hClip) 321 { 322 /* The hMem ownership has gone to the system. Finish the processing. */ 323 break; 324 } 325 326 /* Cleanup follows. */ 327 } 328 } 329 } 330 if (hMem) 331 GlobalUnlock(hMem); 332 } 333 if (hMem) 334 GlobalFree(hMem); 335 } 336 } 337 } 338 break; 339 340 case WM_RENDERALLFORMATS: 341 { 342 /* Do nothing. The clipboard formats will be unavailable now, because the 343 * windows is to be destroyed and therefore the guest side becomes inactive. 344 */ 345 int rc = VBoxClipboardWinOpen(hwnd); 346 if (RT_SUCCESS(rc)) 347 { 348 348 VBoxClipboardWinClear(); 349 349 VBoxClipboardWinClose(); 350 351 352 353 354 355 350 } 351 } 352 break; 353 354 case VBOX_CLIPBOARD_WM_SET_FORMATS: 355 { 356 356 /* Announce available formats. Do not insert data, they will be inserted in WM_RENDER*. */ 357 357 VBOXCLIPBOARDFORMATS fFormats = (uint32_t)lParam; … … 389 389 else if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 390 390 { 391 LogFunc(("VBOX_WM_SHCLPB_SET_FORMATS: VBOX_CLIPBOARD_WIN_REGFMT_URI_LIST\n")); 392 if (pWinCtx->URI.pDataObj == NULL) /* Only allow one transfer at a time. */ 391 LogFunc(("VBOX_WM_SHCLPB_SET_FORMATS: VBOX_CLIPBOARD_WIN_REGFMT_URI_LIST cTransfers=%RU32\n", 392 pWinCtx->URI.cTransfers)); 393 if (pWinCtx->URI.cTransfers == 0) /* Only allow one transfer at a time for now. */ 393 394 { 394 pWinCtx->URI. pDataObj = new VBoxClipboardWinDataObject(/* No additional formats needed right now */);395 if (pWinCtx->URI. pDataObj)395 pWinCtx->URI.Transfer.pDataObj = new VBoxClipboardWinDataObject(/* No additional formats needed right now */); 396 if (pWinCtx->URI.Transfer.pDataObj) 396 397 { 397 rc = pWinCtx->URI. pDataObj->Init(pCtx->u32ClientID);398 rc = pWinCtx->URI.Transfer.pDataObj->Init(pCtx->u32ClientID); 398 399 if (RT_SUCCESS(rc)) 399 400 { … … 405 406 * OleSetClipboard() will fail. Needs fixing. */ 406 407 407 HRESULT hr = OleSetClipboard(pWinCtx->URI.pDataObj); 408 if (FAILED(hr)) 408 HRESULT hr = OleSetClipboard(pWinCtx->URI.Transfer.pDataObj); 409 if (SUCCEEDED(hr)) 410 { 411 pWinCtx->URI.cTransfers++; 412 } 413 else 409 414 LogRel(("Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr)); 410 415 } … … 423 428 LogFunc(("VBOX_WM_SHCLPB_SET_FORMATS: cfFormat=%u, lastErr=%ld\n", cfFormat, GetLastError())); 424 429 } 425 426 427 428 429 430 431 uint32_t u32Formats= (uint32_t)lParam;432 433 434 LogFlowFunc(("VBOX_WM_SHCLPB_READ_DATA: u32Formats=0x%x\n", u32Formats));435 436 437 438 439 if (u 32Formats &VBOX_SHARED_CLIPBOARD_FMT_BITMAP)430 } 431 break; 432 433 case VBOX_CLIPBOARD_WM_READ_DATA: 434 { 435 /* Send data in the specified format to the host. */ 436 VBOXCLIPBOARDFORMAT uFormat = (uint32_t)lParam; 437 HANDLE hClip = NULL; 438 439 LogFlowFunc(("VBOX_WM_SHCLPB_READ_DATA: uFormat=0x%x\n", uFormat)); 440 441 int rc = VBoxClipboardWinOpen(hwnd); 442 if (RT_SUCCESS(rc)) 443 { 444 if (uFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 440 445 { 441 446 hClip = GetClipboardData(CF_DIB); … … 455 460 } 456 461 } 457 else if (u 32Formats &VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)462 else if (uFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 458 463 { 459 464 hClip = GetClipboardData(CF_UNICODETEXT); … … 473 478 } 474 479 } 475 else if (u 32Formats &VBOX_SHARED_CLIPBOARD_FMT_HTML)480 else if (uFormat == VBOX_SHARED_CLIPBOARD_FMT_HTML) 476 481 { 477 482 UINT format = RegisterClipboardFormat(VBOX_CLIPBOARD_WIN_REGFMT_HTML); … … 497 502 } 498 503 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 499 else if (u 32Formats &VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)504 else if (uFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 500 505 { 501 506 /* The data data in CF_HDROP format, as the files are locally present and don't need to be … … 507 512 if (hDrop) 508 513 { 509 /* vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST, 510 );*/ 514 char *pszList; 515 size_t cbList; 516 rc = VBoxClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &pszList, &cbList); 517 if (RT_SUCCESS(rc)) 518 { 519 rc = VbglR3ClipboardWriteData(pCtx->u32ClientID, uFormat, pszList, (uint32_t)cbList); 520 RTMemFree(pszList); 521 } 522 511 523 GlobalUnlock(hClip); 512 524 } … … 518 530 } 519 531 #endif 532 if (hClip == NULL) 533 { 534 LogFunc(("VBOX_WM_SHCLPB_READ_DATA: hClip=NULL, lastError=%ld\n", GetLastError())); 535 536 /* Requested clipboard format is not available, send empty data. */ 537 VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_NONE, NULL, 0); 538 } 539 520 540 VBoxClipboardWinClose(); 521 } 522 523 if (hClip == NULL) 524 { 525 /* Requested clipboard format is not available, send empty data. */ 526 VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_NONE, NULL, 0); 527 } 528 } 529 break; 530 531 case WM_DESTROY: 532 { 533 VBoxClipboardWinRemoveFromCBChain(pWinCtx); 534 if (pWinCtx->oldAPI.timerRefresh) 541 } 542 } 543 break; 544 545 case WM_DESTROY: 546 { 547 VBoxClipboardWinRemoveFromCBChain(pWinCtx); 548 if (pWinCtx->oldAPI.timerRefresh) 535 549 KillTimer(pWinCtx->hWnd, 0); 536 537 538 539 540 541 542 543 544 545 546 547 550 /* 551 * don't need to call PostQuitMessage cause 552 * the VBoxTray already finished a message loop 553 */ 554 } 555 break; 556 557 default: 558 { 559 lresultRc = DefWindowProc(hwnd, msg, wParam, lParam); 560 } 561 break; 548 562 } 549 563 … … 554 568 } 555 569 556 static LRESULT CALLBACK vboxClipboardW ndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);570 static LRESULT CALLBACK vboxClipboardWinWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 557 571 558 572 static int vboxClipboardCreateWindow(PVBOXCLIPBOARDCONTEXT pCtx) … … 573 587 { 574 588 wc.style = CS_NOCLOSE; 575 wc.lpfnWndProc = vboxClipboardW ndProc;589 wc.lpfnWndProc = vboxClipboardWinWndProc; 576 590 wc.hInstance = pCtx->pEnv->hInstance; 577 591 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); … … 626 640 } 627 641 628 static LRESULT CALLBACK vboxClipboardW ndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)642 static LRESULT CALLBACK vboxClipboardWinWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 629 643 { 630 644 PVBOXCLIPBOARDCONTEXT pCtx = &g_Ctx; /** @todo r=andy Make pCtx available through SetWindowLongPtr() / GWL_USERDATA. */ … … 632 646 633 647 /* Forward with proper context. */ 634 return vboxClipboard ProcessMsg(pCtx, hWnd, uMsg, wParam, lParam);648 return vboxClipboardWinProcessMsg(pCtx, hWnd, uMsg, wParam, lParam); 635 649 } 636 650 -
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp
r78315 r78581 499 499 /* 500 500 * Send the (meta) data; in case of URIs it's the (non-recursive) file/directory 501 * URI list the host needs to know upfront to set up the drag'n dropoperation.501 * URI list the host needs to know upfront to set up the Shared Clipboard operation. 502 502 */ 503 503 RTCString strRootDest = lstURI.GetRootEntries(); -
trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
r78307 r78581 103 103 clipboard.cpp 104 104 ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 105 ifdef VBOX_WITH_LIBFUSE 105 VBoxClient_SOURCES += \ 106 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardURIList.cpp \ 107 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardURIObject.cpp \ 108 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/ClipboardPath.cpp 109 ifdef VBOX_WITH_LIBFUSE_DISABLED 106 110 VBoxClient_SOURCES += \ 107 111 clipboard-fuse.cpp … … 170 174 171 175 include $(FILE_KBUILD_SUB_FOOTER) 172 -
trunk/src/VBox/Additions/x11/VBoxClient/clipboard.cpp
r78346 r78581 181 181 * @returns VBox status code 182 182 */ 183 int vboxClipboardConnect(void)183 int VBoxClipboardSvcImplConnect(void) 184 184 { 185 185 int rc = VINF_SUCCESS; … … 294 294 if (RT_FAILURE(rc)) 295 295 VBClFatalError(("Failed to connect to the VirtualBox kernel service, rc=%Rrc\n", rc)); 296 rc = vboxClipboardConnect();296 rc = VBoxClipboardSvcImplConnect(); 297 297 /* Not RT_SUCCESS: VINF_PERMISSION_DENIED is host service not present. */ 298 298 if (rc == VINF_SUCCESS) -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardCache.cpp
r78501 r78581 75 75 uint16_t SharedClipboardCache::AddRef(void) 76 76 { 77 return ASMAtomicIncU 16(&m_cRefs);77 return ASMAtomicIncU32(&m_cRefs); 78 78 } 79 79 … … 86 86 { 87 87 Assert(m_cRefs); 88 return ASMAtomicDecU 16(&m_cRefs);88 return ASMAtomicDecU32(&m_cRefs); 89 89 } 90 90 -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp
r78501 r78581 594 594 /** 595 595 * Converts a DROPFILES (HDROP) structure to a string list, separated by \r\n. 596 * Does not do any locking on the input data. 596 597 * 597 598 * @returns VBox status code. 598 599 * @param pDropFiles Pointer to DROPFILES structure to convert. 599 * @param ppvData Where to return the converted (allocated) data on success. 600 * @param ppszData Where to return the converted (allocated) data on success. 601 * Must be free'd by the caller with RTMemFree(). 600 602 * @param pcbData Size (in bytes) of the allocated data returned. 601 603 */ 602 int VBoxClipboardWinDropFilesToStringList(DROPFILES *pDropFiles, void **ppvData, size_t *pcbData)604 int VBoxClipboardWinDropFilesToStringList(DROPFILES *pDropFiles, char **ppszbData, size_t *pcbData) 603 605 { 604 606 AssertPtrReturn(pDropFiles, VERR_INVALID_POINTER); 605 AssertPtrReturn(pp vData,VERR_INVALID_POINTER);607 AssertPtrReturn(ppszbData, VERR_INVALID_POINTER); 606 608 AssertPtrReturn(pcbData, VERR_INVALID_POINTER); 607 609 … … 725 727 memcpy(pvData, strRoot.c_str(), cbRoot); 726 728 727 *pp vData =pvData;728 *pcbData = cbRoot;729 *ppszbData = (char *)pvData; 730 *pcbData = cbRoot; 729 731 } 730 732 else -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r78161 r78581 75 75 * Structures and Typedefs * 76 76 *********************************************************************************************************************************/ 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; 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; 89 93 90 94 … … 101 105 /** The table mapping X11 names to data formats and to the corresponding 102 106 * VBox clipboard formats (currently only Unicode) */ 103 static struct _CLIPFORMATTABLE 104 { 105 /** The X11 atom name of the format (several names can match one format) 106 */ 107 static struct _CLIPX11FORMATTABLE 108 { 109 /** The X11 atom name of the format (several names can match one format) */ 107 110 const char *pcszAtom; 108 /** The format corresponding to thename */109 CLIP FORMAT enmFormat;111 /** The format target corresponding to the atom name */ 112 CLIPX11FORMATTARGET enmTarget; 110 113 /** The corresponding VBox clipboard format */ 111 uint32_t u32VBoxFormat;114 VBOXCLIPBOARDFORMAT vboxFormat; 112 115 } g_aFormats[] = 113 116 { 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 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 131 133 /** @todo Inkscape exports image/png but not bmp... */ 132 134 }; … … 134 136 enum 135 137 { 136 NIL_CLIPX11FORMAT= 0,137 MAX_CLIP_X11_FORMATS= RT_ELEMENTS(g_aFormats)138 CLIPX11FORMATIDX_NIL = 0, 139 CLIPX11FORMATIDX_MAX = RT_ELEMENTS(g_aFormats) 138 140 }; 139 141 140 142 141 /** Return the atom corresponding to a supported X11 format.143 /** Returnx the atom name corresponding to a supported X11 format index. 142 144 * @param widget a valid Xt widget 143 145 */ 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 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. 163 167 * @param widget a valid Xt widget 164 168 */ 165 static CLIPX11FORMAT clipFindX11FormatByAtom(CLIPBACKEND *pCtx, Atom atomFormat)169 static CLIPX11FORMATIDX clipGetFmtIdxFromAtom(CLIPBACKEND *pCtx, Atom atomFormat) 166 170 { 167 171 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 168 if (clip AtomForX11Format(pCtx, i) == atomFormat)172 if (clipGetAtomFromFmtIdx(pCtx, i) == atomFormat) 169 173 return i; 170 return NIL_CLIPX11FORMAT;174 return CLIPX11FORMATIDX_NIL; 171 175 } 172 176 … … 176 180 * @param widget a valid Xt widget 177 181 */ 178 static CLIPX11FORMAT clipFindX11FormatByAtomText(const char *pcsz)182 static CLIPX11FORMATIDX clipGetFmtIdxFromAtomText(const char *pcsz) 179 183 { 180 184 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 181 185 if (!strcmp(g_aFormats[i].pcszAtom, pcsz)) 182 186 return i; 183 return NIL_CLIPX11FORMAT;184 } 185 #endif 186 187 /** 188 * Enumerates supported X11 clipboard formats corresponding to a given VBox 189 * format.187 return CLIPX11FORMATIDX_NIL; 188 } 189 #endif 190 191 /** 192 * Enumerates supported X11 clipboard formats corresponding to a given VBox format. 193 * 190 194 * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMAT if 191 195 * there are no more 192 * @param lastF ormat The valuereturned from the last call of this function.193 * Use NIL_CLIPX11FORMATto start the enumeration.194 */ 195 static CLIPX11FORMAT clipEnumX11Formats(uint32_t u32VBoxFormats,196 CLIPX11FORMAT lastFormat)197 { 198 for (unsigned i = lastF ormat+ 1; i < RT_ELEMENTS(g_aFormats); ++i)199 if ( u32VBoxFormats & clipVBoxFormatForX11Format(i))196 * @param lastFmtIdx The format index returned from the last call of this function. 197 * Use CLIPX11FORMATIDX_NIL to start the enumeration. 198 */ 199 static CLIPX11FORMATIDX clipEnumFmtIdxForVBoxFmt(VBOXCLIPBOARDFORMAT vboxFormat, 200 CLIPX11FORMATIDX lastFmtIdx) 201 { 202 for (unsigned i = lastFmtIdx + 1; i < RT_ELEMENTS(g_aFormats); ++i) 203 if (vboxFormat & clipGetVBoxFmtFromFmtIdx(i)) 200 204 return i; 201 return NIL_CLIPX11FORMAT;205 return CLIPX11FORMATIDX_NIL; 202 206 } 203 207 … … 222 226 /** The best text format X11 has to offer, as an index into the formats 223 227 * table */ 224 CLIPX11FORMAT X11TextFormat;228 CLIPX11FORMATIDX X11TextFmtIdx; 225 229 /** The best bitmap format X11 has to offer, as an index into the formats 226 230 * table */ 227 CLIPX11FORMAT X11BitmapFormat;231 CLIPX11FORMATIDX X11BitmapFmtIdx; 228 232 /** The best HTML format X11 has to offer, as an index into the formats 229 233 * table */ 230 CLIPX11FORMAT X11HTMLFormat; 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 231 240 /** What formats does VBox have on offer? */ 232 uint32_tvboxFormats;241 VBOXCLIPBOARDFORMATS vboxFormats; 233 242 /** Cache of the last unicode data that we received */ 234 243 void *pvUnicodeCache; … … 358 367 (XtPointer)client_data); 359 368 ssize_t cbWritten = write(pCtx->wakeupPipeWrite, WAKE_UP_STRING, WAKE_UP_STRING_LEN); 360 NOREF(cbWritten);369 RT_NOREF(cbWritten); 361 370 #else 362 RT_NOREF 1(pCtx);371 RT_NOREF(pCtx); 363 372 testQueueToEventThread(proc, client_data); 364 373 #endif … … 370 379 static void clipReportFormatsToVBox(CLIPBACKEND *pCtx) 371 380 { 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); 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); 380 391 } 381 392 … … 385 396 static void clipResetX11Formats(CLIPBACKEND *pCtx) 386 397 { 387 pCtx->X11TextFormat = INVALID; 388 pCtx->X11BitmapFormat = INVALID; 389 pCtx->X11HTMLFormat = INVALID; 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 390 404 } 391 405 … … 397 411 } 398 412 399 /** 400 * Go through an array of X11 clipboard targets to see if they contain a text 413 #ifdef TESTCASE 414 static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx) 415 { 416 bool success = true; 417 CLIPX11FORMAT targets[2]; 418 CLIPX11FORMAT x11Format; 419 targets[0] = clipGetFmtIdxFromAtomText("text/plain"); 420 targets[1] = clipGetFmtIdxFromAtomText("image/bmp"); 421 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 422 if (clipGetTargetFmtFromFmtIdx(x11Format) != TEXT) 423 success = false; 424 targets[0] = clipGetFmtIdxFromAtomText("UTF8_STRING"); 425 targets[1] = clipGetFmtIdxFromAtomText("text/plain"); 426 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 427 if (clipGetTargetFmtFromFmtIdx(x11Format) != UTF8) 428 success = false; 429 return success; 430 } 431 #endif 432 433 /** 434 * Go through an array of X11 clipboard targets to see if they contain a bitmap 401 435 * format we can support, and if so choose the ones we prefer (e.g. we like 402 * Utf8 better than plain text). 436 * BMP better than PNG because we don't have to convert). 437 * 403 438 * @param pCtx the clipboard backend context structure 404 439 * @param pTargets the list of targets 405 440 * @param cTargets the size of the list in @a pTargets 406 441 */ 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); 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 415 452 for (unsigned i = 0; i < cTargets; ++i) 416 453 { 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)) 454 CLIPX11FORMATIDX format = paTargets[i]; 455 if (format != CLIPX11FORMATIDX_NIL) 456 { 457 if ( (clipGetVBoxFmtFromFmtIdx(format) == vboxFormat) 458 && enmBestTarget < clipGetTargetFmtFromFmtIdx(format)) 423 459 { 424 enmBestT extTarget = clipRealFormatForX11Format(format);425 best TextFormat= format;460 enmBestTarget = clipGetTargetFmtFromFmtIdx(format); 461 bestFmtIdx = format; 426 462 } 427 463 } 428 464 } 429 return bestTextFormat; 430 } 431 432 #ifdef TESTCASE 433 static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx) 434 { 435 bool success = true; 436 CLIPX11FORMAT targets[2]; 437 CLIPX11FORMAT x11Format; 438 targets[0] = clipFindX11FormatByAtomText("text/plain"); 439 targets[1] = clipFindX11FormatByAtomText("image/bmp"); 440 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 441 if (clipRealFormatForX11Format(x11Format) != TEXT) 442 success = false; 443 targets[0] = clipFindX11FormatByAtomText("UTF8_STRING"); 444 targets[1] = clipFindX11FormatByAtomText("text/plain"); 445 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2); 446 if (clipRealFormatForX11Format(x11Format) != UTF8) 447 success = false; 448 return success; 449 } 450 #endif 451 452 /** 453 * Go through an array of X11 clipboard targets to see if they contain a bitmap 454 * format we can support, and if so choose the ones we prefer (e.g. we like 455 * BMP better than PNG because we don't have to convert). 465 return bestFmtIdx; 466 } 467 468 /** 469 * Go through an array of X11 clipboard targets to see if we can support any 470 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8 471 * better than plain text). 472 * 456 473 * @param pCtx the clipboard backend context structure 457 474 * @param pTargets the list of targets 458 475 * @param cTargets the size of the list in @a pTargets 459 476 */ 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);468 for (unsigned i = 0; i < cTargets; ++i)469 {470 CLIPX11FORMAT format = pTargets[i];471 if (format != NIL_CLIPX11FORMAT)472 {473 if ( (clipVBoxFormatForX11Format(format)474 == VBOX_SHARED_CLIPBOARD_FMT_BITMAP)475 && enmBestBitmapTarget < clipRealFormatForX11Format(format))476 {477 enmBestBitmapTarget = clipRealFormatForX11Format(format);478 bestBitmapFormat = format;479 }480 }481 }482 return bestBitmapFormat;483 }484 485 /**486 * Go through an array of X11 clipboard targets to see if they contain a HTML487 * format we can support, and if so choose the ones we prefer488 * @param pCtx the clipboard backend context structure489 * @param pTargets the list of targets490 * @param cTargets the size of the list in @a pTargets491 */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 516 517 /**518 * Go through an array of X11 clipboard targets to see if we can support any519 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8520 * better than plain text).521 * @param pCtx the clipboard backend context structure522 * @param pTargets the list of targets523 * @param cTargets the size of the list in @a pTargets524 */525 477 static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, 526 CLIPX11FORMAT *pTargets, size_t cTargets)478 CLIPX11FORMATIDX *paTargets, size_t cTargets) 527 479 { 528 480 AssertPtrReturnVoid(pCtx); 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 } 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 549 502 } 550 503 … … 554 507 * Update the context's information about targets currently supported by X11, 555 508 * based on an array of X11 atoms. 509 * 556 510 * @param pCtx the context to be updated 557 511 * @param pTargets the array of atoms describing the targets supported 558 512 * @param cTargets the size of the array @a pTargets 559 513 */ 560 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets,561 size_t cTargets) 562 { 563 LogRel2 (("%s: called\n", __FUNCTION__)); 514 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMATIDX *paTargetFmtIdx, size_t cTargets) 515 { 516 LogRel2(("Shared clipboard: clipUpdateX11Targets called\n")); 517 564 518 #ifndef VBOX_AFTER_5_2 565 519 pCtx->fBusy = false; … … 572 526 } 573 527 #endif 574 if (pTargets == NULL) { 528 529 if (paTargetFmtIdx == NULL) 530 { 575 531 /* No data available */ 576 532 clipReportEmptyX11CB(pCtx); 577 533 return; 578 534 } 579 clipGetFormatsFromTargets(pCtx, pTargets, cTargets); 535 536 clipGetFormatsFromTargets(pCtx, paTargetFmtIdx, cTargets); 580 537 clipReportFormatsToVBox(pCtx); 581 538 } … … 588 545 * unit test. So keep it simple, be paranoid and log everything. 589 546 */ 590 static void clipConvertX11Targets(Widget widget, XtPointer p ClientData,547 static void clipConvertX11Targets(Widget widget, XtPointer pSvcCtxData, 591 548 Atom * /* selection */, Atom *atomType, 592 549 XtPointer pValue, long unsigned int *pcLen, 593 550 int *piFormat) 594 551 { 595 RT_NOREF1(piFormat); 596 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClientData); 552 RT_NOREF(piFormat); 553 554 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pSvcCtxData); 597 555 Atom *pAtoms = (Atom *)pValue; 598 556 unsigned i, j; 599 LogRel2(("%s: pValue=%p, *pcLen=%u, *atomType=%d%s\n", __FUNCTION__, 557 558 LogRel2(("Shared clipboard: pValue=%p, *pcLen=%u, *atomType=%d%s\n", 600 559 pValue, *pcLen, *atomType, 601 560 *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : "")); 602 CLIPX11FORMAT *pFormats = NULL; 561 562 CLIPX11FORMATIDX *paFmtIdx = NULL; 563 603 564 if (*pcLen && pValue && (*atomType != XT_CONVERT_FAIL /* time out */)) 604 pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT)); 565 paFmtIdx = (CLIPX11FORMATIDX *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMATIDX)); 566 605 567 #if defined(DEBUG) && !defined(TESTCASE) 606 568 if (pValue) 607 569 { 608 570 for (i = 0; i < *pcLen; ++i) 571 { 609 572 if (pAtoms[i]) 610 573 { 611 574 char *pszName = XGetAtomName(XtDisplay(widget), pAtoms[i]); 612 LogRel2(("%s: found target %s\n", __FUNCTION__, 613 pszName)); 575 LogRel(("Shared clipboard: Found target %s\n", pszName)); 614 576 XFree(pszName); 615 577 } 616 578 else 617 LogRel2(("%s: found empty target.\n", __FUNCTION__)); 618 } 619 #endif 620 if (pFormats) 579 LogRel(("Shared clipboard: Found empty target\n")); 580 } 581 } 582 #endif 583 584 if (paFmtIdx) 621 585 { 622 586 for (i = 0; i < *pcLen; ++i) … … 624 588 for (j = 0; j < RT_ELEMENTS(g_aFormats); ++j) 625 589 { 626 Atom target = XInternAtom(XtDisplay(widget), 627 g_aFormats[j].pcszAtom, False); 590 Atom target = XInternAtom(XtDisplay(widget), g_aFormats[j].pcszAtom, False); 628 591 if (*(pAtoms + i) == target) 629 p Formats[i] = j;592 paFmtIdx[i] = j; 630 593 } 631 594 #if defined(DEBUG) && !defined(TESTCASE) 632 LogRel 2(("%s: reporting format %d (%s)\n", __FUNCTION__,633 pFormats[i], g_aFormats[pFormats[i]].pcszAtom));595 LogRel(("Shared clipboard: Reporting format %d (%s)\n", 596 paFmtIdx[i], g_aFormats[paFmtIdx[i]].pcszAtom)); 634 597 #endif 635 598 } 636 599 } 637 600 else 638 LogRel2(("%s: reporting empty targets (none reported or allocation failure).\n", 639 __FUNCTION__)); 640 clipUpdateX11Targets(pCtx, pFormats, *pcLen); 641 RTMemFree(pFormats); 601 LogRel2(("Shared clipboard: Reporting empty targets (none reported or allocation failure)\n")); 602 603 clipUpdateX11Targets(pCtx, paFmtIdx, *pcLen); 604 605 RTMemFree(paFmtIdx); 642 606 XtFree(reinterpret_cast<char *>(pValue)); 643 607 } … … 652 616 static void clipQueryX11CBFormats(CLIPBACKEND *pCtx) 653 617 { 654 LogRel2 ((" %s: requesting the targets that the X11 clipboard offers\n",655 __PRETTY_FUNCTION__)); 618 LogRel2 (("Shared clipboard: Requesting the targets that the X11 clipboard offers\n")); 619 656 620 #ifndef VBOX_AFTER_5_2 657 621 if (pCtx->fBusy) … … 718 682 static DECLCALLBACK(int) clipEventThread(RTTHREAD hThreadSelf, void *pvUser) 719 683 { 720 RT_NOREF1(hThreadSelf); 684 RT_NOREF(hThreadSelf); 685 721 686 LogRel(("Shared clipboard: Starting shared clipboard thread\n")); 722 687 … … 725 690 if (pCtx->fGrabClipboardOnStart) 726 691 clipQueryX11CBFormats(pCtx); 692 727 693 while (XtAppGetExitFlag(pCtx->appContext) == FALSE) 728 694 { … … 730 696 XtAppProcessEvent(pCtx->appContext, XtIMAll); 731 697 } 698 732 699 LogRel(("Shared clipboard: Shared clipboard thread terminated successfully\n")); 733 700 return VINF_SUCCESS; … … 764 731 static void clipStopEventThreadWorker(void *pUserData, void *) 765 732 { 766 767 733 CLIPBACKEND *pCtx = (CLIPBACKEND *)pUserData; 768 734 … … 829 795 #endif 830 796 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. */ 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 */ 833 801 static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *) 834 802 { … … 836 804 char acBuf[WAKE_UP_STRING_LEN]; 837 805 838 LogRel2(("clipDrainWakeupPipe: called\n")); 806 LogRel2(("Shared clipboard: clipDrainWakeupPipe called\n")); 807 839 808 while (read(pCtx->wakeupPipeRead, acBuf, sizeof(acBuf)) > 0) {} 840 809 } 841 810 842 /** X11 specific initialisation for the shared clipboard. 811 /** 812 * X11 specific initialisation for the shared clipboard. 813 * 843 814 * @note X11 backend code. 844 815 */ … … 861 832 if (NULL == pDisplay) 862 833 { 863 LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running .\n"));834 LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running\n")); 864 835 rc = VERR_NOT_SUPPORTED; 865 836 } … … 869 840 rc = clipLoadXFixes(pDisplay, pCtx); 870 841 if (RT_FAILURE(rc)) 871 LogRel(("Shared clipboard: Failed to load the XFIXES extension .\n"));842 LogRel(("Shared clipboard: Failed to load the XFIXES extension\n")); 872 843 } 873 844 #endif … … 880 851 if (NULL == pCtx->widget) 881 852 { 882 LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager .\n"));853 LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager\n")); 883 854 rc = VERR_NO_MEMORY; 884 855 } … … 911 882 rc = RTErrConvertFromErrno(errno); 912 883 if (RT_FAILURE(rc)) 913 LogRel(("Shared clipboard: Failed to setup the termination mechanism .\n"));884 LogRel(("Shared clipboard: Failed to setup the termination mechanism\n")); 914 885 } 915 886 else … … 923 894 924 895 /** 925 * Construct the X11 backend of the shared clipboard. 896 * Constructs the X11 backend of the shared clipboard. 897 * 926 898 * @note X11 backend code 927 899 */ … … 937 909 * This is important for VBoxHeadless. 938 910 */ 939 LogRel Func(("X11 DISPLAY variable not set -- disabling shared clipboard\n"));911 LogRel(("Shared clipboard: X11 DISPLAY variable not set -- disabling Shared Clipboard\n")); 940 912 pCtx->fHaveX11 = false; 941 913 return pCtx; … … 945 917 946 918 LogRel(("Shared clipboard: Initializing X11 clipboard backend\n")); 919 947 920 if (pCtx) 948 921 pCtx->pFrontend = pFrontend; … … 951 924 952 925 /** 953 * Destruct the shared clipboard X11 backend. 926 * Destructs the shared clipboard X11 backend. 927 * 954 928 * @note X11 backend code 955 929 */ … … 965 939 966 940 /** 967 * Announce to the X11 backend that we are ready to start. 941 * Announces to the X11 backend that we are ready to start. 942 * 968 943 * @param grab whether we should try to grab the shared clipboard at once 969 944 */ … … 971 946 { 972 947 int rc = VINF_SUCCESS; 973 LogRelFlowFunc(("\n")); 948 949 LogRel2(("Shared clipboard: Starting\n")); 950 974 951 /* 975 952 * Immediately return if we are not connected to the X server. … … 991 968 if (RT_FAILURE(rc)) 992 969 { 993 LogRel(("Shared clipboard: Failed to start the shared clipboard thread .\n"));970 LogRel(("Shared clipboard: Failed to start the shared clipboard thread, rc=%Rrc\n", rc)); 994 971 clipUninit(pCtx); 995 972 } … … 1000 977 1001 978 /** 1002 * Shut down the shared clipboard X11 backend. 1003 * @note X11 backend code 979 * Shuts down the shared clipboard X11 backend. 980 * 981 * @note X11 backend code. 1004 982 * @note Any requests from this object to get clipboard data from VBox 1005 983 * *must* have completed or aborted before we are called, as … … 1017 995 return VINF_SUCCESS; 1018 996 1019 LogRelFunc(("stopping the shared clipboard X11 backend\n")); 997 LogRel(("Shared clipboard: Stopping X11 backend\n")); 998 1020 999 /* Write to the "stop" pipe */ 1021 1000 clipQueueToEventThread(pCtx, clipStopEventThreadWorker, (XtPointer) pCtx); … … 1035 1014 AssertRC(rcThread); 1036 1015 else 1037 LogRelFunc(("rc=%Rrc\n", rc)); 1016 LogRel(("Shared clipboard: Stopping X11 backend failed with rc=%Rrc\n", rc)); 1017 1038 1018 clipUninit(pCtx); 1039 LogRelFlowFunc(("returning %Rrc.\n", rc)); 1019 1040 1020 RT_NOREF_PV(rcThread); 1041 1021 return rc; … … 1045 1025 * Satisfy a request from X11 for clipboard targets supported by VBox. 1046 1026 * 1047 * @returns iprt status code1048 * @param atomTypeReturn The type of the data we are returning 1027 * @returns IPRT status code. 1028 * @param atomTypeReturn The type of the data we are returning. 1049 1029 * @param pValReturn A pointer to the data we are returning. This 1050 1030 * should be set to memory allocated by XtMalloc, 1051 1031 * which will be freed later by the Xt toolkit. 1052 * @param pcLenReturn The length of the data we are returning 1032 * @param pcLenReturn The length of the data we are returning. 1053 1033 * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are 1054 * returning 1034 * returning. 1035 * 1055 1036 * @note X11 backend code, called by the XtOwnSelection callback. 1056 1037 */ … … 1060 1041 int *piFormatReturn) 1061 1042 { 1062 Atom *atomTargets = (Atom *)XtMalloc( (MAX_CLIP_X11_FORMATS + 3) 1063 * sizeof(Atom)); 1043 Atom *atomTargets = (Atom *)XtMalloc((CLIPX11FORMATIDX_MAX + 3) * sizeof(Atom)); 1064 1044 unsigned cTargets = 0; 1045 1065 1046 LogRelFlowFunc (("called\n")); 1066 CLIPX11FORMAT format = NIL_CLIPX11FORMAT; 1047 1048 CLIPX11FORMATIDX fmtIdx = CLIPX11FORMATIDX_NIL; 1049 1067 1050 do 1068 1051 { 1069 f ormat = clipEnumX11Formats(pCtx->vboxFormats, format);1070 if (f ormat != NIL_CLIPX11FORMAT)1071 { 1072 atomTargets[cTargets] = clip AtomForX11Format(pCtx, format);1052 fmtIdx = clipEnumFmtIdxForVBoxFmt(pCtx->vboxFormats, fmtIdx); 1053 if (fmtIdx != CLIPX11FORMATIDX_NIL) 1054 { 1055 atomTargets[cTargets] = clipGetAtomFromFmtIdx(pCtx, fmtIdx); 1073 1056 ++cTargets; 1074 1057 } 1075 } while (format != NIL_CLIPX11FORMAT); 1058 } while (fmtIdx != CLIPX11FORMATIDX_NIL); 1059 1076 1060 /* We always offer these */ 1077 atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS");1061 atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS"); 1078 1062 atomTargets[cTargets + 1] = clipGetAtom(pCtx, "MULTIPLE"); 1079 1063 atomTargets[cTargets + 2] = clipGetAtom(pCtx, "TIMESTAMP"); 1064 1080 1065 *atomTypeReturn = XA_ATOM; 1081 1066 *pValReturn = (XtPointer)atomTargets; 1082 1067 *pcLenReturn = cTargets + 3; 1083 1068 *piFormatReturn = 32; 1069 1084 1070 return VINF_SUCCESS; 1085 1071 } 1086 1072 1087 /** This is a wrapper around ClipRequestDataForX11 that will cache the 1073 /** 1074 * This is a wrapper around ClipRequestDataForX11 that will cache the 1088 1075 * data returned. 1089 1076 */ 1090 static int clipReadVBoxClipboard(CLIPBACKEND *pCtx, uint32_t u32Format,1077 static int clipReadVBoxClipboard(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMAT vboxFormat, 1091 1078 void **ppv, uint32_t *pcb) 1092 1079 { 1093 1080 int rc = VINF_SUCCESS; 1094 LogRelFlowFunc(("pCtx=%p, u32Format=%02X, ppv=%p, pcb=%p\n", pCtx,1095 u32Format, ppv, pcb));1096 if ( u32Format == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)1081 LogRelFlowFunc(("pCtx=%p, vboxFormat=%02X, ppv=%p, pcb=%p\n", pCtx, 1082 vboxFormat, ppv, pcb)); 1083 if (vboxFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 1097 1084 { 1098 1085 if (pCtx->pvUnicodeCache == NULL) 1099 rc = ClipRequestDataForX11(pCtx->pFrontend, u32Format,1086 rc = ClipRequestDataForX11(pCtx->pFrontend, vboxFormat, 1100 1087 &pCtx->pvUnicodeCache, 1101 1088 &pCtx->cbUnicodeCache); … … 1109 1096 } 1110 1097 else 1111 rc = ClipRequestDataForX11(pCtx->pFrontend, u32Format,1098 rc = ClipRequestDataForX11(pCtx->pFrontend, vboxFormat, 1112 1099 ppv, pcb); 1113 1100 LogRelFlowFunc(("returning %Rrc\n", rc)); … … 1118 1105 1119 1106 /** 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 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. 1124 1112 * @param cwc the size in USC-2 elements of the source text, with or 1125 * without the terminator 1126 * @param pcbActual where to store the buffer size needed 1113 * without the terminator. 1114 * @param pcbActual where to store the buffer size needed. 1127 1115 */ 1128 1116 static int clipWinTxtBufSizeForUtf8(PRTUTF16 pwsz, size_t cwc, … … 1137 1125 1138 1126 /** 1139 * Convert text from Windows format (UCS-2 with CRLF line endings) to standard1127 * Converts text from Windows format (UCS-2 with CRLF line endings) to standard 1140 1128 * Utf-8. 1141 1129 * 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 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. 1148 1135 * @param pcbActual where to store the size of the converted string. 1149 1136 * optional. … … 1179 1166 LogRelFlowFunc(("returning %Rrc\n", rc)); 1180 1167 if (RT_SUCCESS(rc)) 1181 LogRelFlowFunc (("converted string is %.*s. Returning .\n", cbDest,1168 LogRelFlowFunc (("converted string is %.*s. Returning\n", cbDest, 1182 1169 pszBuf)); 1183 1170 return rc; … … 1185 1172 1186 1173 /** 1187 * Satisf ya request from X11 to convert the clipboard text to Utf-8. We1174 * Satisfies a request from X11 to convert the clipboard text to Utf-8. We 1188 1175 * return null-terminated text, but can cope with non-null-terminated input. 1189 1176 * 1190 * @returns iprt status code1177 * @returns IPRT status code. 1191 1178 * @param pDisplay an X11 display structure, needed for conversions 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 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. 1195 1182 * @param atomTypeReturn where to store the atom for the type of the data 1196 * we are returning 1183 * we are returning. 1197 1184 * @param pValReturn where to store the pointer to the data we are 1198 1185 * returning. This should be to memory allocated by … … 1200 1187 * later. 1201 1188 * @param pcLenReturn where to store the length of the data we are 1202 * returning 1189 * returning. 1203 1190 * @param piFormatReturn where to store the bit width (8, 16, 32) of the 1204 * data we are returning 1191 * data we are returning. 1205 1192 */ 1206 1193 static int clipWinTxtToUtf8ForX11CB(Display *pDisplay, PRTUTF16 pwszSrc, … … 1211 1198 int *piFormatReturn) 1212 1199 { 1213 RT_NOREF 2(pDisplay, pcLenReturn);1200 RT_NOREF(pDisplay, pcLenReturn); 1214 1201 1215 1202 /* This may slightly overestimate the space needed. */ … … 1235 1222 1236 1223 /** 1237 * Satisf ya request from X11 to convert the clipboard HTML fragment to Utf-8. We1224 * Satisfies a request from X11 to convert the clipboard HTML fragment to Utf-8. We 1238 1225 * return null-terminated text, but can cope with non-null-terminated input. 1239 1226 * 1240 * @returns iprt status code1227 * @returns IPRT status code. 1241 1228 * @param pDisplay an X11 display structure, needed for conversions 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 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. 1245 1232 * @param atomTypeReturn where to store the atom for the type of the data 1246 * we are returning 1233 * we are returning. 1247 1234 * @param pValReturn where to store the pointer to the data we are 1248 1235 * returning. This should be to memory allocated by … … 1250 1237 * later. 1251 1238 * @param pcLenReturn where to store the length of the data we are 1252 * returning 1239 * returning. 1253 1240 * @param piFormatReturn where to store the bit width (8, 16, 32) of the 1254 * data we are returning 1241 * data we are returning. 1255 1242 */ 1256 1243 static int clipWinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc, … … 1261 1248 int *piFormatReturn) 1262 1249 { 1263 RT_NOREF 2(pDisplay, pValReturn);1250 RT_NOREF(pDisplay, pValReturn); 1264 1251 1265 1252 /* This may slightly overestimate the space needed. */ … … 1280 1267 } 1281 1268 1282 1283 1269 /** 1284 1270 * Does this atom correspond to one of the two selection types we support? 1271 * 1285 1272 * @param widget a valid Xt widget 1286 1273 * @param selType the atom in question … … 1293 1280 1294 1281 /** 1295 * Remove a trailing nul character from a string by adjusting the string1282 * Removes a trailing nul character from a string by adjusting the string 1296 1283 * length. Some X11 applications don't like zero-terminated text... 1284 * 1297 1285 * @param pText the text in question 1298 1286 * @param pcText the length of the text, adjusted on return … … 1300 1288 */ 1301 1289 static void clipTrimTrailingNul(XtPointer pText, unsigned long *pcText, 1302 CLIP FORMAT format)1290 CLIPX11FORMATTARGET format) 1303 1291 { 1304 1292 AssertPtrReturnVoid(pText); 1305 1293 AssertPtrReturnVoid(pcText); 1306 AssertReturnVoid((format == UTF8) || (format == TEXT) || (format == HTML)); 1294 AssertReturnVoid( (format == CLIPX11FORMATTARGET_UTF8) 1295 || (format == CLIPX11FORMATTARGET_TEXT) 1296 || (format == CLIPX11FORMATTARGET_HTML)); 1307 1297 if (((char *)pText)[*pcText - 1] == '\0') 1308 1298 --(*pcText); … … 1316 1306 { 1317 1307 int rc = VINF_SUCCESS; 1318 CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx, *atomTarget); 1319 CLIPFORMAT format = clipRealFormatForX11Format(x11Format); 1320 if ( ((format == UTF8) || (format == TEXT)) 1308 1309 CLIPX11FORMATIDX fmtIdx = clipGetFmtIdxFromAtom(pCtx, *atomTarget); 1310 CLIPX11FORMATTARGET fmtTgt = clipGetTargetFmtFromFmtIdx(fmtIdx); 1311 1312 if ( ((fmtTgt == CLIPX11FORMATTARGET_UTF8) || (fmtTgt == CLIPX11FORMATTARGET_TEXT)) 1321 1313 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)) 1322 1314 { 1323 1315 void *pv = NULL; 1324 1316 uint32_t cb = 0; 1325 rc = clipReadVBoxClipboard(pCtx, 1326 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, 1327 &pv, &cb); 1317 rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pv, &cb); 1328 1318 if (RT_SUCCESS(rc) && (cb == 0)) 1329 1319 rc = VERR_NO_DATA; 1330 if (RT_SUCCESS(rc) && ((format == UTF8) || (format == TEXT))) 1320 1321 if (RT_SUCCESS(rc) && ( (fmtTgt == CLIPX11FORMATTARGET_UTF8) 1322 || (fmtTgt == CLIPX11FORMATTARGET_TEXT))) 1323 { 1331 1324 rc = clipWinTxtToUtf8ForX11CB(XtDisplay(pCtx->widget), 1332 1325 (PRTUTF16)pv, cb, atomTarget, 1333 1326 atomTypeReturn, pValReturn, 1334 1327 pcLenReturn, piFormatReturn); 1328 } 1329 1335 1330 if (RT_SUCCESS(rc)) 1336 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format); 1331 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtTgt); 1332 1337 1333 RTMemFree(pv); 1338 1334 } 1339 else if ( (f ormat ==BMP)1335 else if ( (fmtTgt == CLIPX11FORMATTARGET_BMP) 1340 1336 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)) 1341 1337 { 1342 1338 void *pv = NULL; 1343 1339 uint32_t cb = 0; 1344 rc = clipReadVBoxClipboard(pCtx, 1345 VBOX_SHARED_CLIPBOARD_FMT_BITMAP, 1346 &pv, &cb); 1340 rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, &pv, &cb); 1347 1341 if (RT_SUCCESS(rc) && (cb == 0)) 1348 1342 rc = VERR_NO_DATA; 1349 if (RT_SUCCESS(rc) && (format == BMP)) 1350 { 1351 /* Create a full BMP from it */ 1343 1344 if (RT_SUCCESS(rc) && (fmtTgt == CLIPX11FORMATTARGET_BMP)) 1345 { 1346 /* Create a full BMP from it. */ 1352 1347 rc = vboxClipboardDibToBmp(pv, cb, (void **)pValReturn, 1353 1348 (size_t *)pcLenReturn); … … 1361 1356 *piFormatReturn = 8; 1362 1357 } 1358 1363 1359 RTMemFree(pv); 1364 1360 } 1365 else if ( (format ==HTML)1366 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_HTML))1361 else if ( (fmtTgt == CLIPX11FORMATTARGET_HTML) 1362 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_HTML)) 1367 1363 { 1368 1364 void *pv = NULL; 1369 1365 uint32_t cb = 0; 1370 rc = clipReadVBoxClipboard(pCtx, 1371 VBOX_SHARED_CLIPBOARD_FMT_HTML, 1372 &pv, &cb); 1366 rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_HTML, &pv, &cb); 1373 1367 if (RT_SUCCESS(rc) && (cb == 0)) 1374 1368 rc = VERR_NO_DATA; 1369 1375 1370 if (RT_SUCCESS(rc)) 1376 1371 { … … 1384 1379 */ 1385 1380 rc = clipWinHTMLToUtf8ForX11CB(XtDisplay(pCtx->widget), 1386 (const char*)pv, cb, atomTarget, 1387 atomTypeReturn, pValReturn, 1388 pcLenReturn, piFormatReturn); 1389 1390 1381 (const char*)pv, cb, atomTarget, 1382 atomTypeReturn, pValReturn, 1383 pcLenReturn, piFormatReturn); 1391 1384 if (RT_SUCCESS(rc)) 1392 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format); 1385 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtTgt); 1386 1393 1387 RTMemFree(pv); 1394 1388 } 1395 1389 } 1390 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 1391 else if ( (fmtTgt == CLIPX11FORMATTARGET_URI_LIST) 1392 && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)) 1393 { 1394 /** Nothing to do here yet. */ 1395 } 1396 #endif 1396 1397 else 1397 1398 rc = VERR_NOT_SUPPORTED; … … 1400 1401 1401 1402 /** 1402 * Return VBox's clipboard data for an X11 client. 1403 * @note X11 backend code, callback for XtOwnSelection 1403 * Returns VBox's clipboard data for an X11 client. 1404 * 1405 * @note X11 backend code, callback for XtOwnSelection. 1404 1406 */ 1405 1407 static Boolean clipXtConvertSelectionProc(Widget widget, Atom *atomSelection, … … 1434 1436 CLIPBACKEND *pCtx; 1435 1437 /** Formats supported by VBox */ 1436 uint32_t formats;1438 VBOXCLIPBOARDFORMATS vboxFormats; 1437 1439 } CLIPNEWVBOXFORMATS; 1438 1440 … … 1448 1450 1449 1451 /** 1450 * Take possession of the X11 clipboard (and middle-button selection).1451 */ 1452 static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats)1452 * Takes possession of the X11 clipboard (and middle-button selection). 1453 */ 1454 static void clipGrabX11CB(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMATS vboxFormats) 1453 1455 { 1454 1456 if (XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1455 1457 CurrentTime, clipXtConvertSelectionProc, NULL, 0)) 1456 1458 { 1457 pCtx->vboxFormats = u32Formats; 1459 pCtx->vboxFormats = vboxFormats; 1460 1458 1461 /* Grab the middle-button paste selection too. */ 1459 1462 XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "PRIMARY"), … … 1475 1478 * Worker function for ClipAnnounceFormatToX11 which runs on the 1476 1479 * event thread. 1480 * 1477 1481 * @param pUserData Pointer to a CLIPNEWVBOXFORMATS structure containing 1478 1482 * information about the VBox formats available and the 1479 1483 * clipboard context data. Must be freed by the worker. 1480 1484 */ 1481 static void clipNewVBoxFormatsWorker(void *pUserData, 1482 void * /* interval */) 1485 static void clipNewVBoxFormatsWorker(void *pUserData, void * /* interval */) 1483 1486 { 1484 1487 CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData; 1488 1485 1489 CLIPBACKEND *pCtx = pFormats->pCtx; 1486 uint32_t u32Formats = pFormats->formats; 1490 VBOXCLIPBOARDFORMAT vboxFormat = pFormats->vboxFormats; 1491 1487 1492 RTMemFree(pFormats); 1488 LogRelFlowFunc (("u32Formats=%d\n", u32Formats)); 1493 1494 LogRelFlowFunc (("vboxFormat=%RU32\n", vboxFormat)); 1495 1489 1496 clipInvalidateVBoxCBCache(pCtx); 1490 clipGrabX11CB(pCtx, u32Formats);1497 clipGrabX11CB(pCtx, vboxFormat); 1491 1498 clipResetX11Formats(pCtx); 1499 1492 1500 LogRelFlowFunc(("returning\n")); 1493 1501 } … … 1496 1504 * VBox is taking possession of the shared clipboard. 1497 1505 * 1498 * @param u32Formats Clipboard formats that VBox is offering1506 * @param vboxFormats Clipboard formats that VBox is offering 1499 1507 * @note X11 backend code 1500 1508 */ 1501 void ClipAnnounceFormatToX11(CLIPBACKEND *pCtx, 1502 uint32_t u32Formats) 1509 int ClipAnnounceFormatToX11(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMATS vboxFormats) 1503 1510 { 1504 1511 /* … … 1506 1513 */ 1507 1514 if (!pCtx->fHaveX11) 1508 return; 1515 return VINF_SUCCESS; 1516 1517 int rc; 1518 1509 1519 /* This must be freed by the worker callback */ 1510 1520 CLIPNEWVBOXFORMATS *pFormats = 1511 1521 (CLIPNEWVBOXFORMATS *) RTMemAlloc(sizeof(CLIPNEWVBOXFORMATS)); 1522 1512 1523 if (pFormats != NULL) /* if it is we will soon have other problems */ 1513 1524 { 1514 1525 pFormats->pCtx = pCtx; 1515 pFormats-> formats = u32Formats;1526 pFormats->vboxFormats = vboxFormats; 1516 1527 clipQueueToEventThread(pCtx, clipNewVBoxFormatsWorker, 1517 1528 (XtPointer) pFormats); 1518 } 1519 } 1520 1521 /** 1522 * Massage generic Utf16 with CR end-of-lines into the format Windows expects 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 1523 1539 * and return the result in a RTMemAlloc allocated buffer. 1524 * @returns IPRT status code 1525 * @param pwcSrc The source Utf16 1540 * 1541 * @returns IPRT status code. 1542 * @param pwcSrc The source Utf16. 1526 1543 * @param cwcSrc The number of 16bit elements in @a pwcSrc, not counting 1527 * the terminating zero 1528 * @param ppwszDest Where to store the buffer address 1544 * the terminating zero. 1545 * @param ppwszDest Where to store the buffer address. 1529 1546 * @param pcbDest On success, where to store the number of bytes written. 1530 * Undefined otherwise. Optional 1547 * Undefined otherwise. Optional. 1531 1548 */ 1532 1549 static int clipUtf16ToWinTxt(RTUTF16 *pwcSrc, size_t cwcSrc, … … 1567 1584 1568 1585 /** 1569 * Convert Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it1586 * Converts Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it 1570 1587 * and return the result in a RTMemAlloc allocated buffer. 1571 * @returns IPRT status code 1572 * @param pcSrc The source Utf-8 1588 * 1589 * @returns IPRT status code. 1590 * @param pcSrc The source Utf-8. 1573 1591 * @param cbSrc The size of the source in bytes, not counting the 1574 * terminating zero 1575 * @param ppwszDest Where to store the buffer address 1592 * terminating zero. 1593 * @param ppwszDest Where to store the buffer address. 1576 1594 * @param pcbDest On success, where to store the number of bytes written. 1577 * Undefined otherwise. Optional 1595 * Undefined otherwise. Optional. 1578 1596 */ 1579 1597 static int clipUtf8ToWinTxt(const char *pcSrc, unsigned cbSrc, … … 1600 1618 1601 1619 /** 1602 * Convert Latin-1 text with CR end-of-lines into Utf-16 as Windows expects1620 * Converts Latin-1 text with CR end-of-lines into Utf-16 as Windows expects 1603 1621 * it and return the result in a RTMemAlloc allocated buffer. 1604 * @returns IPRT status code 1605 * @param pcSrc The source text 1622 * 1623 * @returns IPRT status code. 1624 * @param pcSrc The source text. 1606 1625 * @param cbSrc The size of the source in bytes, not counting the 1607 * terminating zero 1608 * @param ppwszDest Where to store the buffer address 1626 * terminating zero. 1627 * @param ppwszDest Where to store the buffer address. 1609 1628 * @param pcbDest On success, where to store the number of bytes written. 1610 * Undefined otherwise. Optional 1629 * Undefined otherwise. Optional. 1611 1630 */ 1612 1631 static int clipLatin1ToWinTxt(char *pcSrc, unsigned cbSrc, … … 1662 1681 1663 1682 /** 1664 * Convert Utf16 text into UTF8 as Windows expects 1665 * it and return the result in a RTMemAlloc allocated buffer. 1666 * @returns IPRT status code 1667 * @param pcSrc The source text 1668 * @param cbSrc The size of the source in bytes, not counting the 1669 * terminating zero 1670 * @param ppwszDest Where to store the buffer address 1671 * @param pcbDest On success, where to store the number of bytes written. 1672 * Undefined otherwise. Optional 1673 */ 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 */ 1674 1694 int clipUTF16ToWinHTML(RTUTF16 *pwcBuf, size_t cb, char **ppszOut, uint32_t *pcOut) 1675 1695 { … … 1732 1752 } 1733 1753 1734 1735 1736 1754 /** A structure containing information about where to store a request 1737 1755 * for the X11 clipboard contents. */ 1738 1756 struct _CLIPREADX11CBREQ 1739 1757 { 1758 /** @todo r=andy Why all those different CLIPX11FORMAT members? Shouldn't be one enough? */ 1759 1740 1760 /** The format VBox would like the data in */ 1741 uint32_tmFormat;1761 VBOXCLIPBOARDFORMAT mFormat; 1742 1762 /** The text format we requested from X11 if we requested text */ 1743 CLIPX11FORMAT mTextFormat;1763 CLIPX11FORMATIDX mTextFmtIdx; 1744 1764 /** The bitmap format we requested from X11 if we requested bitmap */ 1745 CLIPX11FORMAT mBitmapFormat;1765 CLIPX11FORMATIDX mBitmapFmtIdx; 1746 1766 /** The HTML format we requested from X11 if we requested HTML */ 1747 CLIPX11FORMAT mHtmlFormat; 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 1748 1772 /** The clipboard context this request is associated with */ 1749 1773 CLIPBACKEND *mCtx; … … 1755 1779 1756 1780 /** 1757 * Convert the data obtained from the X11 clipboard to the required format,1781 * Converts the data obtained from the X11 clipboard to the required format, 1758 1782 * place it in the buffer supplied and signal that data has arrived. 1759 1783 * Convert the text obtained UTF-16LE with Windows EOLs. 1760 1784 * Convert full BMP data to DIB format. 1785 * 1761 1786 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1762 1787 * the X11 clipboard contains a format we understand. 1763 1788 */ 1764 static void clipConvertX11CB(void *p ClientData, void *pvSrc, unsigned cbSrc)1765 { 1766 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) p ClientData;1789 static void clipConvertX11CB(void *pSvcCtxData, void *pvSrc, unsigned cbSrc) 1790 { 1791 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pSvcCtxData; 1767 1792 LogRelFlowFunc(("pReq->mFormat=%02X, pReq->mTextFormat=%u, " 1768 1793 "pReq->mBitmapFormat=%u, pReq->mHtmlFormat=%u, pReq->mCtx=%p\n", 1769 pReq->mFormat, pReq->mTextF ormat, pReq->mBitmapFormat,1770 pReq->mHtmlF ormat, pReq->mCtx));1794 pReq->mFormat, pReq->mTextFmtIdx, pReq->mBitmapFmtIdx, 1795 pReq->mHtmlFmtIdx, pReq->mCtx)); 1771 1796 AssertPtr(pReq->mCtx); 1772 1797 Assert(pReq->mFormat != 0); /* sanity */ … … 1789 1814 { 1790 1815 /* In which format is the clipboard data? */ 1791 switch (clip RealFormatForX11Format(pReq->mTextFormat))1792 { 1793 case UTF8:1794 case TEXT:1816 switch (clipGetTargetFmtFromFmtIdx(pReq->mTextFmtIdx)) 1817 { 1818 case CLIPX11FORMATTARGET_UTF8: 1819 case CLIPX11FORMATTARGET_TEXT: 1795 1820 { 1796 1821 /* If we are given broken Utf-8, we treat it as Latin1. Is … … 1812 1837 { 1813 1838 /* In which format is the clipboard data? */ 1814 switch (clip RealFormatForX11Format(pReq->mBitmapFormat))1815 { 1816 case BMP:1839 switch (clipGetTargetFmtFromFmtIdx(pReq->mBitmapFmtIdx)) 1840 { 1841 case CLIPX11FORMATTARGET_BMP: 1817 1842 { 1818 1843 const void *pDib; … … 1840 1865 { 1841 1866 /* In which format is the clipboard data? */ 1842 switch (clip RealFormatForX11Format(pReq->mHtmlFormat))1843 { 1844 case HTML:1867 switch (clipGetTargetFmtFromFmtIdx(pReq->mHtmlFmtIdx)) 1868 { 1869 case CLIPX11FORMATTARGET_HTML: 1845 1870 { 1846 1871 /* The common VBox HTML encoding will be - Utf8 … … 1889 1914 } 1890 1915 } 1916 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 1917 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 1918 { 1919 // @todo 1920 } 1921 #endif 1891 1922 else 1892 1923 rc = VERR_NOT_IMPLEMENTED; … … 1900 1931 #ifndef TESTCASE 1901 1932 /** 1902 * Convert the data obtained from the X11 clipboard to the required format,1933 * Converts the data obtained from the X11 clipboard to the required format, 1903 1934 * place it in the buffer supplied and signal that data has arrived. 1904 1935 * Convert the text obtained UTF-16LE with Windows EOLs. 1905 1936 * Convert full BMP data to DIB format. 1937 * 1906 1938 * @note X11 backend code, callback for XtGetSelectionValue, for use when 1907 1939 * the X11 clipboard contains a format we understand. 1908 1940 */ 1909 static void cbConvertX11CB(Widget widget, XtPointer p ClientData,1941 static void cbConvertX11CB(Widget widget, XtPointer pSvcCtxData, 1910 1942 Atom * /* selection */, Atom *atomType, 1911 1943 XtPointer pvSrc, long unsigned int *pcLen, 1912 1944 int *piFormat) 1913 1945 { 1914 RT_NOREF 1(widget);1946 RT_NOREF(widget); 1915 1947 if (*atomType == XT_CONVERT_FAIL) /* Xt timeout */ 1916 clipConvertX11CB(p ClientData, NULL, 0);1948 clipConvertX11CB(pSvcCtxData, NULL, 0); 1917 1949 else 1918 clipConvertX11CB(p ClientData, pvSrc, (*pcLen) * (*piFormat) / 8);1950 clipConvertX11CB(pSvcCtxData, pvSrc, (*pcLen) * (*piFormat) / 8); 1919 1951 1920 1952 XtFree((char *)pvSrc); … … 1923 1955 1924 1956 #ifdef TESTCASE 1925 static void testRequestData(CLIPBACKEND* pCtx, CLIPX11FORMAT target,1957 static void testRequestData(CLIPBACKEND* pCtx, CLIPX11FORMATTARGET target, 1926 1958 void *closure); 1927 1959 #endif 1928 1960 1929 static void getSelectionValue(CLIPBACKEND *pCtx, CLIPX11FORMAT format,1961 static void getSelectionValue(CLIPBACKEND *pCtx, CLIPX11FORMATIDX format, 1930 1962 CLIPREADX11CBREQ *pReq) 1931 1963 { 1932 1964 #ifndef TESTCASE 1933 1965 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1934 clip AtomForX11Format(pCtx, format),1966 clipGetAtomFromFmtIdx(pCtx, format), 1935 1967 cbConvertX11CB, 1936 1968 reinterpret_cast<XtPointer>(pReq), … … 1943 1975 /** Worker function for ClipRequestDataFromX11 which runs on the event 1944 1976 * thread. */ 1945 static void vboxClipboardReadX11Worker(void *pUserData, 1946 void * /* interval */) 1977 static void vboxClipboardReadX11Worker(void *pUserData, void * /* interval */) 1947 1978 { 1948 1979 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *)pUserData; … … 1955 1986 pCtx->fBusy = true; 1956 1987 if (fBusy) 1988 { 1957 1989 /* If the clipboard is busy just fend off the request. */ 1958 1990 rc = VERR_TRY_AGAIN; 1991 } 1959 1992 else 1960 1993 #endif … … 1964 1997 * VBox wants to read data in the given format. 1965 1998 */ 1966 pReq->mTextFormat = pCtx->X11TextFormat; 1967 if (pReq->mTextFormat == INVALID) 1999 pReq->mTextFmtIdx = pCtx->X11TextFmtIdx; 2000 if (pReq->mTextFmtIdx == CLIPX11FORMATIDX_NIL) 2001 { 1968 2002 /* VBox thinks we have data and we don't */ 1969 2003 rc = VERR_NO_DATA; 2004 } 2005 else 2006 { 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 else 2020 { 2021 /* Send out a request for the data to the current clipboard 2022 * 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 } 1970 2035 else 1971 2036 /* Send out a request for the data to the current clipboard 1972 2037 * owner */ 1973 getSelectionValue(pCtx, pCtx->X11TextFormat, pReq); 1974 } 1975 else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 1976 { 1977 pReq->mBitmapFormat = pCtx->X11BitmapFormat; 1978 if (pReq->mBitmapFormat == INVALID) 1979 /* VBox thinks we have data and we don't */ 1980 rc = VERR_NO_DATA; 1981 else 1982 /* Send out a request for the data to the current clipboard 1983 * owner */ 1984 getSelectionValue(pCtx, pCtx->X11BitmapFormat, pReq); 1985 } 1986 else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_HTML) 1987 { 1988 /* Send out a request for the data to the current clipboard 1989 * owner */ 1990 pReq->mHtmlFormat = pCtx->X11HTMLFormat; 1991 if(pReq->mHtmlFormat == INVALID) 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 { 1992 2047 /* VBox thinks we have data and we don't */ 1993 2048 rc = VERR_NO_DATA; 2049 } 1994 2050 else 1995 /* Send out a request for the data to the current clipboard 1996 * owner */ 1997 getSelectionValue(pCtx, pCtx->X11HTMLFormat, pReq); 1998 } 2051 { 2052 /* Send out a request for the data to the current clipboard owner */ 2053 getSelectionValue(pCtx, pCtx->X11HTMLFmtIdx, pReq); 2054 } 2055 } 2056 #endif 1999 2057 else 2000 2058 { … … 2004 2062 #endif 2005 2063 } 2064 2006 2065 if (RT_FAILURE(rc)) 2007 2066 { … … 2012 2071 RTMemFree(pReq); 2013 2072 } 2073 2014 2074 LogRelFlowFunc(("status %Rrc\n", rc)); 2015 2075 } … … 2018 2078 * Called when VBox wants to read the X11 clipboard. 2019 2079 * 2020 * @returns iprt status code2021 * @param pCtx Context data for the clipboard backend 2022 * @param u32Format The format that the VBox would like to receive the data2023 * in2024 * @param pv Where to write the data to2025 * @param cb The size of the buffer to write the data to2026 * @param pcbActual Where to write the actual size of the written data2027 * @note We allocate a request structure which must be freed by the worker 2028 */ 2029 int ClipRequestDataFromX11(CLIPBACKEND *pCtx, uint32_t u32Format,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, 2030 2090 CLIPREADCBREQ *pReq) 2031 2091 { … … 2042 2102 else 2043 2103 { 2044 pX11Req->mFormat = u32Format;2104 pX11Req->mFormat = vboxFormat; 2045 2105 pX11Req->mCtx = pCtx; 2046 2106 pX11Req->mReq = pReq; … … 2116 2176 2117 2177 /* Return the data in the simulated VBox clipboard. */ 2118 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb)2119 { 2120 RT_NOREF 2(pCtx, u32Format);2178 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, VBOXCLIPBOARDFORMAT vboxFormat, void **ppv, uint32_t *pcb) 2179 { 2180 RT_NOREF(pCtx, vboxFormat); 2121 2181 *pcb = g_vboxDatacb; 2122 2182 if (g_vboxDatapv != NULL) … … 2131 2191 2132 2192 Display *XtDisplay(Widget w) 2133 { NOREF(w); return (Display *) 0xffff; }2134 2135 void XtAppSetExitFlag(XtAppContext app_context) { NOREF(app_context); }2136 2137 void XtDestroyWidget(Widget w) { NOREF(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); } 2138 2198 2139 2199 XtAppContext XtCreateApplicationContext(void) { return (XtAppContext)0xffff; } 2140 2200 2141 void XtDestroyApplicationContext(XtAppContext app_context) { NOREF(app_context); }2201 void XtDestroyApplicationContext(XtAppContext app_context) { RT_NOREF(app_context); } 2142 2202 2143 2203 void XtToolkitInitialize(void) {} … … 2163 2223 } 2164 2224 2165 void XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed) { RT_NOREF 2(widget, mapped_when_managed); }2166 2167 void XtRealizeWidget(Widget widget) { NOREF(widget); }2225 void XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed) { RT_NOREF(widget, mapped_when_managed); } 2226 2227 void XtRealizeWidget(Widget widget) { RT_NOREF(widget); } 2168 2228 2169 2229 XtInputId XtAppAddInput(XtAppContext app_context, int source, XtPointer condition, XtInputCallbackProc proc, XtPointer closure) … … 2212 2272 void testRequestData(CLIPBACKEND *pCtx, CLIPX11FORMAT target, void *closure) 2213 2273 { 2214 RT_NOREF 1(pCtx);2274 RT_NOREF(pCtx); 2215 2275 unsigned long count = 0; 2216 2276 int format = 0; … … 2239 2299 void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats) 2240 2300 { 2241 RT_NOREF 1(pCtx);2301 RT_NOREF(pCtx); 2242 2302 g_fX11Formats = u32Formats; 2243 2303 } … … 2268 2328 XtSelectionDoneProc done) 2269 2329 { 2270 RT_NOREF 2(widget, time);2330 RT_NOREF(widget, time); 2271 2331 if (selection != XInternAtom(NULL, "CLIPBOARD", 0)) 2272 2332 return True; /* We don't really care about this. */ … … 2319 2379 { 2320 2380 Atom clipAtom = XInternAtom(NULL, "CLIPBOARD", 0); 2321 g_selTargets[0] = clip FindX11FormatByAtomText(pcszTarget);2381 g_selTargets[0] = clipGetFmtIdxFromAtomText(pcszTarget); 2322 2382 g_cTargets = 1; 2323 2383 g_selType = type; … … 2345 2405 char *XGetAtomName(Display *display, Atom atom) 2346 2406 { 2347 RT_NOREF 1(display);2407 RT_NOREF(display); 2348 2408 AssertReturn((unsigned)atom < RT_ELEMENTS(g_aFormats) + 1, NULL); 2349 2409 const char *pcszName = NULL; … … 2387 2447 void ClipCompleteDataRequestFromX11(VBOXCLIPBOARDCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb) 2388 2448 { 2389 RT_NOREF 1(pCtx);2449 RT_NOREF(pCtx); 2390 2450 if (cb <= MAX_BUF_SIZE) 2391 2451 { … … 2540 2600 static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx, const char *pcszTarget, Atom typeExp, const char *valueExp) 2541 2601 { 2542 RT_NOREF 1(pCtx);2602 RT_NOREF(pCtx); 2543 2603 bool retval = false; 2544 2604 Atom type; … … 2581 2641 static void testStringFromVBoxFailed(RTTEST hTest, CLIPBACKEND *pCtx, const char *pcszTarget) 2582 2642 { 2583 RT_NOREF 1(pCtx);2643 RT_NOREF(pCtx); 2584 2644 Atom type; 2585 2645 XtPointer value = NULL; … … 2596 2656 static void testNoSelectionOwnership(CLIPBACKEND *pCtx, const char *pcszTestCtx) 2597 2657 { 2598 RT_NOREF 1(pCtx);2658 RT_NOREF(pCtx); 2599 2659 RTTESTI_CHECK_MSG(!g_ownsSel, ("context: %s\n", pcszTestCtx)); 2600 2660 } … … 2622 2682 clipSendTargetUpdate(pCtx); 2623 2683 if (clipQueryFormats() == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 2624 RTTestFailed(hTest, "Failed to report targets after bad host request .\n");2684 RTTestFailed(hTest, "Failed to report targets after bad host request\n"); 2625 2685 } 2626 2686 } … … 2889 2949 void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats) 2890 2950 { 2891 RT_NOREF 2(pCtx, u32Formats);2951 RT_NOREF(pCtx, u32Formats); 2892 2952 } 2893 2953 -
trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard.h
r78580 r78581 49 49 struct { 50 50 VBOXHGCMCALLHANDLE callHandle; 51 VBOXHGCMSVCPARM *paParms;51 VBOXHGCMSVCPARM *paParms; 52 52 } async; 53 53 54 54 struct { 55 55 VBOXHGCMCALLHANDLE callHandle; 56 VBOXHGCMSVCPARM *paParms;56 VBOXHGCMSVCPARM *paParms; 57 57 } asyncRead; 58 58 -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp
r78580 r78581 507 507 } 508 508 509 void ClipAnnounceFormatToX11(CLIPBACKEND *pBackend, uint32_t u32Formats)510 { 511 pBackend->formats = u32Formats;512 } 513 514 extern int ClipRequestDataFromX11(CLIPBACKEND *pBackend, uint32_t u32Format,509 void ClipAnnounceFormatToX11(CLIPBACKEND *pBackend, VBOXCLIPBOARDFORMATS vboxFormats) 510 { 511 pBackend->formats = vboxFormats; 512 } 513 514 extern int ClipRequestDataFromX11(CLIPBACKEND *pBackend, VBOXCLIPBOARDFORMAT vboxFormat, 515 515 CLIPREADCBREQ *pReq) 516 516 { 517 pBackend->readData.format = u32Format;517 pBackend->readData.format = vboxFormat; 518 518 pBackend->readData.pReq = pReq; 519 519 return pBackend->readData.rc; -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp
r78580 r78581 513 513 uint32_t u32Formats; 514 514 515 rc = VBoxHGCMParmUInt32Get 515 rc = VBoxHGCMParmUInt32Get(&paParms[0], &u32Formats); 516 516 517 517 if (RT_SUCCESS (rc)) … … 562 562 uint32_t cb; 563 563 564 rc = VBoxHGCMParmUInt32Get 564 rc = VBoxHGCMParmUInt32Get(&paParms[0], &u32Format); 565 565 566 566 if (RT_SUCCESS (rc)) 567 567 { 568 rc = VBoxHGCMParmPtrGet 568 rc = VBoxHGCMParmPtrGet(&paParms[1], &pv, &cb); 569 569 570 570 if (RT_SUCCESS (rc)) … … 629 629 else if (RT_SUCCESS (rc)) 630 630 { 631 VBoxHGCMParmUInt32Set 631 VBoxHGCMParmUInt32Set(&paParms[2], cbActual); 632 632 } 633 633 } … … 657 657 uint32_t u32Format; 658 658 659 rc = VBoxHGCMParmUInt32Get 659 rc = VBoxHGCMParmUInt32Get(&paParms[0], &u32Format); 660 660 661 661 if (RT_SUCCESS (rc)) 662 662 { 663 rc = VBoxHGCMParmPtrGet 663 rc = VBoxHGCMParmPtrGet(&paParms[1], &pv, &cb); 664 664 665 665 if (RT_SUCCESS (rc))
Note:
See TracChangeset
for help on using the changeset viewer.