]>
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 | //--------------------------------------------------------------------------- | |
f87da722 | 17 | #ifndef __WXX11__ |
d14a1e28 | 18 | |
d14a1e28 RD |
19 | %newgroup |
20 | ||
21 | // flags for wxDropSource::DoDragDrop() | |
22 | // | |
dd9f7fea RD |
23 | // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1 |
24 | // (== True) for compatibility with the old DoDragDrop(bool) method! | |
d14a1e28 RD |
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 | %{ | |
d14a1e28 | 54 | IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback); |
d14a1e28 RD |
55 | %} |
56 | ||
57 | ||
1b8c7ba6 RD |
58 | %rename(DropSource) wxPyDropSource; |
59 | class wxPyDropSource { | |
d14a1e28 | 60 | public: |
864a91c8 | 61 | %pythonAppend wxPyDropSource "self._setCallbackInfo(self, DropSource, 0)" |
d14a1e28 | 62 | #ifndef __WXGTK__ |
e6477984 | 63 | wxPyDropSource(wxWindow *win, |
d14a1e28 RD |
64 | const wxCursor © = wxNullCursor, |
65 | const wxCursor &move = wxNullCursor, | |
66 | const wxCursor &none = wxNullCursor); | |
67 | #else | |
e6477984 | 68 | wxPyDropSource(wxWindow *win, |
d14a1e28 RD |
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); | |
d14a1e28 RD |
75 | ~wxPyDropSource(); |
76 | ||
77 | // set the data which is transfered by drag and drop | |
78 | void SetData(wxDataObject& data); | |
864a91c8 | 79 | |
d14a1e28 | 80 | wxDataObject *GetDataObject(); |
864a91c8 | 81 | |
d14a1e28 RD |
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 | ||
a7a01418 RD |
87 | bool GiveFeedback(wxDragResult effect); |
88 | %MAKE_BASE_FUNC(DropSource, GiveFeedback); | |
d14a1e28 RD |
89 | }; |
90 | ||
91 | ||
f66cece3 RD |
92 | %pythoncode { |
93 | def DROP_ICON(filename): | |
94 | """ | |
95 | Returns either a `wx.Cursor` or `wx.Icon` created from the image file | |
96 | ``filename``. This function is useful with the `wx.DropSource` class | |
97 | which, depending on platform accepts either a icon or a cursor. | |
98 | """ | |
99 | img = wx.Image(filename) | |
100 | if wx.Platform == '__WXGTK__': | |
101 | return wx.IconFromBitmap(wx.BitmapFromImage(img)) | |
102 | else: | |
103 | return wx.CursorFromImage(img) | |
104 | } | |
105 | ||
106 | ||
d14a1e28 RD |
107 | //--------------------------------------------------------------------------- |
108 | ||
109 | // wxDropTarget should be associated with a window if it wants to be able to | |
110 | // receive data via drag and drop. | |
111 | // | |
112 | // To use this class, you should derive from wxDropTarget and implement | |
113 | // OnData() pure virtual method. You may also wish to override OnDrop() if you | |
114 | // want to accept the data only inside some region of the window (this may | |
115 | // avoid having to copy the data to this application which happens only when | |
116 | // OnData() is called) | |
117 | ||
118 | ||
119 | // Just a place holder for the type system. The real base class for | |
120 | // wxPython is wxPyDropTarget | |
121 | // class wxDropTarget { | |
122 | // public: | |
123 | // }; | |
124 | ||
125 | ||
126 | %{ | |
d14a1e28 RD |
127 | IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave); |
128 | IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter); | |
129 | IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver); | |
130 | IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData); | |
131 | IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop); | |
d14a1e28 RD |
132 | %} |
133 | ||
134 | ||
1b8c7ba6 RD |
135 | %rename(DropTarget) wxPyDropTarget; |
136 | class wxPyDropTarget // : public wxDropTarget | |
d14a1e28 RD |
137 | { |
138 | public: | |
2b9048c5 | 139 | %pythonAppend wxPyDropTarget |
8668c242 | 140 | "self._setCallbackInfo(self, DropTarget)" |
214c4fbe RD |
141 | |
142 | %disownarg( wxDataObject *dataObject ); | |
d14a1e28 RD |
143 | |
144 | wxPyDropTarget(wxDataObject *dataObject = NULL); | |
145 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
146 | ||
147 | ~wxPyDropTarget(); | |
148 | ||
149 | // get/set the associated wxDataObject | |
150 | wxDataObject *GetDataObject(); | |
d14a1e28 RD |
151 | void SetDataObject(wxDataObject *dataObject); |
152 | ||
214c4fbe | 153 | %cleardisown( wxDataObject *dataObject ); |
8668c242 | 154 | |
a7a01418 RD |
155 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); |
156 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
157 | void OnLeave(); | |
158 | bool OnDrop(wxCoord x, wxCoord y); | |
d14a1e28 | 159 | |
a7a01418 RD |
160 | %MAKE_BASE_FUNC(DropTarget, OnEnter); |
161 | %MAKE_BASE_FUNC(DropTarget, OnDragOver); | |
162 | %MAKE_BASE_FUNC(DropTarget, OnLeave); | |
163 | %MAKE_BASE_FUNC(DropTarget, OnDrop); | |
164 | ||
165 | ||
d14a1e28 | 166 | // may be called *only* from inside OnData() and will fill m_dataObject |
dd9f7fea | 167 | // with the data from the drop source if it returns True |
d14a1e28 RD |
168 | bool GetData(); |
169 | ||
303f572e RD |
170 | // sets the default action for drag and drop: |
171 | // use wxDragMove or wxDragCopy to set deafult action to move or copy | |
172 | // and use wxDragNone (default) to set default action specified by | |
173 | // initialization of draging (see wxDropSourceBase::DoDragDrop()) | |
174 | void SetDefaultAction(wxDragResult action); | |
175 | ||
176 | // returns default action for drag and drop or | |
177 | // wxDragNone if this not specified | |
178 | wxDragResult GetDefaultAction(); | |
d14a1e28 RD |
179 | }; |
180 | ||
181 | ||
182 | %pythoncode { PyDropTarget = DropTarget } | |
183 | ||
184 | //--------------------------------------------------------------------------- | |
185 | ||
186 | // A simple wxDropTarget derived class for text data: you only need to | |
187 | // override OnDropText() to get something working | |
188 | ||
189 | ||
190 | %{ | |
191 | class wxPyTextDropTarget : public wxTextDropTarget { | |
192 | public: | |
193 | wxPyTextDropTarget() {} | |
194 | ||
195 | DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText); | |
196 | ||
197 | DEC_PYCALLBACK__(OnLeave); | |
198 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
199 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
200 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
201 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
202 | ||
203 | PYPRIVATE; | |
204 | }; | |
205 | ||
206 | IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText); | |
207 | IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave); | |
208 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter); | |
209 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver); | |
210 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData); | |
211 | IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop); | |
212 | ||
213 | %} | |
214 | ||
1b8c7ba6 RD |
215 | %rename(TextDropTarget) wxPyTextDropTarget; |
216 | class wxPyTextDropTarget : public wxPyDropTarget { | |
d14a1e28 | 217 | public: |
2b9048c5 | 218 | %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)" |
d14a1e28 RD |
219 | |
220 | wxPyTextDropTarget(); | |
221 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
222 | ||
a7a01418 RD |
223 | bool OnDropText(wxCoord x, wxCoord y, const wxString& text); |
224 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
225 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
226 | void OnLeave(); | |
227 | bool OnDrop(wxCoord x, wxCoord y); | |
228 | wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); | |
229 | ||
230 | %MAKE_BASE_FUNC(TextDropTarget, OnDropText); | |
231 | %MAKE_BASE_FUNC(TextDropTarget, OnEnter); | |
232 | %MAKE_BASE_FUNC(TextDropTarget, OnDragOver); | |
233 | %MAKE_BASE_FUNC(TextDropTarget, OnLeave); | |
234 | %MAKE_BASE_FUNC(TextDropTarget, OnDrop); | |
235 | %MAKE_BASE_FUNC(TextDropTarget, OnData); | |
d14a1e28 RD |
236 | }; |
237 | ||
238 | //--------------------------------------------------------------------------- | |
239 | ||
240 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
241 | ||
242 | ||
243 | %{ | |
244 | class wxPyFileDropTarget : public wxFileDropTarget { | |
245 | public: | |
246 | wxPyFileDropTarget() {} | |
247 | ||
248 | virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
249 | ||
250 | DEC_PYCALLBACK__(OnLeave); | |
251 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
252 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
253 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
254 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
255 | ||
256 | PYPRIVATE; | |
257 | }; | |
258 | ||
259 | bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, | |
260 | const wxArrayString& filenames) { | |
a72f4631 | 261 | bool rval = false; |
6e6b3557 | 262 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
263 | if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) { |
264 | PyObject* list = wxArrayString2PyList_helper(filenames); | |
265 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list)); | |
266 | Py_DECREF(list); | |
267 | } | |
da32eb53 | 268 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
269 | return rval; |
270 | } | |
271 | ||
272 | ||
273 | ||
274 | IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave); | |
275 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter); | |
276 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver); | |
277 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData); | |
278 | IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop); | |
279 | ||
280 | %} | |
281 | ||
282 | ||
1b8c7ba6 RD |
283 | %rename(FileDropTarget) wxPyFileDropTarget; |
284 | class wxPyFileDropTarget : public wxPyDropTarget | |
d14a1e28 RD |
285 | { |
286 | public: | |
2b9048c5 | 287 | %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)" |
d14a1e28 RD |
288 | |
289 | wxPyFileDropTarget(); | |
290 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
291 | ||
a7a01418 RD |
292 | bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); |
293 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
294 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
295 | void OnLeave(); | |
296 | bool OnDrop(wxCoord x, wxCoord y); | |
297 | wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); | |
298 | ||
299 | %MAKE_BASE_FUNC(FileDropTarget, OnDropFiles); | |
300 | %MAKE_BASE_FUNC(FileDropTarget, OnEnter); | |
301 | %MAKE_BASE_FUNC(FileDropTarget, OnDragOver); | |
302 | %MAKE_BASE_FUNC(FileDropTarget, OnLeave); | |
303 | %MAKE_BASE_FUNC(FileDropTarget, OnDrop); | |
304 | %MAKE_BASE_FUNC(FileDropTarget, OnData); | |
d14a1e28 RD |
305 | }; |
306 | ||
307 | ||
308 | //--------------------------------------------------------------------------- | |
309 | %init %{ | |
310 | wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource"); | |
311 | wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget"); | |
312 | wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget"); | |
313 | wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget"); | |
314 | %} | |
315 | //--------------------------------------------------------------------------- | |
f87da722 RD |
316 | |
317 | #endif |