]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _dnd.i | |
3 | // Purpose: SWIG definitions for the Drag-n-drop classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 31-October-1999 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | #include <wx/dnd.h> | |
20 | %} | |
21 | ||
22 | //--------------------------------------------------------------------------- | |
23 | %newgroup | |
24 | ||
25 | // flags for wxDropSource::DoDragDrop() | |
26 | // | |
dd9f7fea RD |
27 | // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1 |
28 | // (== True) for compatibility with the old DoDragDrop(bool) method! | |
d14a1e28 RD |
29 | enum |
30 | { | |
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 | |
34 | }; | |
35 | ||
36 | // result of wxDropSource::DoDragDrop() call | |
37 | enum wxDragResult | |
38 | { | |
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) | |
45 | }; | |
46 | ||
47 | bool wxIsDragResultOk(wxDragResult res); | |
48 | ||
49 | //--------------------------------------------------------------------------- | |
50 | ||
51 | ||
52 | // wxDropSource is the object you need to create (and call DoDragDrop on it) | |
53 | // to initiate a drag-and-drop operation | |
54 | ||
55 | ||
56 | ||
57 | %{ | |
58 | class wxPyDropSource : public wxDropSource { | |
59 | public: | |
60 | #ifndef __WXGTK__ | |
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) {} | |
66 | #else | |
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) {} | |
72 | #endif | |
73 | ~wxPyDropSource() { } | |
74 | ||
75 | DEC_PYCALLBACK_BOOL_DR(GiveFeedback); | |
76 | PYPRIVATE; | |
77 | }; | |
78 | ||
79 | IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback); | |
80 | ||
81 | %} | |
82 | ||
83 | ||
84 | %name(DropSource) class wxPyDropSource { | |
85 | public: | |
86 | #ifndef __WXGTK__ | |
87 | wxPyDropSource(wxWindow *win = NULL, | |
88 | const wxCursor © = wxNullCursor, | |
89 | const wxCursor &move = wxNullCursor, | |
90 | const wxCursor &none = wxNullCursor); | |
91 | #else | |
92 | wxPyDropSource(wxWindow *win = NULL, | |
93 | const wxIcon& copy = wxNullIcon, | |
94 | const wxIcon& move = wxNullIcon, | |
95 | const wxIcon& none = wxNullIcon); | |
96 | #endif | |
97 | ||
98 | void _setCallbackInfo(PyObject* self, PyObject* _class, int incref); | |
99 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)" | |
100 | ~wxPyDropSource(); | |
101 | ||
102 | // set the data which is transfered by drag and drop | |
103 | void SetData(wxDataObject& data); | |
104 | ||
105 | wxDataObject *GetDataObject(); | |
106 | ||
107 | // set the icon corresponding to given drag result | |
108 | void SetCursor(wxDragResult res, const wxCursor& cursor); | |
109 | ||
110 | wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); | |
111 | ||
112 | bool base_GiveFeedback(wxDragResult effect); | |
113 | }; | |
114 | ||
115 | ||
116 | //--------------------------------------------------------------------------- | |
117 | ||
118 | // wxDropTarget should be associated with a window if it wants to be able to | |
119 | // receive data via drag and drop. | |
120 | // | |
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) | |
126 | ||
127 | ||
128 | // Just a place holder for the type system. The real base class for | |
129 | // wxPython is wxPyDropTarget | |
130 | // class wxDropTarget { | |
131 | // public: | |
132 | // }; | |
133 | ||
134 | ||
135 | %{ | |
136 | class wxPyDropTarget : public wxDropTarget { | |
137 | public: | |
138 | wxPyDropTarget(wxDataObject *dataObject = NULL) | |
139 | : wxDropTarget(dataObject) {} | |
140 | ||
141 | // called when mouse leaves the window: might be used to remove the | |
142 | // feedback which was given in OnEnter() | |
143 | DEC_PYCALLBACK__(OnLeave); | |
144 | ||
145 | // called when the mouse enters the window (only once until OnLeave()) | |
146 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
147 | ||
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); | |
151 | ||
dd9f7fea | 152 | // called after OnDrop() returns True: you will usually just call |
d14a1e28 RD |
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); | |
158 | ||
159 | // this function is called when data is dropped at position (x, y) - if it | |
dd9f7fea | 160 | // returns True, OnData() will be called immediately afterwards which will |
d14a1e28 RD |
161 | // allow to retrieve the data dropped. |
162 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
163 | ||
164 | PYPRIVATE; | |
165 | }; | |
166 | ||
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); | |
172 | ||
173 | %} | |
174 | ||
175 | ||
176 | %name(DropTarget) class wxPyDropTarget // : public wxDropTarget | |
177 | { | |
178 | public: | |
179 | %addtofunc wxPyDropTarget "if args: args[1].thisown = 0; self._setCallbackInfo(self, DropTarget)" | |
180 | ||
181 | wxPyDropTarget(wxDataObject *dataObject = NULL); | |
182 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
183 | ||
184 | ~wxPyDropTarget(); | |
185 | ||
186 | // get/set the associated wxDataObject | |
187 | wxDataObject *GetDataObject(); | |
188 | %addtofunc SetDataObject "args[1].thisown = 0" | |
189 | void SetDataObject(wxDataObject *dataObject); | |
190 | ||
191 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
192 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
193 | void base_OnLeave(); | |
194 | bool base_OnDrop(wxCoord x, wxCoord y); | |
195 | ||
196 | // may be called *only* from inside OnData() and will fill m_dataObject | |
dd9f7fea | 197 | // with the data from the drop source if it returns True |
d14a1e28 RD |
198 | bool GetData(); |
199 | ||
200 | }; | |
201 | ||
202 | ||
203 | %pythoncode { PyDropTarget = DropTarget } | |
204 | ||
205 | //--------------------------------------------------------------------------- | |
206 | ||
207 | // A simple wxDropTarget derived class for text data: you only need to | |
208 | // override OnDropText() to get something working | |
209 | ||
210 | ||
211 | %{ | |
212 | class wxPyTextDropTarget : public wxTextDropTarget { | |
213 | public: | |
214 | wxPyTextDropTarget() {} | |
215 | ||
216 | DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText); | |
217 | ||
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); | |
223 | ||
224 | PYPRIVATE; | |
225 | }; | |
226 | ||
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); | |
233 | ||
234 | %} | |
235 | ||
236 | %name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget { | |
237 | public: | |
238 | %addtofunc wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)" | |
239 | ||
240 | wxPyTextDropTarget(); | |
241 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
242 | ||
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); | |
246 | void base_OnLeave(); | |
247 | bool base_OnDrop(wxCoord x, wxCoord y); | |
248 | wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); | |
249 | }; | |
250 | ||
251 | //--------------------------------------------------------------------------- | |
252 | ||
253 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
254 | ||
255 | ||
256 | %{ | |
257 | class wxPyFileDropTarget : public wxFileDropTarget { | |
258 | public: | |
259 | wxPyFileDropTarget() {} | |
260 | ||
261 | virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
262 | ||
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); | |
268 | ||
269 | PYPRIVATE; | |
270 | }; | |
271 | ||
272 | bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, | |
273 | const wxArrayString& filenames) { | |
dd9f7fea | 274 | bool rval = False; |
d14a1e28 RD |
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)); | |
279 | Py_DECREF(list); | |
280 | } | |
281 | wxPyEndBlockThreads(); | |
282 | return rval; | |
283 | } | |
284 | ||
285 | ||
286 | ||
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); | |
292 | ||
293 | %} | |
294 | ||
295 | ||
296 | %name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget | |
297 | { | |
298 | public: | |
299 | %addtofunc wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)" | |
300 | ||
301 | wxPyFileDropTarget(); | |
302 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
303 | ||
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); | |
307 | void base_OnLeave(); | |
308 | bool base_OnDrop(wxCoord x, wxCoord y); | |
309 | wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); | |
310 | }; | |
311 | ||
312 | ||
313 | //--------------------------------------------------------------------------- | |
314 | %init %{ | |
315 | wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource"); | |
316 | wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget"); | |
317 | wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget"); | |
318 | wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget"); | |
319 | %} | |
320 | //--------------------------------------------------------------------------- |