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