1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #if defined(__BORLANDC__)
28 #include "wx/window.h"
31 #if wxUSE_OLE && wxUSE_DRAG_AND_DROP
36 #include "wx/msw/private.h"
38 // for some compilers, the entire ole2.h must be included, not only oleauto.h
39 #if wxUSE_NORLANDER_HEADERS || defined(__WATCOMC__) || defined(__WXWINCE__)
45 #include "wx/msw/ole/oleutils.h"
47 // ----------------------------------------------------------------------------
48 // wxIDropSource implementation of IDropSource interface
49 // ----------------------------------------------------------------------------
51 class wxIDropSource
: public IDropSource
54 wxIDropSource(wxDropSource
*pDropSource
);
55 virtual ~wxIDropSource() { }
58 STDMETHODIMP
QueryContinueDrag(BOOL fEscapePressed
, DWORD grfKeyState
);
59 STDMETHODIMP
GiveFeedback(DWORD dwEffect
);
61 DECLARE_IUNKNOWN_METHODS
;
64 DWORD m_grfInitKeyState
; // button which started the d&d operation
65 wxDropSource
*m_pDropSource
; // pointer to C++ class we belong to
67 DECLARE_NO_COPY_CLASS(wxIDropSource
)
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;
92 // Name : wxIDropSource::QueryContinueDrag
93 // Purpose : decide if drag operation must be continued or not
94 // Returns : HRESULT: S_OK if we should continue
95 // DRAGDROP_S_DROP to drop right now
96 // DRAGDROP_S_CANCEL to cancel everything
97 // Params : [in] BOOL fEscapePressed <Esc> pressed since last call?
98 // [in] DWORD grfKeyState mask containing state of kbd keys
99 // Notes : as there is no reasonably simple portable way to implement this
100 // function, we currently don't give the possibility to override the
101 // default behaviour implemented here
102 STDMETHODIMP
wxIDropSource::QueryContinueDrag(BOOL fEscapePressed
,
105 if ( fEscapePressed
)
106 return DRAGDROP_S_CANCEL
;
108 // initialize ourself with the drag begin button
109 if ( m_grfInitKeyState
== 0 ) {
110 m_grfInitKeyState
= grfKeyState
& (MK_LBUTTON
| MK_RBUTTON
| MK_MBUTTON
);
113 if ( !(grfKeyState
& m_grfInitKeyState
) ) {
114 // button which started d&d released, go!
115 return DRAGDROP_S_DROP
;
121 // Name : wxIDropSource::GiveFeedback
122 // Purpose : give UI feedback according to current state of operation
123 // Returns : STDMETHODIMP
124 // Params : [in] DWORD dwEffect - what would happen if we dropped now
125 // Notes : default implementation is ok in more than 99% of cases
126 STDMETHODIMP
wxIDropSource::GiveFeedback(DWORD dwEffect
)
129 if ( dwEffect
& DROPEFFECT_COPY
)
131 else if ( dwEffect
& DROPEFFECT_MOVE
)
136 if ( m_pDropSource
->GiveFeedback(effect
) )
139 return DRAGDROP_S_USEDEFAULTCURSORS
;
142 // ----------------------------------------------------------------------------
143 // wxDropSource implementation
144 // ----------------------------------------------------------------------------
148 // common part of all ctors
149 void wxDropSource::Init()
151 m_pIDropSource
= new wxIDropSource(this);
152 m_pIDropSource
->AddRef();
155 wxDropSource::wxDropSource(wxWindow
* WXUNUSED(win
),
156 const wxCursor
&cursorCopy
,
157 const wxCursor
&cursorMove
,
158 const wxCursor
&cursorStop
)
159 : wxDropSourceBase(cursorCopy
, cursorMove
, cursorStop
)
164 wxDropSource::wxDropSource(wxDataObject
& data
,
165 wxWindow
* WXUNUSED(win
),
166 const wxCursor
&cursorCopy
,
167 const wxCursor
&cursorMove
,
168 const wxCursor
&cursorStop
)
169 : wxDropSourceBase(cursorCopy
, cursorMove
, cursorStop
)
175 wxDropSource::~wxDropSource()
177 m_pIDropSource
->Release();
181 // Purpose : start drag and drop operation
182 // Returns : wxDragResult - the code of performed operation
183 // Params : [in] int flags: specifies if moving is allowe (or only copying)
184 // Notes : you must call SetData() before if you had used def ctor
185 wxDragResult
wxDropSource::DoDragDrop(int flags
)
187 wxCHECK_MSG( m_data
!= NULL
, wxDragNone
, wxT("No data in wxDropSource!") );
190 HRESULT hr
= ::DoDragDrop(m_data
->GetInterface(),
192 (flags
& wxDrag_AllowMove
)
193 ? DROPEFFECT_COPY
| DROPEFFECT_MOVE
197 if ( hr
== DRAGDROP_S_CANCEL
) {
200 else if ( hr
== DRAGDROP_S_DROP
) {
201 if ( dwEffect
& DROPEFFECT_COPY
) {
204 else if ( dwEffect
& DROPEFFECT_MOVE
) {
205 // consistency check: normally, we shouldn't get "move" at all
206 // here if we don't allow it, but in practice it does happen quite often
207 return (flags
& wxDrag_AllowMove
) ? wxDragMove
: wxDragCopy
;
216 wxLogApiError(wxT("DoDragDrop"), hr
);
217 wxLogError(wxT("Drag & drop operation failed."));
220 wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."),
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 // Notes : here we just leave this stuff for default implementation
233 bool wxDropSource::GiveFeedback(wxDragResult effect
)
235 const wxCursor
& cursor
= GetCursor(effect
);
238 ::SetCursor((HCURSOR
)cursor
.GetHCURSOR());
248 #endif //USE_DRAG_AND_DROP