1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the Drag-n-drop classes
7 // Created: 31-October-1999
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 // flags for wxDropSource::DoDragDrop()
23 // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1
24 // (== True) for compatibility with the old DoDragDrop(bool) method!
27 wxDrag_CopyOnly = 0, // allow only copying
28 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
29 wxDrag_DefaultMove = 3 // the default operation is move, not copy
32 // result of wxDropSource::DoDragDrop() call
35 wxDragError, // error prevented the d&d operation from completing
36 wxDragNone, // drag target didn't accept the data
37 wxDragCopy, // the data was successfully copied
38 wxDragMove, // the data was successfully moved (MSW only)
39 wxDragLink, // operation is a drag-link
40 wxDragCancel // the operation was cancelled by user (not an error)
43 bool wxIsDragResultOk(wxDragResult res);
45 //---------------------------------------------------------------------------
48 // wxDropSource is the object you need to create (and call DoDragDrop on it)
49 // to initiate a drag-and-drop operation
54 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
58 %rename(DropSource) wxPyDropSource;
59 class wxPyDropSource {
61 %pythonAppend wxPyDropSource "self._setCallbackInfo(self, DropSource, 0)"
63 wxPyDropSource(wxWindow *win,
64 const wxCursor © = wxNullCursor,
65 const wxCursor &move = wxNullCursor,
66 const wxCursor &none = wxNullCursor);
68 wxPyDropSource(wxWindow *win,
69 const wxIcon& copy = wxNullIcon,
70 const wxIcon& move = wxNullIcon,
71 const wxIcon& none = wxNullIcon);
74 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
77 // set the data which is transfered by drag and drop
78 void SetData(wxDataObject& data);
80 wxDataObject *GetDataObject();
82 // set the icon corresponding to given drag result
83 void SetCursor(wxDragResult res, const wxCursor& cursor);
85 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
87 bool GiveFeedback(wxDragResult effect);
88 %MAKE_BASE_FUNC(DropSource, GiveFeedback);
90 %property(DataObject, GetDataObject, SetData, doc="See `GetDataObject` and `SetData`");
95 def DROP_ICON(filename):
97 Returns either a `wx.Cursor` or `wx.Icon` created from the image file
98 ``filename``. This function is useful with the `wx.DropSource` class
99 which, depending on platform accepts either a icon or a cursor.
101 img = wx.Image(filename)
102 if wx.Platform == '__WXGTK__':
103 return wx.IconFromBitmap(wx.BitmapFromImage(img))
105 return wx.CursorFromImage(img)
109 //---------------------------------------------------------------------------
111 // wxDropTarget should be associated with a window if it wants to be able to
112 // receive data via drag and drop.
114 // To use this class, you should derive from wxDropTarget and implement
115 // OnData() pure virtual method. You may also wish to override OnDrop() if you
116 // want to accept the data only inside some region of the window (this may
117 // avoid having to copy the data to this application which happens only when
118 // OnData() is called)
121 // Just a place holder for the type system. The real base class for
122 // wxPython is wxPyDropTarget
123 // class wxDropTarget {
129 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
130 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
131 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
132 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
133 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
137 %rename(DropTarget) wxPyDropTarget;
138 class wxPyDropTarget // : public wxDropTarget
141 %pythonAppend wxPyDropTarget
142 "self._setCallbackInfo(self, DropTarget)"
144 %disownarg( wxDataObject *dataObject );
146 wxPyDropTarget(wxDataObject *dataObject = NULL);
147 void _setCallbackInfo(PyObject* self, PyObject* _class);
151 // get/set the associated wxDataObject
152 wxDataObject *GetDataObject();
153 void SetDataObject(wxDataObject *dataObject);
155 %cleardisown( wxDataObject *dataObject );
157 wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
158 wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
160 bool OnDrop(wxCoord x, wxCoord y);
162 %MAKE_BASE_FUNC(DropTarget, OnEnter);
163 %MAKE_BASE_FUNC(DropTarget, OnDragOver);
164 %MAKE_BASE_FUNC(DropTarget, OnLeave);
165 %MAKE_BASE_FUNC(DropTarget, OnDrop);
168 // may be called *only* from inside OnData() and will fill m_dataObject
169 // with the data from the drop source if it returns True
172 // sets the default action for drag and drop:
173 // use wxDragMove or wxDragCopy to set deafult action to move or copy
174 // and use wxDragNone (default) to set default action specified by
175 // initialization of draging (see wxDropSourceBase::DoDragDrop())
176 void SetDefaultAction(wxDragResult action);
178 // returns default action for drag and drop or
179 // wxDragNone if this not specified
180 wxDragResult GetDefaultAction();
182 %property(Data, GetData, doc="See `GetData`");
183 %property(DataObject, GetDataObject, SetDataObject, doc="See `GetDataObject` and `SetDataObject`");
184 %property(DefaultAction, GetDefaultAction, SetDefaultAction, doc="See `GetDefaultAction` and `SetDefaultAction`");
188 %pythoncode { PyDropTarget = DropTarget }
190 //---------------------------------------------------------------------------
192 // A simple wxDropTarget derived class for text data: you only need to
193 // override OnDropText() to get something working
197 class wxPyTextDropTarget : public wxTextDropTarget {
199 wxPyTextDropTarget() {}
201 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
203 DEC_PYCALLBACK__(OnLeave);
204 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
205 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
206 DEC_PYCALLBACK_DR_2WXCDR(OnData);
207 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
212 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
213 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
214 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
215 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
216 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
217 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
221 %rename(TextDropTarget) wxPyTextDropTarget;
222 class wxPyTextDropTarget : public wxPyDropTarget {
224 %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
226 wxPyTextDropTarget();
227 void _setCallbackInfo(PyObject* self, PyObject* _class);
229 bool OnDropText(wxCoord x, wxCoord y, const wxString& text);
230 wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
231 wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
233 bool OnDrop(wxCoord x, wxCoord y);
234 wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
236 %MAKE_BASE_FUNC(TextDropTarget, OnDropText);
237 %MAKE_BASE_FUNC(TextDropTarget, OnEnter);
238 %MAKE_BASE_FUNC(TextDropTarget, OnDragOver);
239 %MAKE_BASE_FUNC(TextDropTarget, OnLeave);
240 %MAKE_BASE_FUNC(TextDropTarget, OnDrop);
241 %MAKE_BASE_FUNC(TextDropTarget, OnData);
244 //---------------------------------------------------------------------------
246 // A drop target which accepts files (dragged from File Manager or Explorer)
250 class wxPyFileDropTarget : public wxFileDropTarget {
252 wxPyFileDropTarget() {}
254 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
256 DEC_PYCALLBACK__(OnLeave);
257 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
258 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
259 DEC_PYCALLBACK_DR_2WXCDR(OnData);
260 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
265 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
266 const wxArrayString& filenames) {
268 wxPyBlock_t blocked = wxPyBeginBlockThreads();
269 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
270 PyObject* list = wxArrayString2PyList_helper(filenames);
271 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
274 wxPyEndBlockThreads(blocked);
280 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
281 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
282 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
283 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
284 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
289 %rename(FileDropTarget) wxPyFileDropTarget;
290 class wxPyFileDropTarget : public wxPyDropTarget
293 %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
295 wxPyFileDropTarget();
296 void _setCallbackInfo(PyObject* self, PyObject* _class);
298 bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
299 wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
300 wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
302 bool OnDrop(wxCoord x, wxCoord y);
303 wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
305 %MAKE_BASE_FUNC(FileDropTarget, OnDropFiles);
306 %MAKE_BASE_FUNC(FileDropTarget, OnEnter);
307 %MAKE_BASE_FUNC(FileDropTarget, OnDragOver);
308 %MAKE_BASE_FUNC(FileDropTarget, OnLeave);
309 %MAKE_BASE_FUNC(FileDropTarget, OnDrop);
310 %MAKE_BASE_FUNC(FileDropTarget, OnData);
314 //---------------------------------------------------------------------------
316 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
317 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
318 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
319 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
321 //---------------------------------------------------------------------------