VirtualBox

Ignore:
Timestamp:
Jan 23, 2014 11:51:09 AM (11 years ago)
Author:
vboxsync
Message:

DnD/VBoxTray: Update.

File:
1 edited

Legend:

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

    r50101 r50177  
    146146    {
    147147        DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
    148         DWORD dwStyle = WS_POPUPWINDOW;
     148        DWORD dwStyle = WS_POPUP;
    149149#ifdef VBOX_DND_DEBUG_WND
    150         dwExStyle &= ~WS_EX_TRANSPARENT;
    151         dwStyle |= WS_VISIBLE | WS_OVERLAPPEDWINDOW;
     150        dwExStyle &= ~WS_EX_TRANSPARENT; /* Remove transparency bit. */
     151        dwStyle |= WS_VISIBLE; /* Make the window visible. */
    152152#endif
    153153        pThis->hWnd =
     
    176176#else
    177177            LogFlowFunc(("Debug proxy window created, hWnd=0x%x\n", pThis->hWnd));
     178
     179            /*
     180             * Install some mouse tracking.
     181             */
     182            TRACKMOUSEEVENT me;
     183            RT_ZERO(me);
     184            me.cbSize    = sizeof(TRACKMOUSEEVENT);
     185            me.dwFlags   = TME_HOVER | TME_LEAVE | TME_NONCLIENT;
     186            me.hwndTrack = pThis->hWnd;
     187            BOOL fRc = TrackMouseEvent(&me);
     188            Assert(fRc);
    178189#endif
    179190        }
     
    183194    {
    184195        OleInitialize(NULL);
     196
     197        pThis->RegisterAsDropTarget();
    185198
    186199        bool fShutdown = false;
     
    269282            LogFlowThisFunc(("WM_LBUTTONUP\n"));
    270283            mfMouseButtonDown = false;
     284            return 0;
     285
     286        case WM_MOUSELEAVE:
     287            LogFlowThisFunc(("WM_MOUSELEAVE\n"));
    271288            return 0;
    272289
     
    341358            else if (mMode == GH) /* Guest to host. */
    342359            {
    343                 hide();
     360                //hide();
     361
     362                /* Starting here VBoxDnDDropTarget should
     363                 * take over; was instantiated when registering
     364                 * this proxy window as a (valid) drop target. */
    344365            }
    345366            else
     
    350371            return 0;
    351372        }
     373
     374        case WM_NCMOUSEHOVER:
     375            LogFlowThisFunc(("WM_NCMOUSEHOVER\n"));
     376            return 0;
     377
     378        case WM_NCMOUSELEAVE:
     379            LogFlowThisFunc(("WM_NCMOUSELEAVE\n"));
     380            return 0;
    352381
    353382        case WM_VBOXTRAY_DND_MESSAGE:
     
    532561        return VINF_SUCCESS;
    533562
    534     int rc = VBoxDnDDropTarget::CreateDropTarget(this /* pParent */,
    535                                                  &pDropTarget);
    536     if (RT_SUCCESS(rc))
    537     {
     563    int rc;
     564    try
     565    {
     566        pDropTarget = new VBoxDnDDropTarget(this /* pParent */);
    538567        AssertPtr(pDropTarget);
    539568        HRESULT hr = CoLockObjectExternal(pDropTarget, TRUE /* fLock */,
     
    544573        if (FAILED(hr))
    545574        {
    546             LogRel(("DnD: Creating drop target failed with hr=0x%x\n", hr));
     575            LogRel(("DnD: Creating drop target failed with hr=%Rhrc\n", hr));
    547576            rc = VERR_GENERAL_FAILURE; /** @todo Find a better rc. */
    548577        }
     578        else
     579            rc = VINF_SUCCESS;
     580    }
     581    catch (std::bad_alloc)
     582    {
     583        rc = VERR_NO_MEMORY;
    549584    }
    550585
     
    707742        rc = VbglR3DnDHGAcknowledgeOperation(mClientID, uActionNotify);
    708743        if (RT_FAILURE(rc))
    709             LogFlowThisFunc(("Acknowleding operation failed with rc=%Rrc\n", rc));
     744            LogFlowThisFunc(("Acknowledging operation failed with rc=%Rrc\n", rc));
    710745    }
    711746
     
    828863    if (mState == Initialized)
    829864    {
    830         //rc = makeFullscreen();
    831         rc = VINF_SUCCESS;
     865        rc = makeFullscreen();
     866        /*if (RT_SUCCESS(rc))
     867            rc = RegisterAsDropTarget();*/
     868
    832869        if (RT_SUCCESS(rc))
    833             rc = RegisterAsDropTarget();
    834 
    835         if (RT_SUCCESS(rc))
     870        {
     871            /*
     872             * We have to release the left mouse button to
     873             * get into our (invisible) proxy window.
     874             */
     875            dragRelease();
     876
     877            /*
     878             * Even if we just released the left mouse button
     879             * we're still in the dragging state to handle our
     880             * own drop target (for the host).
     881             */
    836882            mState = Dragging;
     883        }
    837884    }
    838885    else
    839886        rc = VINF_SUCCESS;
     887
     888    /**
     889     * Some notes regarding guest cursor movement:
     890     * - The host only sends an HOST_DND_GH_REQ_PENDING message to the guest
     891     *   if the mouse cursor is outside the VM's window.
     892     * - The guest does not know anything about the host's cursor
     893     *   position / state due to security reasons.
     894     * - The guest *only* knows that the host currently is asking whether a
     895     *   guest DnD operation is in progress.
     896     */
    840897
    841898    if (   RT_SUCCESS(rc)
     
    845902        POINT p;
    846903        GetCursorPos(&p);
    847 
     904        ClientToScreen(hWnd, &p);
    848905#ifdef DEBUG_andy
    849         LogFlowThisFunc(("Setting cursor to curX=%d, curY=%d\n", p.x, p.y));
    850 #endif
     906        LogFlowThisFunc(("Client to screen curX=%ld, curY=%ld\n", p.x, p.y));
     907#endif
     908
     909#if 1
    851910        /** @todo Multi-monitor setups? */
    852911        int iScreenX = GetSystemMetrics(SM_CXSCREEN) - 1;
    853912        int iScreenY = GetSystemMetrics(SM_CYSCREEN) - 1;
    854913
    855         static int pos = 100;
    856         pos++;
     914        static LONG px = p.x;
     915        if (px <= 0)
     916            px = 1;
     917        static LONG py = p.y;
     918        if (py <= 0)
     919            py = 1;
     920        //px++; py++;
     921        LogFlowThisFunc(("px=%ld, py=%ld\n", px, py));
    857922
    858923        INPUT Input[1] = { 0 };
    859924        Input[0].type       = INPUT_MOUSE;
    860         Input[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
    861         Input[0].mi.dx      = pos * (65535 / iScreenX); //p.x * (65535 / iScreenX);
    862         Input[0].mi.dy      = 100 * (65535 / iScreenY); //p.y * (65535 / iScreenY);
    863         SendInput(1, Input, sizeof(INPUT));
     925        Input[0].mi.dwFlags = MOUSEEVENTF_MOVE | /*MOUSEEVENTF_LEFTDOWN |*/ MOUSEEVENTF_ABSOLUTE;
     926        Input[0].mi.dx      = px * (65535 / iScreenX);
     927        Input[0].mi.dy      = py * (65535 / iScreenY);
     928        UINT uiProcessed = SendInput(1, Input, sizeof(INPUT));
     929        if (uiProcessed)
     930        {
     931#ifdef DEBUG_andy
     932            LogFlowFunc(("Sent %RU16 mouse input(s), x=%ld, y=%ld, flags=0x%x\n",
     933                         uiProcessed, Input[0].mi.dx, Input[0].mi.dy, Input[0].mi.dwFlags));
     934#endif
     935        }
     936        else
     937            LogFlowFunc(("Unable to send input, error=0x%x\n", GetLastError()));
     938#else
     939        SetCursorPos(p.x, p.y);
     940#endif
    864941
    865942#ifdef DEBUG_andy
     
    875952    }
    876953
    877     int rc2= VbglR3DnDGHAcknowledgePending(mClientID,
    878                                            DND_COPY_ACTION, DND_COPY_ACTION, "text/plain;charset=utf-8");
    879     LogFlowThisFunc(("sent=%Rrc\n", rc2));
     954    if (RT_SUCCESS(rc))
     955    {
     956        uint32_t uDefAction = DND_IGNORE_ACTION;
     957        RTCString strFormat = "unknown";
     958        if (   pDropTarget
     959            && pDropTarget->HasData())
     960        {
     961            uDefAction = DND_COPY_ACTION;
     962            uAllActions = uDefAction;
     963            strFormat = "text/plain;charset=utf-8";
     964        }
     965
     966        LogFlowFunc(("Acknowledging pDropTarget=0x%p, uDefAction=0x%x, uAllActions=0x%x, strFormat=%s\n",
     967                     pDropTarget, uDefAction, uAllActions, strFormat.c_str()));
     968        rc = VbglR3DnDGHAcknowledgePending(mClientID,
     969                                           uDefAction, uAllActions, strFormat.c_str());
     970    }
    880971
    881972    LogFlowFuncLeaveRC(rc);
     
    888979    LogFlowThisFunc(("mMode=%ld, mState=%ld, cbFormats=%RU32, uDefAction=0x%x\n",
    889980                     mMode, mState, cbFormats, uDefAction));
    890 
    891981    int rc;
    892982    if (mState == Dragging)
    893983    {
     984        AssertPtr(pDropTarget);
    894985    }
    895986    else
     
    9131004int VBoxDnDWnd::dragRelease(void)
    9141005{
     1006#ifdef DEBUG_andy
     1007    LogFlowFunc(("\n"));
     1008#endif
    9151009    /* Release mouse button in the guest to start the "drop"
    9161010     * action at the current mouse cursor position. */
     
    9251019int VBoxDnDWnd::hide(void)
    9261020{
     1021#ifdef DEBUG_andy
     1022    LogFlowFunc(("\n"));
     1023#endif
    9271024    ShowWindow(hWnd, SW_HIDE);
    9281025
     
    9671064    if (RT_SUCCESS(rc))
    9681065    {
     1066        LONG lStyle = GetWindowLong(hWnd, GWL_STYLE);
     1067        SetWindowLong(hWnd, GWL_STYLE,
     1068                      lStyle & ~(WS_CAPTION | WS_THICKFRAME));
     1069        LONG lExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
     1070        SetWindowLong(hWnd, GWL_EXSTYLE,
     1071                      lExStyle & ~(  WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE
     1072                                   | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
     1073
    9691074        fRc = SetWindowPos(hWnd, HWND_TOPMOST,
    9701075                           r.left,
     
    9731078                           r.bottom - r.top,
    9741079#ifdef VBOX_DND_DEBUG_WND
    975                            SWP_SHOWWINDOW);
     1080                           SWP_SHOWWINDOW | SWP_FRAMECHANGED);
    9761081#else
    9771082                           SWP_SHOWWINDOW | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
    9781083#endif
    9791084        if (fRc)
     1085        {
    9801086            LogFlowFunc(("Virtual screen is %ld,%ld,%ld,%ld (%ld x %ld)\n",
    9811087                         r.left, r.top, r.right, r.bottom,
    9821088                         r.right - r.left, r.bottom - r.top));
     1089        }
    9831090        else
    9841091        {
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