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 %name(DropSource) class wxPyDropSource {
61 wxPyDropSource(wxWindow *win = NULL,
62 const wxCursor © = wxNullCursor,
63 const wxCursor &move = wxNullCursor,
64 const wxCursor &none = wxNullCursor);
66 wxPyDropSource(wxWindow *win = NULL,
67 const wxIcon& copy = wxNullIcon,
68 const wxIcon& move = wxNullIcon,
69 const wxIcon& none = wxNullIcon);
72 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
73 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
76 // set the data which is transfered by drag and drop
77 void SetData(wxDataObject& data);
79 wxDataObject *GetDataObject();
81 // set the icon corresponding to given drag result
82 void SetCursor(wxDragResult res, const wxCursor& cursor);
84 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
86 bool base_GiveFeedback(wxDragResult effect);
90 //---------------------------------------------------------------------------
92 // wxDropTarget should be associated with a window if it wants to be able to
93 // receive data via drag and drop.
95 // To use this class, you should derive from wxDropTarget and implement
96 // OnData() pure virtual method. You may also wish to override OnDrop() if you
97 // want to accept the data only inside some region of the window (this may
98 // avoid having to copy the data to this application which happens only when
99 // OnData() is called)
102 // Just a place holder for the type system. The real base class for
103 // wxPython is wxPyDropTarget
104 // class wxDropTarget {
110 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
111 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
112 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
113 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
114 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
118 %name(DropTarget) class wxPyDropTarget // : public wxDropTarget
121 %addtofunc wxPyDropTarget
122 "if args: args[0].thisown = 0;
123 self._setCallbackInfo(self, DropTarget)"
125 wxPyDropTarget(wxDataObject *dataObject = NULL);
126 void _setCallbackInfo(PyObject* self, PyObject* _class);
130 // get/set the associated wxDataObject
131 wxDataObject *GetDataObject();
132 %addtofunc SetDataObject "args[1].thisown = 0"
133 void SetDataObject(wxDataObject *dataObject);
135 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
136 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
138 bool base_OnDrop(wxCoord x, wxCoord y);
140 // may be called *only* from inside OnData() and will fill m_dataObject
141 // with the data from the drop source if it returns True
147 %pythoncode { PyDropTarget = DropTarget }
149 //---------------------------------------------------------------------------
151 // A simple wxDropTarget derived class for text data: you only need to
152 // override OnDropText() to get something working
156 class wxPyTextDropTarget : public wxTextDropTarget {
158 wxPyTextDropTarget() {}
160 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
162 DEC_PYCALLBACK__(OnLeave);
163 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
164 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
165 DEC_PYCALLBACK_DR_2WXCDR(OnData);
166 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
171 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
172 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
173 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
174 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
175 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
176 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
180 %name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
182 %addtofunc wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
184 wxPyTextDropTarget();
185 void _setCallbackInfo(PyObject* self, PyObject* _class);
187 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
188 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
189 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
191 bool base_OnDrop(wxCoord x, wxCoord y);
192 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
195 //---------------------------------------------------------------------------
197 // A drop target which accepts files (dragged from File Manager or Explorer)
201 class wxPyFileDropTarget : public wxFileDropTarget {
203 wxPyFileDropTarget() {}
205 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
207 DEC_PYCALLBACK__(OnLeave);
208 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
209 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
210 DEC_PYCALLBACK_DR_2WXCDR(OnData);
211 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
216 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
217 const wxArrayString& filenames) {
219 wxPyBeginBlockThreads();
220 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
221 PyObject* list = wxArrayString2PyList_helper(filenames);
222 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
225 wxPyEndBlockThreads();
231 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
232 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
233 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
234 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
235 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
240 %name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
243 %addtofunc wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
245 wxPyFileDropTarget();
246 void _setCallbackInfo(PyObject* self, PyObject* _class);
248 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
249 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
250 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
252 bool base_OnDrop(wxCoord x, wxCoord y);
253 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
257 //---------------------------------------------------------------------------
259 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
260 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
261 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
262 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
264 //---------------------------------------------------------------------------