VirtualBox

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

Last change on this file since 53517 was 51476, checked in by vboxsync, 11 years ago

DnD: API overhaul; now using IDnDTarget + IDnDSource. Renamed DragAndDrop* enumerations to DnD*. Also rewrote some internal code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: VBoxDnDDropSource.cpp 51476 2014-05-30 14:58:02Z vboxsync $ */
2/** @file
3 * VBoxDnDSource.cpp - IDropSource implementation.
4 */
5
6/*
7 * Copyright (C) 2013-2014 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#include <windows.h>
18#include <new> /* For bad_alloc. */
19
20#ifdef LOG_GROUP
21# undef LOG_GROUP
22#endif
23#define LOG_GROUP LOG_GROUP_GUEST_DND
24#include <VBox/log.h>
25
26#include "VBoxTray.h"
27#include "VBoxHelpers.h"
28#include "VBoxDnD.h"
29
30#include "VBox/HostServices/DragAndDropSvc.h"
31
32
33
34VBoxDnDDropSource::VBoxDnDDropSource(VBoxDnDWnd *pParent)
35 : mRefCount(1),
36 mpWndParent(pParent),
37 mClientID(UINT32_MAX),
38 mdwCurEffect(0),
39 muCurAction(DND_IGNORE_ACTION)
40{
41 int rc = VbglR3DnDConnect(&mClientID);
42
43 LogFlowFunc(("rc=%Rrc\n", rc));
44}
45
46VBoxDnDDropSource::~VBoxDnDDropSource(void)
47{
48 int rc = VbglR3DnDDisconnect(mClientID);
49
50 LogFlowFunc(("rc=%Rrc, mRefCount=%RI32\n", rc, mRefCount));
51}
52
53/*
54 * IUnknown methods.
55 */
56
57STDMETHODIMP_(ULONG) VBoxDnDDropSource::AddRef(void)
58{
59 return InterlockedIncrement(&mRefCount);
60}
61
62STDMETHODIMP_(ULONG) VBoxDnDDropSource::Release(void)
63{
64 LONG lCount = InterlockedDecrement(&mRefCount);
65 if (lCount == 0)
66 {
67 delete this;
68 return 0;
69 }
70
71 return lCount;
72}
73
74STDMETHODIMP VBoxDnDDropSource::QueryInterface(REFIID iid, void **ppvObject)
75{
76 AssertPtrReturn(ppvObject, E_INVALIDARG);
77
78 if ( iid == IID_IDropSource
79 || iid == IID_IUnknown)
80 {
81 AddRef();
82 *ppvObject = this;
83 return S_OK;
84 }
85
86 *ppvObject = 0;
87 return E_NOINTERFACE;
88}
89
90/*
91 * IDropSource methods.
92 */
93
94/**
95 * The system informs us about whether we should continue the drag'n drop
96 * operation or not, depending on the sent key states.
97 *
98 * @return HRESULT
99 */
100STDMETHODIMP VBoxDnDDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD dwKeyState)
101{
102#if 1
103 LogFlowFunc(("fEscapePressed=%RTbool, dwKeyState=0x%x, mdwCurEffect=%RI32, muCurAction=%RU32\n",
104 fEscapePressed, dwKeyState, mdwCurEffect, muCurAction));
105#endif
106
107 /* ESC pressed? Bail out. */
108 if (fEscapePressed)
109 {
110 mdwCurEffect = 0;
111 muCurAction = DND_IGNORE_ACTION;
112
113 LogFlowFunc(("Canceled\n"));
114 return DRAGDROP_S_CANCEL;
115 }
116
117 /* Left mouse button released? Start "drop" action. */
118 if ((dwKeyState & MK_LBUTTON) == 0)
119 {
120 LogFlowFunc(("Dropping ...\n"));
121 return DRAGDROP_S_DROP;
122 }
123
124 /* No change, just continue. */
125 return S_OK;
126}
127
128/**
129 * The drop target gives our source feedback about whether
130 * it can handle our data or not.
131 *
132 * @return HRESULT
133 */
134STDMETHODIMP VBoxDnDDropSource::GiveFeedback(DWORD dwEffect)
135{
136 uint32_t uAction = DND_IGNORE_ACTION;
137
138#if 1
139 LogFlowFunc(("dwEffect=0x%x\n", dwEffect));
140#endif
141 if (dwEffect)
142 {
143 if (dwEffect & DROPEFFECT_COPY)
144 uAction |= DND_COPY_ACTION;
145 if (dwEffect & DROPEFFECT_MOVE)
146 uAction |= DND_MOVE_ACTION;
147 if (dwEffect & DROPEFFECT_LINK)
148 uAction |= DND_LINK_ACTION;
149 }
150
151 mdwCurEffect = dwEffect;
152 muCurAction = uAction;
153
154 return DRAGDROP_S_USEDEFAULTCURSORS;
155}
156
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette