VirtualBox

Changeset 79174 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Jun 17, 2019 10:30:49 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131345
Message:

Shared Clipboard/URI: Update.

File:
1 edited

Legend:

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

    r79107 r79174  
    8383#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    8484static DECLCALLBACK(void) vboxClipboardOnURITransferComplete(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc);
     85static DECLCALLBACK(void) vboxClipboardOnURITransferError(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc);
    8586#endif
    8687
     
    9899       case WM_CLIPBOARDUPDATE:
    99100       {
    100            if (GetClipboardOwner() != hwnd)
    101            {
    102                /* Clipboard was updated by another application.
     101            const HWND hWndClipboardOwner = GetClipboardOwner();
     102            if (pWinCtx->hWndClipboardOwnerUs != hWndClipboardOwner)
     103            {
     104                LogFunc(("WM_CLIPBOARDUPDATE: hWndOldClipboardOwner=%p, hWndNewClipboardOwner=%p\n",
     105                         pWinCtx->hWndClipboardOwnerUs, hWndClipboardOwner));
     106
     107                /* Clipboard was updated by another application.
    103108                * Report available formats to the host. */
    104109               VBOXCLIPBOARDFORMATS fFormats;
    105110               int rc = VBoxClipboardWinGetFormats(&pCtx->Win, &fFormats);
    106111               if (RT_SUCCESS(rc))
     112               {
     113                   LogFunc(("WM_CLIPBOARDUPDATE: Reporting formats 0x%x\n", fFormats));
    107114                   rc = VbglR3ClipboardReportFormats(pCtx->u32ClientID, fFormats);
    108 
    109                LogFunc(("WM_CLIPBOARDUPDATE: rc=%Rrc, fFormats=0x%x\n", rc, fFormats));
    110            }
    111            else
    112                LogFlowFunc(("WM_CLIPBOARDUPDATE: No change (VBoxTray is owner)\n"));
     115               }
     116            }
    113117       }
    114118       break;
     
    116120       case WM_CHANGECBCHAIN:
    117121       {
    118            if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI))
    119            {
    120                lresultRc = DefWindowProc(hwnd, msg, wParam, lParam);
    121                break;
    122            }
    123 
    124            HWND hWndRemoved = (HWND)wParam;
    125            HWND hWndNext    = (HWND)lParam;
    126 
    127            LogFlowFunc(("WM_CHANGECBCHAIN: hWndRemoved=%p, hWndNext=%p, hWnd=%p\n", hWndRemoved, hWndNext, pWinCtx->hWnd));
    128 
    129            if (hWndRemoved == pWinCtx->hWndNextInChain)
    130            {
    131                /* The window that was next to our in the chain is being removed.
    132                 * Relink to the new next window. */
    133                pWinCtx->hWndNextInChain = hWndNext;
    134            }
    135            else
    136            {
    137                if (pWinCtx->hWndNextInChain)
    138                {
    139                    /* Pass the message further. */
    140                    DWORD_PTR dwResult;
    141                    lresultRc = SendMessageTimeout(pWinCtx->hWndNextInChain, WM_CHANGECBCHAIN, wParam, lParam, 0,
    142                                                   VBOX_CLIPBOARD_CBCHAIN_TIMEOUT_MS, &dwResult);
    143                    if (!lresultRc)
    144                        lresultRc = (LRESULT)dwResult;
    145                }
    146            }
     122           LogFunc(("WM_CHANGECBCHAIN\n"));
     123           lresultRc = VBoxClipboardWinHandleWMChangeCBChain(pWinCtx, hwnd, msg, wParam, lParam);
    147124       }
    148125       break;
     
    162139           }
    163140
    164            if (pWinCtx->hWndNextInChain)
    165            {
    166                /* Pass the message to next windows in the clipboard chain. */
    167                SendMessageTimeout(pWinCtx->hWndNextInChain, msg, wParam, lParam, 0, VBOX_CLIPBOARD_CBCHAIN_TIMEOUT_MS, NULL);
    168            }
     141           lresultRc = VBoxClipboardWinChainPassToNext(pWinCtx, msg, wParam, lParam);
    169142       }
    170143       break;
     
    172145       case WM_TIMER:
    173146       {
    174            if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI))
    175                break;
    176 
    177            HWND hViewer = GetClipboardViewer();
    178 
    179            /* Re-register ourselves in the clipboard chain if our last ping
    180            * timed out or there seems to be no valid chain. */
    181            if (!hViewer || pWinCtx->oldAPI.fCBChainPingInProcess)
    182            {
    183                VBoxClipboardWinRemoveFromCBChain(pWinCtx);
    184                VBoxClipboardWinAddToCBChain(pWinCtx);
    185            }
    186 
    187            /* Start a new ping by passing a dummy WM_CHANGECBCHAIN to be
    188            * processed by ourselves to the chain. */
    189            pWinCtx->oldAPI.fCBChainPingInProcess = TRUE;
    190 
    191            hViewer = GetClipboardViewer();
    192            if (hViewer)
    193                SendMessageCallback(hViewer, WM_CHANGECBCHAIN, (WPARAM)pWinCtx->hWndNextInChain, (LPARAM)pWinCtx->hWndNextInChain,
    194                                    VBoxClipboardWinChainPingProc, (ULONG_PTR)pWinCtx);
     147            int rc = VBoxClipboardWinHandleWMTimer(pWinCtx);
     148            AssertRC(rc);
    195149       }
    196150       break;
     
    353307       case WM_RENDERALLFORMATS:
    354308       {
    355            /* Do nothing. The clipboard formats will be unavailable now, because the
    356            * windows is to be destroyed and therefore the guest side becomes inactive.
    357            */
    358            int rc = VBoxClipboardWinOpen(hwnd);
    359            if (RT_SUCCESS(rc))
    360            {
    361                VBoxClipboardWinClear();
    362                VBoxClipboardWinClose();
    363            }
     309           LogFunc(("WM_RENDERALLFORMATS\n"));
     310
     311           int rc = VBoxClipboardWinHandleWMRenderAllFormats(pWinCtx, hwnd);
     312           AssertRC(rc);
    364313       }
    365314       break;
     
    367316       case VBOX_CLIPBOARD_WM_SET_FORMATS:
    368317       {
    369             /* Announce available formats. Do not insert data, they will be inserted in WM_RENDER*. */
     318            /* Announce available formats. Do not insert data -- will be inserted in WM_RENDERFORMAT. */
    370319            VBOXCLIPBOARDFORMATS fFormats = (uint32_t)lParam;
    371 
    372             int rc = VBoxClipboardWinOpen(hwnd);
    373             if (RT_SUCCESS(rc))
     320            if (fFormats != VBOX_SHARED_CLIPBOARD_FMT_NONE) /* Could arrive with some older GA versions. */
    374321            {
    375                 VBoxClipboardWinClear();
    376 
    377                 rc = VBoxClipboardWinHandleWMSetFormats(pWinCtx, fFormats);
    378                 if (rc == VERR_NOT_SUPPORTED)
     322                int rc = VBoxClipboardWinOpen(hwnd);
     323                if (RT_SUCCESS(rc))
    379324                {
    380 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    381                     SHAREDCLIPBOARDPROVIDERCREATIONCTX providerCtx;
    382                     RT_ZERO(providerCtx);
    383                     providerCtx.enmSource = SHAREDCLIPBOARDPROVIDERSOURCE_VBGLR3;
    384                     providerCtx.u.VBGLR3.uClientID = pCtx->u32ClientID;
    385 
    386                     rc = VBoxClipboardWinURIHandleWMSetFormats(pWinCtx, &pCtx->URI, &providerCtx, fFormats);
    387 #endif
    388                     if (rc == VERR_NOT_SUPPORTED)
    389                         LogRel(("Clipboard: Unsupported format(s) (0x%x), skipping\n", fFormats));
     325                    VBoxClipboardWinClear();
     326
     327#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
     328                    if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)
     329                    {
     330                        LogFunc(("VBOX_SHARED_CLIPBOARD_FMT_URI_LIST\n"));
     331
     332                        SHAREDCLIPBOARDPROVIDERCREATIONCTX providerCtx;
     333                        RT_ZERO(providerCtx);
     334                        providerCtx.enmSource = SHAREDCLIPBOARDPROVIDERSOURCE_VBGLR3;
     335                        providerCtx.u.VbglR3.uClientID = pCtx->u32ClientID;
     336
     337                        rc = VBoxClipboardWinURIReadMain(pWinCtx, &pCtx->URI, &providerCtx, fFormats);
     338
     339                        /* Note: VBoxClipboardWinURIReadMain() takes care of closing the clipboard. */
     340                    }
     341                    else
     342                    {
     343#endif
     344                        rc = VBoxClipboardWinAnnounceFormats(pWinCtx, fFormats);
     345
     346                        VBoxClipboardWinClose();
     347#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
     348                    }
     349#endif
    390350                }
    391 
    392                 if (RT_FAILURE(rc))
    393                     LogFunc(("Failed with %Rrc\n", rc));
    394 
    395                 VBoxClipboardWinClose();
    396 
    397                 LogFunc(("VBOX_CLIPBOARD_WM_SET_FORMATS: fFormats=0x%x, lastErr=%ld\n", fFormats, GetLastError()));
    398351            }
     352            LogFunc(("VBOX_CLIPBOARD_WM_SET_FORMATS: fFormats=0x%x, lastErr=%ld\n", fFormats, GetLastError()));
    399353        }
    400354        break;
     
    482436                       RT_ZERO(creationCtx);
    483437                       creationCtx.enmSource = SHAREDCLIPBOARDPROVIDERSOURCE_VBGLR3;
    484                        creationCtx.u.VBGLR3.uClientID = pCtx->u32ClientID;
     438                       creationCtx.u.VbglR3.uClientID = pCtx->u32ClientID;
    485439
    486440                       PSHAREDCLIPBOARDURITRANSFER pTransfer;
     
    493447                           TransferCallbacks.pvUser              = &pCtx->URI;
    494448                           TransferCallbacks.pfnTransferComplete = vboxClipboardOnURITransferComplete;
     449                           TransferCallbacks.pfnTransferError    = vboxClipboardOnURITransferError;
    495450
    496451                           SharedClipboardURITransferSetCallbacks(pTransfer, &TransferCallbacks);
     
    511466                                       rc = VBoxClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &pszList, &cbList);
    512467                                       if (RT_SUCCESS(rc))
     468                                       {
    513469                                           rc = SharedClipboardURITransferMetaDataAdd(pTransfer, pszList, (uint32_t)cbList);
     470                                           RTMemFree(pszList);
     471                                       }
    514472
    515473                                       GlobalUnlock(hClip);
    516474
    517475                                       if (RT_SUCCESS(rc))
    518                                            rc = SharedClipboardURITransferRun(pTransfer, true /* fAsync */);
     476                                       {
     477                                           rc = SharedClipboardURITransferMetaDataComplete(pTransfer);
     478                                           if (RT_SUCCESS(rc))
     479                                               rc = SharedClipboardURITransferRun(pTransfer, true /* fAsync */);
     480                                       }
    519481                                   }
    520482                                   else
     
    543505                   /* Requested clipboard format is not available, send empty data. */
    544506                   VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_NONE, NULL, 0);
     507#ifdef DEBUG_andy
     508                   AssertFailed();
     509#endif
    545510               }
    546511
     
    552517       case WM_DESTROY:
    553518       {
    554            VBoxClipboardWinRemoveFromCBChain(pWinCtx);
    555            if (pWinCtx->oldAPI.timerRefresh)
    556                KillTimer(pWinCtx->hWnd, 0);
     519           LogFunc(("WM_DESTROY\n"));
     520
     521           int rc = VBoxClipboardWinHandleWMDestroy(pWinCtx);
     522           AssertRC(rc);
     523
    557524           /*
    558            * don't need to call PostQuitMessage cause
    559            * the VBoxTray already finished a message loop
    560            */
     525            * Don't need to call PostQuitMessage cause
     526            * the VBoxTray already finished a message loop.
     527            */
    561528       }
    562529       break;
     
    564531       default:
    565532       {
     533           LogFunc(("WM_ %p\n", msg));
    566534           lresultRc = DefWindowProc(hwnd, msg, wParam, lParam);
    567535       }
     
    569537    }
    570538
    571 #ifndef DEBUG_andy
    572     LogFlowFunc(("vboxClipboardProcessMsg returned with lresultRc=%ld\n", lresultRc));
    573 #endif
     539    LogFunc(("WM_ rc %d\n", lresultRc));
    574540    return lresultRc;
    575541}
     
    622588                         SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
    623589
    624             VBoxClipboardWinAddToCBChain(pWinCtx);
     590            VBoxClipboardWinChainAdd(pWinCtx);
    625591            if (!VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI))
    626592                pWinCtx->oldAPI.timerRefresh = SetTimer(pWinCtx->hWnd, 0, 10 * 1000 /* 10s */, NULL);
     
    638604
    639605    LogFlowFunc(("pData=%p, rc=%Rrc\n", pData, rc));
     606
     607    LogRel(("Shared Clipboard: Transfer to destination complete"));
     608
     609    PSHAREDCLIPBOARDURICTX pCtx = (PSHAREDCLIPBOARDURICTX)pData->pvUser;
     610    AssertPtr(pCtx);
     611
     612    PSHAREDCLIPBOARDURITRANSFER pTransfer = pData->pTransfer;
     613    AssertPtr(pTransfer);
     614
     615    if (pTransfer->pvUser) /* SharedClipboardWinURITransferCtx */
     616    {
     617        delete pTransfer->pvUser;
     618        pTransfer->pvUser = NULL;
     619    }
     620
     621    int rc2 = SharedClipboardURICtxTransferRemove(pCtx, pTransfer);
     622    AssertRC(rc2);
     623}
     624
     625static DECLCALLBACK(void) vboxClipboardOnURITransferError(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc)
     626{
     627    RT_NOREF(rc);
     628
     629    LogFlowFunc(("pData=%p, rc=%Rrc\n", pData, rc));
     630
     631    LogRel(("Shared Clipboard: Transfer to destination failed with %Rrc\n", rc));
    640632
    641633    PSHAREDCLIPBOARDURICTX pCtx = (PSHAREDCLIPBOARDURICTX)pData->pvUser;
     
    764756    for (;;)
    765757    {
     758        LogFlowFunc(("Waiting for host message ...\n"));
     759
    766760        uint32_t u32Msg;
    767761        uint32_t u32Formats;
     
    788782               case VBOX_SHARED_CLIPBOARD_HOST_MSG_REPORT_FORMATS:
    789783               {
     784                   LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_REPORT_FORMATS\n"));
     785
    790786                   /* The host has announced available clipboard formats.
    791787                    * Forward the information to the window, so it can later
     
    797793               case VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA:
    798794               {
     795                   LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA\n"));
     796
    799797                   /* The host needs data in the specified format. */
    800798                   ::PostMessage(pWinCtx->hWnd, VBOX_CLIPBOARD_WM_READ_DATA, 0, u32Formats);
     
    804802               case VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT:
    805803               {
     804                   LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT\n"));
     805
    806806                   /* The host is terminating. */
    807807                   LogRel(("Clipboard: Terminating ...\n"));
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