widget/windows/nsNativeDragSource.cpp

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:fec4f4478cff
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "nsNativeDragSource.h"
7 #include <stdio.h>
8 #include "nsISupportsImpl.h"
9 #include "nsString.h"
10 #include "nsIServiceManager.h"
11 #include "nsToolkit.h"
12 #include "nsWidgetsCID.h"
13 #include "nsIDragService.h"
14
15 /*
16 * class nsNativeDragSource
17 */
18 nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) :
19 m_cRef(0),
20 m_hCursor(nullptr),
21 mUserCancelled(false)
22 {
23 mDataTransfer = do_QueryInterface(aDataTransfer);
24 }
25
26 nsNativeDragSource::~nsNativeDragSource()
27 {
28 }
29
30 STDMETHODIMP
31 nsNativeDragSource::QueryInterface(REFIID riid, void** ppv)
32 {
33 *ppv=nullptr;
34
35 if (IID_IUnknown==riid || IID_IDropSource==riid)
36 *ppv=this;
37
38 if (nullptr!=*ppv) {
39 ((LPUNKNOWN)*ppv)->AddRef();
40 return S_OK;
41 }
42
43 return E_NOINTERFACE;
44 }
45
46 STDMETHODIMP_(ULONG)
47 nsNativeDragSource::AddRef(void)
48 {
49 ++m_cRef;
50 NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this));
51 return m_cRef;
52 }
53
54 STDMETHODIMP_(ULONG)
55 nsNativeDragSource::Release(void)
56 {
57 --m_cRef;
58 NS_LOG_RELEASE(this, m_cRef, "nsNativeDragSource");
59 if (0 != m_cRef)
60 return m_cRef;
61
62 delete this;
63 return 0;
64 }
65
66 STDMETHODIMP
67 nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
68 {
69 static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
70
71 nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
72 if (dragService) {
73 DWORD pos = ::GetMessagePos();
74 dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos));
75 }
76
77 if (fEsc) {
78 mUserCancelled = true;
79 return DRAGDROP_S_CANCEL;
80 }
81
82 if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON))
83 return DRAGDROP_S_DROP;
84
85 return S_OK;
86 }
87
88 STDMETHODIMP
89 nsNativeDragSource::GiveFeedback(DWORD dwEffect)
90 {
91 // For drags involving tabs, we do some custom work with cursors.
92 if (mDataTransfer) {
93 nsAutoString cursor;
94 mDataTransfer->GetMozCursor(cursor);
95 if (cursor.EqualsLiteral("default")) {
96 m_hCursor = ::LoadCursor(0, IDC_ARROW);
97 } else {
98 m_hCursor = nullptr;
99 }
100 }
101
102 if (m_hCursor) {
103 ::SetCursor(m_hCursor);
104 return S_OK;
105 }
106
107 // Let the system choose which cursor to apply.
108 return DRAGDROP_S_USEDEFAULTCURSORS;
109 }

mercurial