2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsNativeDragSource.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsISupportsImpl.h"
|
2009-03-06 09:54:29 -08:00
|
|
|
#include "nsString.h"
|
2011-04-25 18:37:20 -07:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsToolkit.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIDragService.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* class nsNativeDragSource
|
|
|
|
*/
|
2009-03-06 09:54:29 -08:00
|
|
|
nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) :
|
|
|
|
m_cRef(0),
|
2012-07-30 07:20:58 -07:00
|
|
|
m_hCursor(nullptr),
|
2011-10-01 19:16:19 -07:00
|
|
|
mUserCancelled(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-03-06 09:54:29 -08:00
|
|
|
mDataTransfer = do_QueryInterface(aDataTransfer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsNativeDragSource::~nsNativeDragSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragSource::QueryInterface(REFIID riid, void** ppv)
|
|
|
|
{
|
|
|
|
*ppv=NULL;
|
|
|
|
|
|
|
|
if (IID_IUnknown==riid || IID_IDropSource==riid)
|
|
|
|
*ppv=this;
|
|
|
|
|
|
|
|
if (NULL!=*ppv) {
|
|
|
|
((LPUNKNOWN)*ppv)->AddRef();
|
2010-02-20 05:45:19 -08:00
|
|
|
return S_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-20 05:45:19 -08:00
|
|
|
return E_NOINTERFACE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG)
|
|
|
|
nsNativeDragSource::AddRef(void)
|
|
|
|
{
|
|
|
|
++m_cRef;
|
|
|
|
NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this));
|
|
|
|
return m_cRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG)
|
|
|
|
nsNativeDragSource::Release(void)
|
|
|
|
{
|
|
|
|
--m_cRef;
|
|
|
|
NS_LOG_RELEASE(this, m_cRef, "nsNativeDragSource");
|
|
|
|
if (0 != m_cRef)
|
|
|
|
return m_cRef;
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
|
|
|
|
{
|
2011-04-25 18:37:20 -07:00
|
|
|
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
|
|
|
|
if (dragService) {
|
|
|
|
DWORD pos = ::GetMessagePos();
|
|
|
|
dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fEsc) {
|
2011-10-01 19:16:19 -07:00
|
|
|
mUserCancelled = true;
|
2010-02-20 05:45:19 -08:00
|
|
|
return DRAGDROP_S_CANCEL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-20 05:45:19 -08:00
|
|
|
if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON))
|
|
|
|
return DRAGDROP_S_DROP;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-20 05:45:19 -08:00
|
|
|
return S_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragSource::GiveFeedback(DWORD dwEffect)
|
|
|
|
{
|
2009-03-06 09:54:29 -08:00
|
|
|
// For drags involving tabs, we do some custom work with cursors.
|
|
|
|
if (mDataTransfer) {
|
|
|
|
nsAutoString cursor;
|
|
|
|
mDataTransfer->GetMozCursor(cursor);
|
2009-03-09 17:01:55 -07:00
|
|
|
if (cursor.EqualsLiteral("default")) {
|
2009-03-06 09:54:29 -08:00
|
|
|
m_hCursor = ::LoadCursor(0, IDC_ARROW);
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
m_hCursor = nullptr;
|
2009-03-06 09:54:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_hCursor) {
|
|
|
|
::SetCursor(m_hCursor);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the system choose which cursor to apply.
|
2010-02-20 05:45:19 -08:00
|
|
|
return DRAGDROP_S_USEDEFAULTCURSORS;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|