VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDDropSource.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: VBoxDnDDropSource.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxDnDSource.cpp - IDropSource implementation.
4 */
5
6/*
7 * Copyright (C) 2013-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28#include <iprt/win/windows.h>
29#include <new> /* For bad_alloc. */
30
31#ifdef LOG_GROUP
32# undef LOG_GROUP
33#endif
34#define LOG_GROUP LOG_GROUP_GUEST_DND
35#include <VBox/log.h>
36
37#include "VBoxTray.h"
38#include "VBoxHelpers.h"
39#include "VBoxDnD.h"
40
41#include "VBox/HostServices/DragAndDropSvc.h"
42
43
44
45VBoxDnDDropSource::VBoxDnDDropSource(VBoxDnDWnd *pParent)
46 : m_cRefs(1),
47 m_pWndParent(pParent),
48 m_dwCurEffect(0),
49 m_enmActionCurrent(VBOX_DND_ACTION_IGNORE)
50{
51 LogFlowFuncEnter();
52}
53
54VBoxDnDDropSource::~VBoxDnDDropSource(void)
55{
56 LogFlowFunc(("mRefCount=%RI32\n", m_cRefs));
57}
58
59/*
60 * IUnknown methods.
61 */
62
63STDMETHODIMP_(ULONG) VBoxDnDDropSource::AddRef(void)
64{
65 return InterlockedIncrement(&m_cRefs);
66}
67
68STDMETHODIMP_(ULONG) VBoxDnDDropSource::Release(void)
69{
70 LONG lCount = InterlockedDecrement(&m_cRefs);
71 if (lCount == 0)
72 {
73 delete this;
74 return 0;
75 }
76
77 return lCount;
78}
79
80STDMETHODIMP 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 */
106STDMETHODIMP VBoxDnDDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD dwKeyState)
107{
108#if 1
109 LogFlowFunc(("fEscapePressed=%RTbool, dwKeyState=0x%x, mdwCurEffect=%RI32, mDnDActionCurrent=%RU32\n",
110 fEscapePressed, dwKeyState, m_dwCurEffect, m_enmActionCurrent));
111#endif
112
113 /* ESC pressed? Bail out. */
114 if (fEscapePressed)
115 {
116 m_dwCurEffect = 0;
117 m_enmActionCurrent = VBOX_DND_ACTION_IGNORE;
118
119 LogFlowFunc(("Canceled\n"));
120 return DRAGDROP_S_CANCEL;
121 }
122
123 /* Left mouse button released? Start "drop" action. */
124 if ((dwKeyState & MK_LBUTTON) == 0)
125 {
126 LogFlowFunc(("Dropping ...\n"));
127 return DRAGDROP_S_DROP;
128 }
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 */
140STDMETHODIMP VBoxDnDDropSource::GiveFeedback(DWORD dwEffect)
141{
142 uint32_t uAction = VBOX_DND_ACTION_IGNORE;
143
144#if 1
145 LogFlowFunc(("dwEffect=0x%x\n", dwEffect));
146#endif
147 if (dwEffect)
148 {
149 if (dwEffect & DROPEFFECT_COPY)
150 uAction |= VBOX_DND_ACTION_COPY;
151 if (dwEffect & DROPEFFECT_MOVE)
152 uAction |= VBOX_DND_ACTION_MOVE;
153 if (dwEffect & DROPEFFECT_LINK)
154 uAction |= VBOX_DND_ACTION_LINK;
155 }
156
157 m_dwCurEffect = dwEffect;
158 m_enmActionCurrent = uAction;
159
160 return DRAGDROP_S_USEDEFAULTCURSORS;
161}
162
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use