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 //---------------------------------------------------------------------------
22 //---------------------------------------------------------------------------
25 // flags for wxDropSource::DoDragDrop()
27 // NB: wxDrag_CopyOnly must be 0 (== FALSE) and wxDrag_AllowMove must be 1
28 // (== TRUE) for compatibility with the old DoDragDrop(bool) method!
31 wxDrag_CopyOnly = 0, // allow only copying
32 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
33 wxDrag_DefaultMove = 3 // the default operation is move, not copy
36 // result of wxDropSource::DoDragDrop() call
39 wxDragError, // error prevented the d&d operation from completing
40 wxDragNone, // drag target didn't accept the data
41 wxDragCopy, // the data was successfully copied
42 wxDragMove, // the data was successfully moved (MSW only)
43 wxDragLink, // operation is a drag-link
44 wxDragCancel // the operation was cancelled by user (not an error)
47 bool wxIsDragResultOk(wxDragResult res);
49 //---------------------------------------------------------------------------
52 // wxDropSource is the object you need to create (and call DoDragDrop on it)
53 // to initiate a drag-and-drop operation
58 class wxPyDropSource : public wxDropSource {
61 wxPyDropSource(wxWindow *win = NULL,
62 const wxCursor © = wxNullCursor,
63 const wxCursor &move = wxNullCursor,
64 const wxCursor &none = wxNullCursor)
65 : wxDropSource(win, copy, move, none) {}
67 wxPyDropSource(wxWindow *win = NULL,
68 const wxIcon& copy = wxNullIcon,
69 const wxIcon& move = wxNullIcon,
70 const wxIcon& none = wxNullIcon)
71 : wxDropSource(win, copy, move, none) {}
75 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
79 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
84 %name(DropSource) class wxPyDropSource {
87 wxPyDropSource(wxWindow *win = NULL,
88 const wxCursor © = wxNullCursor,
89 const wxCursor &move = wxNullCursor,
90 const wxCursor &none = wxNullCursor);
92 wxPyDropSource(wxWindow *win = NULL,
93 const wxIcon& copy = wxNullIcon,
94 const wxIcon& move = wxNullIcon,
95 const wxIcon& none = wxNullIcon);
98 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
99 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
102 // set the data which is transfered by drag and drop
103 void SetData(wxDataObject& data);
105 wxDataObject *GetDataObject();
107 // set the icon corresponding to given drag result
108 void SetCursor(wxDragResult res, const wxCursor& cursor);
110 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
112 bool base_GiveFeedback(wxDragResult effect);
116 //---------------------------------------------------------------------------
118 // wxDropTarget should be associated with a window if it wants to be able to
119 // receive data via drag and drop.
121 // To use this class, you should derive from wxDropTarget and implement
122 // OnData() pure virtual method. You may also wish to override OnDrop() if you
123 // want to accept the data only inside some region of the window (this may
124 // avoid having to copy the data to this application which happens only when
125 // OnData() is called)
128 // Just a place holder for the type system. The real base class for
129 // wxPython is wxPyDropTarget
130 // class wxDropTarget {
136 class wxPyDropTarget : public wxDropTarget {
138 wxPyDropTarget(wxDataObject *dataObject = NULL)
139 : wxDropTarget(dataObject) {}
141 // called when mouse leaves the window: might be used to remove the
142 // feedback which was given in OnEnter()
143 DEC_PYCALLBACK__(OnLeave);
145 // called when the mouse enters the window (only once until OnLeave())
146 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
148 // called when the mouse moves in the window - shouldn't take long to
149 // execute or otherwise mouse movement would be too slow
150 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
152 // called after OnDrop() returns TRUE: you will usually just call
153 // GetData() from here and, probably, also refresh something to update the
154 // new data and, finally, return the code indicating how did the operation
155 // complete (returning default value in case of success and wxDragError on
156 // failure is usually ok)
157 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
159 // this function is called when data is dropped at position (x, y) - if it
160 // returns TRUE, OnData() will be called immediately afterwards which will
161 // allow to retrieve the data dropped.
162 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
167 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
168 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
169 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
170 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
171 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
176 %name(DropTarget) class wxPyDropTarget // : public wxDropTarget
179 %addtofunc wxPyDropTarget "if args: args[1].thisown = 0; self._setCallbackInfo(self, DropTarget)"
181 wxPyDropTarget(wxDataObject *dataObject = NULL);
182 void _setCallbackInfo(PyObject* self, PyObject* _class);
186 // get/set the associated wxDataObject
187 wxDataObject *GetDataObject();
188 %addtofunc SetDataObject "args[1].thisown = 0"
189 void SetDataObject(wxDataObject *dataObject);
191 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
192 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
194 bool base_OnDrop(wxCoord x, wxCoord y);
196 // may be called *only* from inside OnData() and will fill m_dataObject
197 // with the data from the drop source if it returns TRUE
203 %pythoncode { PyDropTarget = DropTarget }
205 //---------------------------------------------------------------------------
207 // A simple wxDropTarget derived class for text data: you only need to
208 // override OnDropText() to get something working
212 class wxPyTextDropTarget : public wxTextDropTarget {
214 wxPyTextDropTarget() {}
216 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
218 DEC_PYCALLBACK__(OnLeave);
219 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
220 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
221 DEC_PYCALLBACK_DR_2WXCDR(OnData);
222 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
227 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
228 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
229 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
230 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
231 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
232 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
236 %name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
238 %addtofunc wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
240 wxPyTextDropTarget();
241 void _setCallbackInfo(PyObject* self, PyObject* _class);
243 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
244 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
245 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
247 bool base_OnDrop(wxCoord x, wxCoord y);
248 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
251 //---------------------------------------------------------------------------
253 // A drop target which accepts files (dragged from File Manager or Explorer)
257 class wxPyFileDropTarget : public wxFileDropTarget {
259 wxPyFileDropTarget() {}
261 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
263 DEC_PYCALLBACK__(OnLeave);
264 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
265 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
266 DEC_PYCALLBACK_DR_2WXCDR(OnData);
267 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
272 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
273 const wxArrayString& filenames) {
275 wxPyBeginBlockThreads();
276 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
277 PyObject* list = wxArrayString2PyList_helper(filenames);
278 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
281 wxPyEndBlockThreads();
287 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
288 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
289 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
290 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
291 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
296 %name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
299 %addtofunc wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
301 wxPyFileDropTarget();
302 void _setCallbackInfo(PyObject* self, PyObject* _class);
304 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
305 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
306 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
308 bool base_OnDrop(wxCoord x, wxCoord y);
309 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
313 //---------------------------------------------------------------------------
315 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
316 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
317 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
318 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
320 //---------------------------------------------------------------------------