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
75 DECLARE_NO_COPY_CLASS(wxIDropSource
)
78 // ============================================================================
80 // ============================================================================
82 // ----------------------------------------------------------------------------
83 // wxIDropSource implementation
84 // ----------------------------------------------------------------------------
85 BEGIN_IID_TABLE(wxIDropSource
)
90 IMPLEMENT_IUNKNOWN_METHODS(wxIDropSource
)
92 wxIDropSource::wxIDropSource(wxDropSource
*pDropSource
)
94 wxASSERT( pDropSource
!= NULL
);
96 m_pDropSource
= pDropSource
;
97 m_grfInitKeyState
= 0;
100 // Name : wxIDropSource::QueryContinueDrag
101 // Purpose : decide if drag operation must be continued or not
102 // Returns : HRESULT: S_OK if we should continue
103 // DRAGDROP_S_DROP to drop right now
104 // DRAGDROP_S_CANCEL to cancel everything
105 // Params : [in] BOOL fEscapePressed <Esc> pressed since last call?
106 // [in] DWORD grfKeyState mask containing state of kbd keys
107 // Notes : as there is no reasonably simple portable way to implement this
108 // function, we currently don't give the possibility to override the
109 // default behaviour implemented here
110 STDMETHODIMP
wxIDropSource::QueryContinueDrag(BOOL fEscapePressed
,
113 if ( fEscapePressed
)
114 return DRAGDROP_S_CANCEL
;
116 // initialize ourself with the drag begin button
117 if ( m_grfInitKeyState
== 0 ) {
118 m_grfInitKeyState
= grfKeyState
& (MK_LBUTTON
| MK_RBUTTON
| MK_MBUTTON
);
121 if ( !(grfKeyState
& m_grfInitKeyState
) ) {
122 // button which started d&d released, go!
123 return DRAGDROP_S_DROP
;
129 // Name : wxIDropSource::GiveFeedback
130 // Purpose : give UI feedback according to current state of operation
131 // Returns : STDMETHODIMP
132 // Params : [in] DWORD dwEffect - what would happen if we dropped now
133 // Notes : default implementation is ok in more than 99% of cases
134 STDMETHODIMP
wxIDropSource::GiveFeedback(DWORD dwEffect
)
137 if ( dwEffect
& DROPEFFECT_COPY
)
139 else if ( dwEffect
& DROPEFFECT_MOVE
)
144 if ( m_pDropSource
->GiveFeedback(effect
) )
147 return DRAGDROP_S_USEDEFAULTCURSORS
;
150 // ----------------------------------------------------------------------------
151 // wxDropSource implementation
152 // ----------------------------------------------------------------------------
156 // common part of all ctors
157 void wxDropSource::Init()
159 m_pIDropSource
= new wxIDropSource(this);
160 m_pIDropSource
->AddRef();
163 wxDropSource::wxDropSource(wxWindow
* WXUNUSED(win
),
164 const wxCursor
&cursorCopy
,
165 const wxCursor
&cursorMove
,
166 const wxCursor
&cursorStop
)
167 : wxDropSourceBase(cursorCopy
, cursorMove
, cursorStop
)
172 wxDropSource::wxDropSource(wxDataObject
& data
,
173 wxWindow
* WXUNUSED(win
),
174 const wxCursor
&cursorCopy
,
175 const wxCursor
&cursorMove
,
176 const wxCursor
&cursorStop
)
177 : wxDropSourceBase(cursorCopy
, cursorMove
, cursorStop
)
183 wxDropSource::~wxDropSource()
185 m_pIDropSource
->Release();
189 // Purpose : start drag and drop operation
190 // Returns : wxDragResult - the code of performed operation
191 // Params : [in] int flags: specifies if moving is allowe (or only copying)
192 // Notes : you must call SetData() before if you had used def ctor
193 wxDragResult
wxDropSource::DoDragDrop(int flags
)
195 wxCHECK_MSG( m_data
!= NULL
, wxDragNone
, wxT("No data in wxDropSource!") );
198 HRESULT hr
= ::DoDragDrop(m_data
->GetInterface(),
200 (flags
& wxDrag_AllowMove
)
201 ? DROPEFFECT_COPY
| DROPEFFECT_MOVE
205 if ( hr
== DRAGDROP_S_CANCEL
) {
208 else if ( hr
== DRAGDROP_S_DROP
) {
209 if ( dwEffect
& DROPEFFECT_COPY
) {
212 else if ( dwEffect
& DROPEFFECT_MOVE
) {
213 // consistency check: normally, we shouldn't get "move" at all
214 // here if we don't allow it, but in practice it does happen quite often
215 return (flags
& wxDrag_AllowMove
) ? wxDragMove
: wxDragCopy
;
224 wxLogApiError(wxT("DoDragDrop"), hr
);
225 wxLogError(wxT("Drag & drop operation failed."));
228 wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."),
236 // Name : wxDropSource::GiveFeedback
237 // Purpose : visually inform the user about d&d operation state
238 // Returns : bool: true if we do all ourselves or false for default feedback
239 // Params : [in] DragResult effect - what would happen if we dropped now
240 // Notes : here we just leave this stuff for default implementation
241 bool wxDropSource::GiveFeedback(wxDragResult effect
)
243 const wxCursor
& cursor
= GetCursor(effect
);
246 ::SetCursor((HCURSOR
)cursor
.GetHCURSOR());
256 #endif //USE_DRAG_AND_DROP