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__)
31 #include "wx/window.h"
36 #if wxUSE_OLE && wxUSE_DRAG_AND_DROP
43 #if wxUSE_NORLANDER_HEADERS
54 #include "wx/msw/ole/oleutils.h"
56 // ----------------------------------------------------------------------------
57 // wxIDropSource implementation of IDropSource interface
58 // ----------------------------------------------------------------------------
60 class wxIDropSource
: public IDropSource
63 wxIDropSource(wxDropSource
*pDropSource
);
65 DECLARE_IUNKNOWN_METHODS
;
68 STDMETHODIMP
QueryContinueDrag(BOOL fEscapePressed
, DWORD grfKeyState
);
69 STDMETHODIMP
GiveFeedback(DWORD dwEffect
);
72 DWORD m_grfInitKeyState
; // button which started the d&d operation
73 wxDropSource
*m_pDropSource
; // pointer to C++ class we belong to
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
81 // wxIDropSource implementation
82 // ----------------------------------------------------------------------------
83 BEGIN_IID_TABLE(wxIDropSource
)
88 IMPLEMENT_IUNKNOWN_METHODS(wxIDropSource
)
90 wxIDropSource::wxIDropSource(wxDropSource
*pDropSource
)
92 wxASSERT( pDropSource
!= NULL
);
94 m_pDropSource
= pDropSource
;
95 m_grfInitKeyState
= 0;
99 // Name : wxIDropSource::QueryContinueDrag
100 // Purpose : decide if drag operation must be continued or not
101 // Returns : HRESULT: S_OK if we should continue
102 // DRAGDROP_S_DROP to drop right now
103 // DRAGDROP_S_CANCEL to cancel everything
104 // Params : [in] BOOL fEscapePressed <Esc> pressed since last call?
105 // [in] DWORD grfKeyState mask containing state of kbd keys
106 // Notes : as there is no reasonably simple portable way to implement this
107 // function, we currently don't give the possibility to override the
108 // default behaviour implemented here
109 STDMETHODIMP
wxIDropSource::QueryContinueDrag(BOOL fEscapePressed
,
112 if ( fEscapePressed
)
113 return DRAGDROP_S_CANCEL
;
115 // initialize ourself with the drag begin button
116 if ( m_grfInitKeyState
== 0 ) {
117 m_grfInitKeyState
= grfKeyState
& (MK_LBUTTON
| MK_RBUTTON
| MK_MBUTTON
);
120 if ( !(grfKeyState
& m_grfInitKeyState
) ) {
121 // button which started d&d released, go!
122 return DRAGDROP_S_DROP
;
128 // Name : wxIDropSource::GiveFeedback
129 // Purpose : give UI feedback according to current state of operation
130 // Returns : STDMETHODIMP
131 // Params : [in] DWORD dwEffect - what would happen if we dropped now
132 // Notes : default implementation is ok in more than 99% of cases
133 STDMETHODIMP
wxIDropSource::GiveFeedback(DWORD dwEffect
)
136 if ( dwEffect
& DROPEFFECT_COPY
)
138 else if ( dwEffect
& DROPEFFECT_MOVE
)
143 if ( m_pDropSource
->GiveFeedback(effect
) )
146 return DRAGDROP_S_USEDEFAULTCURSORS
;
149 // ----------------------------------------------------------------------------
150 // wxDropSource implementation
151 // ----------------------------------------------------------------------------
155 // common part of all ctors
156 void wxDropSource::Init()
158 m_pIDropSource
= new wxIDropSource(this);
159 m_pIDropSource
->AddRef();
162 wxDropSource::wxDropSource(wxWindow
* WXUNUSED(win
),
163 const wxCursor
&cursorCopy
,
164 const wxCursor
&cursorMove
,
165 const wxCursor
&cursorStop
)
166 : wxDropSourceBase(cursorCopy
, cursorMove
, cursorStop
)
171 wxDropSource::wxDropSource(wxDataObject
& data
,
172 wxWindow
* WXUNUSED(win
),
173 const wxCursor
&cursorCopy
,
174 const wxCursor
&cursorMove
,
175 const wxCursor
&cursorStop
)
176 : wxDropSourceBase(cursorCopy
, cursorMove
, cursorStop
)
182 wxDropSource::~wxDropSource()
184 m_pIDropSource
->Release();
188 // Purpose : start drag and drop operation
189 // Returns : wxDragResult - the code of performed operation
190 // Params : [in] int flags: specifies if moving is allowe (or only copying)
191 // Notes : you must call SetData() before if you had used def ctor
192 wxDragResult
wxDropSource::DoDragDrop(int flags
)
194 wxCHECK_MSG( m_data
!= NULL
, wxDragNone
, wxT("No data in wxDropSource!") );
197 HRESULT hr
= ::DoDragDrop(m_data
->GetInterface(),
199 (flags
& wxDrag_AllowMove
)
200 ? DROPEFFECT_COPY
| DROPEFFECT_MOVE
204 if ( hr
== DRAGDROP_S_CANCEL
) {
207 else if ( hr
== DRAGDROP_S_DROP
) {
208 if ( dwEffect
& DROPEFFECT_COPY
) {
211 else if ( dwEffect
& DROPEFFECT_MOVE
) {
212 // consistency check: normally, we shouldn't get "move" at all
213 // here if we don't allow it, but in practice it does happen quite often
214 return (flags
& wxDrag_AllowMove
) ? wxDragMove
: wxDragCopy
;
223 wxLogApiError(wxT("DoDragDrop"), hr
);
224 wxLogError(wxT("Drag & drop operation failed."));
227 wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."),
235 // Name : wxDropSource::GiveFeedback
236 // Purpose : visually inform the user about d&d operation state
237 // Returns : bool: true if we do all ourselves or false for default feedback
238 // Params : [in] DragResult effect - what would happen if we dropped now
239 // Notes : here we just leave this stuff for default implementation
240 bool wxDropSource::GiveFeedback(wxDragResult effect
)
242 const wxCursor
& cursor
= GetCursor(effect
);
245 ::SetCursor((HCURSOR
)cursor
.GetHCURSOR());
255 #endif //USE_DRAG_AND_DROP