069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/* $Id$ */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/** @file
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * VBox Console COM Class implementation - Guest drag'n drop target.
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/*
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * Copyright (C) 2014 Oracle Corporation
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync *
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * available from http://www.virtualbox.org. This file is free software;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * you can redistribute it and/or modify it under the terms of the GNU
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * General Public License (GPL) as published by the Free Software
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/*******************************************************************************
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync* Header Files *
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync*******************************************************************************/
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include "GuestImpl.h"
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include "GuestDnDTargetImpl.h"
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include "Global.h"
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include "AutoCaller.h"
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#include <algorithm> /* For std::find(). */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include <iprt/cpp/utils.h> /* For unconst(). */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include <VBox/com/array.h>
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include <VBox/HostServices/DragAndDropSvc.h>
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#ifdef LOG_GROUP
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync #undef LOG_GROUP
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#endif
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#define LOG_GROUP LOG_GROUP_GUEST_DND
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#include <VBox/log.h>
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync// constructor / destructor
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/////////////////////////////////////////////////////////////////////////////
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncDEFINE_EMPTY_CTOR_DTOR(GuestDnDTarget)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncHRESULT GuestDnDTarget::FinalConstruct(void)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowThisFunc(("\n"));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return BaseFinalConstruct();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncvoid GuestDnDTarget::FinalRelease(void)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowThisFuncEnter();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uninit();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync BaseFinalRelease();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowThisFuncLeave();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync// public initializer/uninitializer for internal purposes only
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/////////////////////////////////////////////////////////////////////////////
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncint GuestDnDTarget::init(const ComObjPtr<Guest>& pGuest)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowThisFuncEnter();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoInitSpan autoInitSpan(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AssertReturn(autoInitSpan.isOk(), E_FAIL);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync unconst(m_pGuest) = pGuest;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Confirm a successful initialization when it's the case. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync autoInitSpan.setSucceeded();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return VINF_SUCCESS;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/**
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * Uninitializes the instance.
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * Called from FinalRelease().
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncvoid GuestDnDTarget::uninit(void)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowThisFunc(("\n"));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoUninitSpan autoUninitSpan(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (autoUninitSpan.uninitDone())
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync// implementation of wrapped IDnDBase methods.
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync/////////////////////////////////////////////////////////////////////////////
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsyncHRESULT GuestDnDTarget::isFormatSupported(const com::Utf8Str &aFormat,
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync BOOL *aSupported)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync{
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync ReturnComNotImplemented();
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoCaller autoCaller(this);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync return GuestDnDBase::isFormatSupported(aFormat, aSupported);
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync}
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsyncHRESULT GuestDnDTarget::getFormats(std::vector<com::Utf8Str> &aFormats)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync{
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync ReturnComNotImplemented();
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoCaller autoCaller(this);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync return GuestDnDBase::getFormats(aFormats);
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync}
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsyncHRESULT GuestDnDTarget::addFormats(const std::vector<com::Utf8Str> &aFormats)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync{
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync ReturnComNotImplemented();
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoCaller autoCaller(this);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync return GuestDnDBase::addFormats(aFormats);
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync}
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsyncHRESULT GuestDnDTarget::removeFormats(const std::vector<com::Utf8Str> &aFormats)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync{
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync ReturnComNotImplemented();
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoCaller autoCaller(this);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
8f32c587d66eb1633f87183c1d750abe7f4b372cvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync return GuestDnDBase::removeFormats(aFormats);
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync}
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync// implementation of wrapped IDnDTarget methods.
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync/////////////////////////////////////////////////////////////////////////////
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncHRESULT GuestDnDTarget::enter(ULONG aScreenId, ULONG aX, ULONG aY,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T aDefaultAction,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync const std::vector<DnDAction_T> &aAllowedActions,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync const std::vector<com::Utf8Str> &aFormats,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T *aResultAction)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync ReturnComNotImplemented();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Input validation. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (aDefaultAction == DnDAction_Ignore)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return setError(E_INVALIDARG, tr("No default action specified"));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (!aAllowedActions.size())
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return setError(E_INVALIDARG, tr("Number of allowed actions is empty"));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (!aFormats.size())
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return setError(E_INVALIDARG, tr("Number of supported formats is empty"));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoCaller autoCaller(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Default action is ignoring. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T resAction = DnDAction_Ignore;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Check & convert the drag & drop actions */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uint32_t uDefAction = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uint32_t uAllowedActions = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnD::toHGCMActions(aDefaultAction, &uDefAction,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync aAllowedActions, &uAllowedActions);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* If there is no usable action, ignore this request. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (isDnDIgnoreAction(uDefAction))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Make a flat data string out of the supported format list. */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync Utf8Str strFormats = GuestDnD::toFormatString(m_strFormats, aFormats);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* If there is no valid supported format, ignore this request. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (strFormats.isEmpty())
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync HRESULT hr = S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Adjust the coordinates in a multi-monitor setup. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int rc = GuestDnDInst()->adjustScreenCoordinates(aScreenId, &aX, &aY);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync VBOXHGCMSVCPARM paParms[8];
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int i = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aScreenId);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aX);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aY);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(uDefAction);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(uAllowedActions);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setPointer((void*)strFormats.c_str(), strFormats.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(strFormats.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_ENTER,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync i, paParms);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnDResponse *pResp = GuestDnDInst()->response();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (pResp && RT_SUCCESS(pResp->waitForGuestResponse()))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync resAction = GuestDnD::toMainAction(pResp->defAction());
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (aResultAction)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync *aResultAction = resAction;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowFunc(("hr=%Rhrc, resAction=%ld\n", hr, resAction));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return hr;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncHRESULT GuestDnDTarget::move(ULONG aScreenId, ULONG aX, ULONG aY,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T aDefaultAction,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync const std::vector<DnDAction_T> &aAllowedActions,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync const std::vector<com::Utf8Str> &aFormats,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T *aResultAction)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync ReturnComNotImplemented();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Input validation. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoCaller autoCaller(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Default action is ignoring. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T resAction = DnDAction_Ignore;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Check & convert the drag & drop actions. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uint32_t uDefAction = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uint32_t uAllowedActions = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnD::toHGCMActions(aDefaultAction, &uDefAction,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync aAllowedActions, &uAllowedActions);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* If there is no usable action, ignore this request. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (isDnDIgnoreAction(uDefAction))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Make a flat data string out of the supported format list. */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync RTCString strFormats = GuestDnD::toFormatString(m_strFormats, aFormats);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* If there is no valid supported format, ignore this request. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (strFormats.isEmpty())
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync HRESULT hr = S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int rc = GuestDnDInst()->adjustScreenCoordinates(aScreenId, &aX, &aY);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync VBOXHGCMSVCPARM paParms[8];
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int i = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aScreenId);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aX);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aY);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(uDefAction);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(uAllowedActions);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setPointer((void*)strFormats.c_str(), strFormats.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(strFormats.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_MOVE,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync i, paParms);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnDResponse *pResp = GuestDnDInst()->response();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (pResp && RT_SUCCESS(pResp->waitForGuestResponse()))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync resAction = GuestDnD::toMainAction(pResp->defAction());
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (aResultAction)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync *aResultAction = resAction;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowFunc(("hr=%Rhrc, *pResultAction=%ld\n", hr, resAction));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return hr;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncHRESULT GuestDnDTarget::leave(ULONG uScreenId)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync ReturnComNotImplemented();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoCaller autoCaller(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync HRESULT hr = S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_LEAVE,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync 0 /* cParms */, NULL /* paParms */);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnDResponse *pResp = GuestDnDInst()->response();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (pResp)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync pResp->waitForGuestResponse();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowFunc(("hr=%Rhrc\n", hr));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return hr;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsyncHRESULT GuestDnDTarget::drop(ULONG aScreenId, ULONG aX, ULONG aY,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T aDefaultAction,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync const std::vector<DnDAction_T> &aAllowedActions,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync const std::vector<com::Utf8Str> &aFormats,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync com::Utf8Str &aFormat, DnDAction_T *aResultAction)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync ReturnComNotImplemented();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Input validation. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Everything else is optional. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoCaller autoCaller(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Default action is ignoring. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync DnDAction_T resAction = DnDAction_Ignore;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Check & convert the drag & drop actions. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uint32_t uDefAction = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync uint32_t uAllowedActions = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnD::toHGCMActions(aDefaultAction, &uDefAction,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync aAllowedActions, &uAllowedActions);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* If there is no usable action, ignore this request. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (isDnDIgnoreAction(uDefAction))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Make a flat data string out of the supported format list. */
aa08d96e9f8a68de2d11b24f680757cb02d1f16bvboxsync Utf8Str strFormats = GuestDnD::toFormatString(m_strFormats, aFormats);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* If there is no valid supported format, ignore this request. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (strFormats.isEmpty())
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync HRESULT hr = S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Adjust the coordinates in a multi-monitor setup. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int rc = GuestDnDInst()->adjustScreenCoordinates(aScreenId, &aX, &aY);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync VBOXHGCMSVCPARM paParms[8];
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int i = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aScreenId);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aX);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aY);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(uDefAction);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(uAllowedActions);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setPointer((void*)strFormats.c_str(), strFormats.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(strFormats.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_DROPPED,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync i, paParms);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnDResponse *pResp = GuestDnDInst()->response();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (pResp && RT_SUCCESS(pResp->waitForGuestResponse()))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync resAction = GuestDnD::toMainAction(pResp->defAction());
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync aFormat = pResp->format();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync LogFlowFunc(("resFormat=%s, resAction=%RU32\n",
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync pResp->format().c_str(), pResp->defAction()));
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (aResultAction)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync *aResultAction = resAction;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return hr;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
732523ef00def7386c2f24c43778d2b8993ed379vboxsyncHRESULT GuestDnDTarget::sendData(ULONG aScreenId,
732523ef00def7386c2f24c43778d2b8993ed379vboxsync const com::Utf8Str &aFormat,
732523ef00def7386c2f24c43778d2b8993ed379vboxsync const std::vector<BYTE> &aData,
732523ef00def7386c2f24c43778d2b8993ed379vboxsync ComPtr<IProgress> &aProgress)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync{
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#if !defined(VBOX_WITH_DRAG_AND_DROP) || !defined(VBOX_WITH_DRAG_AND_DROP_GH)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync ReturnComNotImplemented();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#else /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Input validation */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync AutoCaller autoCaller(this);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync HRESULT hr = S_OK;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync VBOXHGCMSVCPARM paParms[8];
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int i = 0;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32(aScreenId);
c8e3a310b008bd03e42089b1e7e8adc16daaf077vboxsync paParms[i++].setPointer((void *)aFormat.c_str(), (uint32_t)aFormat.length() + 1);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32((uint32_t)aFormat.length() + 1);
c1765e5d9999d3634e98e8058aa4044b0a9ea1d4vboxsync paParms[i++].setPointer((void*)&aData.front(), (uint32_t)aData.size());
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync paParms[i++].setUInt32((uint32_t)aData.size());
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync GuestDnDResponse *pResp = GuestDnDInst()->response();
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (pResp)
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Reset any old progress status. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync pResp->resetProgress(m_pGuest);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync /* Note: The actual data transfer of files/directoies is performed by the
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync * DnD host service. */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync int rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_SND_DATA,
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync i, paParms);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync if (RT_SUCCESS(rc))
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync {
6f19de7d599963a13f0016beeb7eda20de6f7cefvboxsync hr = pResp->queryProgressTo(aProgress.asOutParam());
6f19de7d599963a13f0016beeb7eda20de6f7cefvboxsync ComAssertComRC(hr);
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync }
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync return hr;
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync#endif /* VBOX_WITH_DRAG_AND_DROP */
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync}
069b9101fbd3b049610c5511b1cc9534d01ea472vboxsync