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 //---------------------------------------------------------------------------
24 // flags for wxDropSource::DoDragDrop()
26 // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1
27 // (== True) for compatibility with the old DoDragDrop(bool) method!
30 wxDrag_CopyOnly = 0, // allow only copying
31 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
32 wxDrag_DefaultMove = 3 // the default operation is move, not copy
35 // result of wxDropSource::DoDragDrop() call
38 wxDragError, // error prevented the d&d operation from completing
39 wxDragNone, // drag target didn't accept the data
40 wxDragCopy, // the data was successfully copied
41 wxDragMove, // the data was successfully moved (MSW only)
42 wxDragLink, // operation is a drag-link
43 wxDragCancel // the operation was cancelled by user (not an error)
46 bool wxIsDragResultOk(wxDragResult res);
48 //---------------------------------------------------------------------------
51 // wxDropSource is the object you need to create (and call DoDragDrop on it)
52 // to initiate a drag-and-drop operation
57 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
61 %name(DropSource) class wxPyDropSource {
64 wxPyDropSource(wxWindow *win = NULL,
65 const wxCursor © = wxNullCursor,
66 const wxCursor &move = wxNullCursor,
67 const wxCursor &none = wxNullCursor);
69 wxPyDropSource(wxWindow *win = NULL,
70 const wxIcon& copy = wxNullIcon,
71 const wxIcon& move = wxNullIcon,
72 const wxIcon& none = wxNullIcon);
75 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
76 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
79 // set the data which is transfered by drag and drop
80 void SetData(wxDataObject& data);
82 wxDataObject *GetDataObject();
84 // set the icon corresponding to given drag result
85 void SetCursor(wxDragResult res, const wxCursor& cursor);
87 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
89 bool base_GiveFeedback(wxDragResult effect);
93 //---------------------------------------------------------------------------
95 // wxDropTarget should be associated with a window if it wants to be able to
96 // receive data via drag and drop.
98 // To use this class, you should derive from wxDropTarget and implement
99 // OnData() pure virtual method. You may also wish to override OnDrop() if you
100 // want to accept the data only inside some region of the window (this may
101 // avoid having to copy the data to this application which happens only when
102 // OnData() is called)
105 // Just a place holder for the type system. The real base class for
106 // wxPython is wxPyDropTarget
107 // class wxDropTarget {
113 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
114 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
115 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
116 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
117 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
121 %name(DropTarget) class wxPyDropTarget // : public wxDropTarget
124 %addtofunc wxPyDropTarget "if args: args[1].thisown = 0; self._setCallbackInfo(self, DropTarget)"
126 wxPyDropTarget(wxDataObject *dataObject = NULL);
127 void _setCallbackInfo(PyObject* self, PyObject* _class);
131 // get/set the associated wxDataObject
132 wxDataObject *GetDataObject();
133 %addtofunc SetDataObject "args[1].thisown = 0"
134 void SetDataObject(wxDataObject *dataObject);
136 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
137 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
139 bool base_OnDrop(wxCoord x, wxCoord y);
141 // may be called *only* from inside OnData() and will fill m_dataObject
142 // with the data from the drop source if it returns True
148 %pythoncode { PyDropTarget = DropTarget }
150 //---------------------------------------------------------------------------
152 // A simple wxDropTarget derived class for text data: you only need to
153 // override OnDropText() to get something working
157 class wxPyTextDropTarget : public wxTextDropTarget {
159 wxPyTextDropTarget() {}
161 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
163 DEC_PYCALLBACK__(OnLeave);
164 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
165 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
166 DEC_PYCALLBACK_DR_2WXCDR(OnData);
167 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
172 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
173 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
174 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
175 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
176 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
177 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
181 %name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
183 %addtofunc wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
185 wxPyTextDropTarget();
186 void _setCallbackInfo(PyObject* self, PyObject* _class);
188 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
189 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
190 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
192 bool base_OnDrop(wxCoord x, wxCoord y);
193 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
196 //---------------------------------------------------------------------------
198 // A drop target which accepts files (dragged from File Manager or Explorer)
202 class wxPyFileDropTarget : public wxFileDropTarget {
204 wxPyFileDropTarget() {}
206 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
208 DEC_PYCALLBACK__(OnLeave);
209 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
210 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
211 DEC_PYCALLBACK_DR_2WXCDR(OnData);
212 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
217 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
218 const wxArrayString& filenames) {
220 wxPyBeginBlockThreads();
221 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
222 PyObject* list = wxArrayString2PyList_helper(filenames);
223 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
226 wxPyEndBlockThreads();
232 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
233 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
234 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
235 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
236 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
241 %name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
244 %addtofunc wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
246 wxPyFileDropTarget();
247 void _setCallbackInfo(PyObject* self, PyObject* _class);
249 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
250 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
251 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
253 bool base_OnDrop(wxCoord x, wxCoord y);
254 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
258 //---------------------------------------------------------------------------
260 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
261 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
262 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
263 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
265 //---------------------------------------------------------------------------