[49947] | 1 | /* $Id: VBoxDnDDropSource.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VBoxDnDSource.cpp - IDropSource implementation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2013-2023 Oracle and/or its affiliates.
|
---|
[49947] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[49947] | 26 | */
|
---|
[69361] | 27 |
|
---|
[62679] | 28 | #include <iprt/win/windows.h>
|
---|
[49947] | 29 | #include <new> /* For bad_alloc. */
|
---|
| 30 |
|
---|
[51469] | 31 | #ifdef LOG_GROUP
|
---|
| 32 | # undef LOG_GROUP
|
---|
| 33 | #endif
|
---|
| 34 | #define LOG_GROUP LOG_GROUP_GUEST_DND
|
---|
| 35 | #include <VBox/log.h>
|
---|
| 36 |
|
---|
[49947] | 37 | #include "VBoxTray.h"
|
---|
| 38 | #include "VBoxHelpers.h"
|
---|
| 39 | #include "VBoxDnD.h"
|
---|
| 40 |
|
---|
| 41 | #include "VBox/HostServices/DragAndDropSvc.h"
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | VBoxDnDDropSource::VBoxDnDDropSource(VBoxDnDWnd *pParent)
|
---|
[85694] | 46 | : m_cRefs(1),
|
---|
| 47 | m_pWndParent(pParent),
|
---|
| 48 | m_dwCurEffect(0),
|
---|
| 49 | m_enmActionCurrent(VBOX_DND_ACTION_IGNORE)
|
---|
[49947] | 50 | {
|
---|
[58336] | 51 | LogFlowFuncEnter();
|
---|
[49947] | 52 | }
|
---|
| 53 |
|
---|
| 54 | VBoxDnDDropSource::~VBoxDnDDropSource(void)
|
---|
| 55 | {
|
---|
[85694] | 56 | LogFlowFunc(("mRefCount=%RI32\n", m_cRefs));
|
---|
[49947] | 57 | }
|
---|
| 58 |
|
---|
| 59 | /*
|
---|
| 60 | * IUnknown methods.
|
---|
| 61 | */
|
---|
| 62 |
|
---|
| 63 | STDMETHODIMP_(ULONG) VBoxDnDDropSource::AddRef(void)
|
---|
| 64 | {
|
---|
[85694] | 65 | return InterlockedIncrement(&m_cRefs);
|
---|
[49947] | 66 | }
|
---|
| 67 |
|
---|
| 68 | STDMETHODIMP_(ULONG) VBoxDnDDropSource::Release(void)
|
---|
| 69 | {
|
---|
[85694] | 70 | LONG lCount = InterlockedDecrement(&m_cRefs);
|
---|
[49947] | 71 | if (lCount == 0)
|
---|
| 72 | {
|
---|
| 73 | delete this;
|
---|
| 74 | return 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | return lCount;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | STDMETHODIMP VBoxDnDDropSource::QueryInterface(REFIID iid, void **ppvObject)
|
---|
| 81 | {
|
---|
| 82 | AssertPtrReturn(ppvObject, E_INVALIDARG);
|
---|
| 83 |
|
---|
| 84 | if ( iid == IID_IDropSource
|
---|
| 85 | || iid == IID_IUnknown)
|
---|
| 86 | {
|
---|
| 87 | AddRef();
|
---|
| 88 | *ppvObject = this;
|
---|
| 89 | return S_OK;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | *ppvObject = 0;
|
---|
| 93 | return E_NOINTERFACE;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /*
|
---|
| 97 | * IDropSource methods.
|
---|
| 98 | */
|
---|
| 99 |
|
---|
| 100 | /**
|
---|
| 101 | * The system informs us about whether we should continue the drag'n drop
|
---|
| 102 | * operation or not, depending on the sent key states.
|
---|
| 103 | *
|
---|
| 104 | * @return HRESULT
|
---|
| 105 | */
|
---|
| 106 | STDMETHODIMP VBoxDnDDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD dwKeyState)
|
---|
| 107 | {
|
---|
[51476] | 108 | #if 1
|
---|
[74442] | 109 | LogFlowFunc(("fEscapePressed=%RTbool, dwKeyState=0x%x, mdwCurEffect=%RI32, mDnDActionCurrent=%RU32\n",
|
---|
[85694] | 110 | fEscapePressed, dwKeyState, m_dwCurEffect, m_enmActionCurrent));
|
---|
[49947] | 111 | #endif
|
---|
| 112 |
|
---|
| 113 | /* ESC pressed? Bail out. */
|
---|
| 114 | if (fEscapePressed)
|
---|
| 115 | {
|
---|
[85694] | 116 | m_dwCurEffect = 0;
|
---|
| 117 | m_enmActionCurrent = VBOX_DND_ACTION_IGNORE;
|
---|
[49947] | 118 |
|
---|
[51476] | 119 | LogFlowFunc(("Canceled\n"));
|
---|
[49947] | 120 | return DRAGDROP_S_CANCEL;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /* Left mouse button released? Start "drop" action. */
|
---|
| 124 | if ((dwKeyState & MK_LBUTTON) == 0)
|
---|
[51476] | 125 | {
|
---|
| 126 | LogFlowFunc(("Dropping ...\n"));
|
---|
[49947] | 127 | return DRAGDROP_S_DROP;
|
---|
[51476] | 128 | }
|
---|
[49947] | 129 |
|
---|
| 130 | /* No change, just continue. */
|
---|
| 131 | return S_OK;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /**
|
---|
| 135 | * The drop target gives our source feedback about whether
|
---|
| 136 | * it can handle our data or not.
|
---|
| 137 | *
|
---|
| 138 | * @return HRESULT
|
---|
| 139 | */
|
---|
| 140 | STDMETHODIMP VBoxDnDDropSource::GiveFeedback(DWORD dwEffect)
|
---|
| 141 | {
|
---|
[74411] | 142 | uint32_t uAction = VBOX_DND_ACTION_IGNORE;
|
---|
[49947] | 143 |
|
---|
[51476] | 144 | #if 1
|
---|
[49947] | 145 | LogFlowFunc(("dwEffect=0x%x\n", dwEffect));
|
---|
| 146 | #endif
|
---|
| 147 | if (dwEffect)
|
---|
| 148 | {
|
---|
| 149 | if (dwEffect & DROPEFFECT_COPY)
|
---|
[74411] | 150 | uAction |= VBOX_DND_ACTION_COPY;
|
---|
[49947] | 151 | if (dwEffect & DROPEFFECT_MOVE)
|
---|
[74411] | 152 | uAction |= VBOX_DND_ACTION_MOVE;
|
---|
[49947] | 153 | if (dwEffect & DROPEFFECT_LINK)
|
---|
[74411] | 154 | uAction |= VBOX_DND_ACTION_LINK;
|
---|
[49947] | 155 | }
|
---|
| 156 |
|
---|
[85694] | 157 | m_dwCurEffect = dwEffect;
|
---|
| 158 | m_enmActionCurrent = uAction;
|
---|
[49947] | 159 |
|
---|
| 160 | return DRAGDROP_S_USEDEFAULTCURSORS;
|
---|
| 161 | }
|
---|
| 162 |
|
---|