1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/dropsrc.cpp
3 // Purpose: implementation of wxIDropSource and wxDropSource
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "dropsrc.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
33 #if wxUSE_DRAG_AND_DROP
36 #include <wx/msw/ole/dataobj.h>
37 #include <wx/msw/ole/dropsrc.h>
48 #include <wx/msw/ole/oleutils.h>
50 // ----------------------------------------------------------------------------
51 // wxIDropSource implementation of IDropSource interface
52 // ----------------------------------------------------------------------------
54 class wxIDropSource
: public IDropSource
57 wxIDropSource(wxDropSource
*pDropSource
);
59 DECLARE_IUNKNOWN_METHODS
;
62 STDMETHODIMP
QueryContinueDrag(BOOL fEscapePressed
, DWORD grfKeyState
);
63 STDMETHODIMP
GiveFeedback(DWORD dwEffect
);
66 DWORD m_grfInitKeyState
; // button which started the d&d operation
67 wxDropSource
*m_pDropSource
; // pointer to C++ class we belong to
70 // ============================================================================
72 // ============================================================================
74 // ----------------------------------------------------------------------------
75 // wxIDropSource implementation
76 // ----------------------------------------------------------------------------
77 BEGIN_IID_TABLE(wxIDropSource
)
82 IMPLEMENT_IUNKNOWN_METHODS(wxIDropSource
)
84 wxIDropSource::wxIDropSource(wxDropSource
*pDropSource
)
86 wxASSERT( pDropSource
!= NULL
);
88 m_pDropSource
= pDropSource
;
89 m_grfInitKeyState
= 0;
93 // Name : wxIDropSource::QueryContinueDrag
94 // Purpose : decide if drag operation must be continued or not
95 // Returns : HRESULT: S_OK if we should continue
96 // DRAGDROP_S_DROP to drop right now
97 // DRAGDROP_S_CANCEL to cancel everything
98 // Params : [in] BOOL fEscapePressed <Esc> pressed since last call?
99 // [in] DWORD grfKeyState mask containing state of kbd keys
100 // Notes : as there is no reasonably simple portable way to implement this
101 // function, we currently don't give the possibility to override the
102 // default behaviour implemented here
103 STDMETHODIMP
wxIDropSource::QueryContinueDrag(BOOL fEscapePressed
,
106 if ( fEscapePressed
)
107 return DRAGDROP_S_CANCEL
;
109 // initialize ourself with the drag begin button
110 if ( m_grfInitKeyState
== 0 ) {
111 m_grfInitKeyState
= grfKeyState
& (MK_LBUTTON
| MK_RBUTTON
| MK_MBUTTON
);
114 if ( !(grfKeyState
& m_grfInitKeyState
) ) {
115 // button which started d&d released, go!
116 return DRAGDROP_S_DROP
;
122 // Name : wxIDropSource::GiveFeedback
123 // Purpose : give UI feedback according to current state of operation
124 // Returns : STDMETHODIMP
125 // Params : [in] DWORD dwEffect - what would happen if we dropped now
126 // Notes : default implementation is ok in more than 99% of cases
127 STDMETHODIMP
wxIDropSource::GiveFeedback(DWORD dwEffect
)
130 if ( dwEffect
& DROPEFFECT_COPY
)
132 else if ( dwEffect
& DROPEFFECT_MOVE
)
137 if ( m_pDropSource
->GiveFeedback(effect
,
138 (dwEffect
& DROPEFFECT_SCROLL
) != 0 ) )
141 return DRAGDROP_S_USEDEFAULTCURSORS
;
144 // ----------------------------------------------------------------------------
145 // wxDropSource implementation
146 // ----------------------------------------------------------------------------
150 // common part of all ctors
151 void wxDropSource::Init()
153 m_pIDropSource
= new wxIDropSource(this);
154 m_pIDropSource
->AddRef();
157 wxDropSource::wxDropSource(wxWindow
* WXUNUSED(win
))
163 wxDropSource::wxDropSource(wxDataObject
& data
, wxWindow
* WXUNUSED(win
))
169 void wxDropSource::SetData(wxDataObject
& data
)
174 wxDropSource::~wxDropSource()
176 m_pIDropSource
->Release();
180 // Purpose : start drag and drop operation
181 // Returns : wxDragResult - the code of performed operation
182 // Params : [in] bool bAllowMove: if false, only copy is allowed
183 // Notes : you must call SetData() before if you had used def ctor
184 wxDragResult
wxDropSource::DoDragDrop(bool bAllowMove
)
186 wxCHECK_MSG( m_pData
!= NULL
, wxDragNone
, "No data in wxDropSource!" );
189 HRESULT hr
= ::DoDragDrop(m_pData
->GetInterface(),
191 bAllowMove
? DROPEFFECT_COPY
| DROPEFFECT_MOVE
195 if ( hr
== DRAGDROP_S_CANCEL
) {
198 else if ( hr
== DRAGDROP_S_DROP
) {
199 if ( dwEffect
& DROPEFFECT_COPY
) {
202 else if ( dwEffect
& DROPEFFECT_MOVE
) {
203 // consistency check: normally, we shouldn't get "move" at all
204 // here if !bAllowMove, but in practice it does happen quite often
217 wxLogApiError("DoDragDrop", hr
);
218 wxLogError("Drag & drop operation failed.");
221 wxLogDebug("Unexpected success return code %08lx from DoDragDrop.", hr
);
228 // Name : wxDropSource::GiveFeedback
229 // Purpose : visually inform the user about d&d operation state
230 // Returns : bool: true if we do all ourselves or false for default feedback
231 // Params : [in] DragResult effect - what would happen if we dropped now
232 // [in] bool bScrolling - true if target is scrolling
233 // Notes : here we just leave this stuff for default implementation
234 bool wxDropSource::GiveFeedback(wxDragResult effect
, bool bScrolling
)
239 #endif //USE_DRAG_AND_DROP