]>
Commit | Line | Data |
---|---|---|
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 | #ifndef __WXX11__ | |
18 | ||
19 | %newgroup | |
20 | ||
21 | // flags for wxDropSource::DoDragDrop() | |
22 | // | |
23 | // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1 | |
24 | // (== True) for compatibility with the old DoDragDrop(bool) method! | |
25 | enum | |
26 | { | |
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 | |
30 | }; | |
31 | ||
32 | // result of wxDropSource::DoDragDrop() call | |
33 | enum wxDragResult | |
34 | { | |
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) | |
41 | }; | |
42 | ||
43 | bool wxIsDragResultOk(wxDragResult res); | |
44 | ||
45 | //--------------------------------------------------------------------------- | |
46 | ||
47 | ||
48 | // wxDropSource is the object you need to create (and call DoDragDrop on it) | |
49 | // to initiate a drag-and-drop operation | |
50 | ||
51 | ||
52 | ||
53 | %{ | |
54 | IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback); | |
55 | %} | |
56 | ||
57 | ||
58 | %rename(DropSource) wxPyDropSource; | |
59 | class wxPyDropSource { | |
60 | public: | |
61 | %pythonAppend wxPyDropSource setCallbackInfo(DropSource) | |
62 | #ifndef __WXGTK__ | |
63 | wxPyDropSource(wxWindow *win, | |
64 | const wxCursor © = wxNullCursor, | |
65 | const wxCursor &move = wxNullCursor, | |
66 | const wxCursor &none = wxNullCursor); | |
67 | #else | |
68 | wxPyDropSource(wxWindow *win, | |
69 | const wxIcon& copy = wxNullIcon, | |
70 | const wxIcon& move = wxNullIcon, | |
71 | const wxIcon& none = wxNullIcon); | |
72 | #endif | |
73 | ||
74 | void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=0); | |
75 | ~wxPyDropSource(); | |
76 | ||
77 | // set the data which is transfered by drag and drop | |
78 | void SetData(wxDataObject& data); | |
79 | ||
80 | wxDataObject *GetDataObject(); | |
81 | ||
82 | // set the icon corresponding to given drag result | |
83 | void SetCursor(wxDragResult res, const wxCursor& cursor); | |
84 | ||
85 | wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); | |
86 | ||
87 | bool GiveFeedback(wxDragResult effect); | |
88 | %MAKE_BASE_FUNC(DropSource, GiveFeedback); | |
89 | ||
90 | %property(DataObject, GetDataObject, SetData, doc="See `GetDataObject` and `SetData`"); | |
91 | }; | |
92 | ||
93 | ||
94 | %pythoncode { | |
95 | def DROP_ICON(filename): | |
96 | """ | |
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. | |
100 | """ | |
101 | img = wx.Image(filename) | |
102 | if wx.Platform == '__WXGTK__': | |
103 | return wx.IconFromBitmap(wx.BitmapFromImage(img)) | |
104 | else: | |
105 | return wx.CursorFromImage(img) | |
106 | } | |
107 | ||
108 | ||
109 | //--------------------------------------------------------------------------- | |
110 | ||
111 | // wxDropTarget should be associated with a window if it wants to be able to | |
112 | // receive data via drag and drop. | |
113 | // | |
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) | |
119 | ||
120 | ||
121 | // Just a place holder for the type system. The real base class for | |
122 | // wxPython is wxPyDropTarget | |
123 | // class wxDropTarget { | |
124 | // public: | |
125 | // }; | |
126 | ||
127 | ||
128 | %{ | |
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); | |
134 | %} | |
135 | ||
136 | ||
137 | %rename(DropTarget) wxPyDropTarget; | |
138 | class wxPyDropTarget // : public wxDropTarget | |
139 | { | |
140 | public: | |
141 | %pythonAppend wxPyDropTarget setCallbackInfo(DropTarget) | |
142 | ||
143 | %disownarg( wxDataObject *dataObject ); | |
144 | ||
145 | wxPyDropTarget(wxDataObject *dataObject = NULL); | |
146 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
147 | ||
148 | ~wxPyDropTarget(); | |
149 | ||
150 | // get/set the associated wxDataObject | |
151 | wxDataObject *GetDataObject(); | |
152 | void SetDataObject(wxDataObject *dataObject); | |
153 | ||
154 | %cleardisown( wxDataObject *dataObject ); | |
155 | ||
156 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
157 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
158 | void OnLeave(); | |
159 | bool OnDrop(wxCoord x, wxCoord y); | |
160 | ||
161 | %MAKE_BASE_FUNC(DropTarget, OnEnter); | |
162 | %MAKE_BASE_FUNC(DropTarget, OnDragOver); | |
163 | %MAKE_BASE_FUNC(DropTarget, OnLeave); | |
164 | %MAKE_BASE_FUNC(DropTarget, OnDrop); | |
165 | ||
166 | ||
167 | // may be called *only* from inside OnData() and will fill m_dataObject | |
168 | // with the data from the drop source if it returns True | |
169 | bool GetData(); | |
170 | ||
171 | // sets the default action for drag and drop: | |
172 | // use wxDragMove or wxDragCopy to set deafult action to move or copy | |
173 | // and use wxDragNone (default) to set default action specified by | |
174 | // initialization of draging (see wxDropSourceBase::DoDragDrop()) | |
175 | void SetDefaultAction(wxDragResult action); | |
176 | ||
177 | // returns default action for drag and drop or | |
178 | // wxDragNone if this not specified | |
179 | wxDragResult GetDefaultAction(); | |
180 | ||
181 | %property(DataObject, GetDataObject, SetDataObject, doc="See `GetDataObject` and `SetDataObject`"); | |
182 | %property(DefaultAction, GetDefaultAction, SetDefaultAction, doc="See `GetDefaultAction` and `SetDefaultAction`"); | |
183 | }; | |
184 | ||
185 | ||
186 | %pythoncode { PyDropTarget = DropTarget } | |
187 | ||
188 | //--------------------------------------------------------------------------- | |
189 | ||
190 | // A simple wxDropTarget derived class for text data: you only need to | |
191 | // override OnDropText() to get something working | |
192 | ||
193 | ||
194 | %{ | |
195 | class wxPyTextDropTarget : public wxTextDropTarget { | |
196 | public: | |
197 | wxPyTextDropTarget() {} | |
198 | ||
199 | DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText); | |
200 | ||
201 | DEC_PYCALLBACK__(OnLeave); | |
202 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
203 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
204 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
205 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
206 | ||
207 | PYPRIVATE; | |
208 | }; | |
209 | ||
210 | IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText); | |
211 | IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave); | |
212 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter); | |
213 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver); | |
214 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData); | |
215 | IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop); | |
216 | ||
217 | %} | |
218 | ||
219 | %rename(TextDropTarget) wxPyTextDropTarget; | |
220 | class wxPyTextDropTarget : public wxPyDropTarget { | |
221 | public: | |
222 | %pythonAppend wxPyTextDropTarget setCallbackInfo(TextDropTarget) | |
223 | ||
224 | wxPyTextDropTarget(); | |
225 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
226 | ||
227 | bool OnDropText(wxCoord x, wxCoord y, const wxString& text); | |
228 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
229 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
230 | void OnLeave(); | |
231 | bool OnDrop(wxCoord x, wxCoord y); | |
232 | wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); | |
233 | ||
234 | %MAKE_BASE_FUNC(TextDropTarget, OnDropText); | |
235 | %MAKE_BASE_FUNC(TextDropTarget, OnEnter); | |
236 | %MAKE_BASE_FUNC(TextDropTarget, OnDragOver); | |
237 | %MAKE_BASE_FUNC(TextDropTarget, OnLeave); | |
238 | %MAKE_BASE_FUNC(TextDropTarget, OnDrop); | |
239 | %MAKE_BASE_FUNC(TextDropTarget, OnData); | |
240 | }; | |
241 | ||
242 | //--------------------------------------------------------------------------- | |
243 | ||
244 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
245 | ||
246 | ||
247 | %{ | |
248 | class wxPyFileDropTarget : public wxFileDropTarget { | |
249 | public: | |
250 | wxPyFileDropTarget() {} | |
251 | ||
252 | virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
253 | ||
254 | DEC_PYCALLBACK__(OnLeave); | |
255 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
256 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
257 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
258 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
259 | ||
260 | PYPRIVATE; | |
261 | }; | |
262 | ||
263 | bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, | |
264 | const wxArrayString& filenames) { | |
265 | bool rval = false; | |
266 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
267 | if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) { | |
268 | PyObject* list = wxArrayString2PyList_helper(filenames); | |
269 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list)); | |
270 | Py_DECREF(list); | |
271 | } | |
272 | wxPyEndBlockThreads(blocked); | |
273 | return rval; | |
274 | } | |
275 | ||
276 | ||
277 | ||
278 | IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave); | |
279 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter); | |
280 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver); | |
281 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData); | |
282 | IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop); | |
283 | ||
284 | %} | |
285 | ||
286 | ||
287 | %rename(FileDropTarget) wxPyFileDropTarget; | |
288 | class wxPyFileDropTarget : public wxPyDropTarget | |
289 | { | |
290 | public: | |
291 | %pythonAppend wxPyFileDropTarget setCallbackInfo(FileDropTarget) | |
292 | ||
293 | wxPyFileDropTarget(); | |
294 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
295 | ||
296 | bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
297 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
298 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
299 | void OnLeave(); | |
300 | bool OnDrop(wxCoord x, wxCoord y); | |
301 | wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); | |
302 | ||
303 | %MAKE_BASE_FUNC(FileDropTarget, OnDropFiles); | |
304 | %MAKE_BASE_FUNC(FileDropTarget, OnEnter); | |
305 | %MAKE_BASE_FUNC(FileDropTarget, OnDragOver); | |
306 | %MAKE_BASE_FUNC(FileDropTarget, OnLeave); | |
307 | %MAKE_BASE_FUNC(FileDropTarget, OnDrop); | |
308 | %MAKE_BASE_FUNC(FileDropTarget, OnData); | |
309 | }; | |
310 | ||
311 | ||
312 | //--------------------------------------------------------------------------- | |
313 | %init %{ | |
314 | wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource"); | |
315 | wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget"); | |
316 | wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget"); | |
317 | wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget"); | |
318 | %} | |
319 | //--------------------------------------------------------------------------- | |
320 | ||
321 | #endif |