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