VirtualBox

Ignore:
Timestamp:
Oct 10, 2019 12:22:34 PM (5 years ago)
Author:
vboxsync
Message:

Shared Clipboard/Transfers: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp

    r81134 r81212  
    154154    if (enmDir == SHCLTRANSFERDIR_WRITE)
    155155    {
    156         Assert(SharedClipboardTransferGetSource(pTransfer) == SHCLSOURCE_LOCAL); /* Sanity. */
    157 
    158         rc = SharedClipboardWinOpen(pCtx->Win.hWnd);
    159         if (RT_SUCCESS(rc))
    160         {
    161             /* The data data in CF_HDROP format, as the files are locally present and don't need to be
    162              * presented as a IDataObject or IStream. */
    163             HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
    164             if (hClip)
    165             {
    166                 HDROP hDrop = (HDROP)GlobalLock(hClip);
    167                 if (hDrop)
    168                 {
    169                     char    *papszList = NULL;
    170                     uint32_t cbList;
    171                     rc = SharedClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
    172 
    173                     GlobalUnlock(hClip);
    174 
    175                     if (RT_SUCCESS(rc))
    176                     {
    177                         rc = SharedClipboardTransferRootsSet(pTransfer,
    178                                                              papszList, cbList + 1 /* Include termination */);
    179                         RTStrFree(papszList);
    180                     }
    181                 }
    182                 else
    183                     LogRel(("Shared Clipboard: Unable to lock clipboard data, last error: %ld\n", GetLastError()));
    184             }
    185             else
    186                 LogRel(("Shared Clipboard: Unable to retrieve clipboard data from clipboard (CF_HDROP), last error: %ld\n",
    187                         GetLastError()));
    188 
    189             SharedClipboardWinClose();
    190         }
     156        rc = SharedClipboardWinGetRoots(&pCtx->Win, pTransfer);
    191157    }
    192158    /* The guest wants to read data from a remote source. */
    193159    else if (enmDir == SHCLTRANSFERDIR_READ)
    194160    {
    195         Assert(SharedClipboardTransferGetSource(pTransfer) == SHCLSOURCE_REMOTE); /* Sanity. */
    196 
    197         rc = SharedClipboardWinTransferCreate(&pCtx->Win, pTransfer);
     161        /* The IDataObject *must* be created on the same thread as our (proxy) window, so post a message to it
     162         * to do the stuff for us. */
     163        const SHCLEVENTID uEvent = SharedClipboardEventIDGenerate(&pTransfer->Events);
     164
     165        rc = SharedClipboardEventRegister(&pTransfer->Events, uEvent);
     166        if (RT_SUCCESS(rc))
     167        {
     168            /* Don't want to rely on SendMessage (synchronous) here, so just post and wait the event getting signalled. */
     169            ::PostMessage(pCtx->Win.hWnd, SHCL_WIN_WM_TRANSFER_START, (WPARAM)pTransfer, (LPARAM)uEvent);
     170
     171            PSHCLEVENTPAYLOAD pPayload;
     172            rc = SharedClipboardEventWait(&pTransfer->Events, uEvent, 30 * 1000 /* Timeout in ms */, &pPayload);
     173            if (RT_SUCCESS(rc))
     174            {
     175                Assert(pPayload->cbData == sizeof(int));
     176                rc = *(int *)pPayload->pvData;
     177
     178                SharedClipboardPayloadFree(pPayload);
     179            }
     180
     181            SharedClipboardEventUnregister(&pTransfer->Events, uEvent);
     182        }
    198183    }
    199184    else
    200185        AssertFailedStmt(rc = VERR_NOT_SUPPORTED);
     186
     187    if (RT_FAILURE(rc))
     188        LogRel(("Shared Clipboard: Starting transfer failed, rc=%Rrc\n", rc));
    201189
    202190    LogFlowFunc(("LEAVE: idTransfer=%RU16, rc=%Rrc\n", SharedClipboardTransferGetID(pTransfer), rc));
     
    651639        }
    652640
    653 #if 0
    654641        case SHCL_WIN_WM_TRANSFER_START:
    655642        {
    656643            LogFunc(("SHCL_WIN_WM_TRANSFER_START\n"));
    657644
    658             PSHCLTRANSFER pTransfer = (PSHCLTRANSFER)lParam;
     645            PSHCLTRANSFER pTransfer  = (PSHCLTRANSFER)wParam;
    659646            AssertPtr(pTransfer);
    660647
     648            const SHCLEVENTID uEvent = (SHCLEVENTID)lParam;
     649
    661650            Assert(SharedClipboardTransferGetSource(pTransfer) == SHCLSOURCE_REMOTE); /* Sanity. */
    662651
    663             int rc2 = SharedClipboardWinTransferCreate(pWinCtx, pTransfer);
    664             AssertRC(rc2);
    665             break;
    666         }
    667 #endif
     652            int rcTransfer = SharedClipboardWinTransferCreate(pWinCtx, pTransfer);
     653
     654            PSHCLEVENTPAYLOAD pPayload = NULL;
     655            int rc = SharedClipboardPayloadAlloc(uEvent, &rcTransfer, sizeof(rcTransfer), &pPayload);
     656            if (RT_SUCCESS(rc))
     657            {
     658                rc = SharedClipboardEventSignal(&pTransfer->Events, uEvent, pPayload);
     659                if (RT_FAILURE(rc))
     660                    SharedClipboardPayloadFree(pPayload);
     661            }
     662
     663            break;
     664        }
    668665
    669666        case WM_DESTROY:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette