]>
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); | |
0eae5d09 RD |
89 | |
90 | %property(DataObject, GetDataObject, SetData, doc="See `GetDataObject` and `SetData`"); | |
d14a1e28 RD |
91 | }; |
92 | ||
93 | ||
f66cece3 RD |
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 | ||
d14a1e28 RD |
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 | %{ | |
d14a1e28 RD |
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); | |
d14a1e28 RD |
134 | %} |
135 | ||
136 | ||
1b8c7ba6 RD |
137 | %rename(DropTarget) wxPyDropTarget; |
138 | class wxPyDropTarget // : public wxDropTarget | |
d14a1e28 RD |
139 | { |
140 | public: | |
2b9048c5 | 141 | %pythonAppend wxPyDropTarget |
8668c242 | 142 | "self._setCallbackInfo(self, DropTarget)" |
214c4fbe RD |
143 | |
144 | %disownarg( wxDataObject *dataObject ); | |
d14a1e28 RD |
145 | |
146 | wxPyDropTarget(wxDataObject *dataObject = NULL); | |
147 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
148 | ||
149 | ~wxPyDropTarget(); | |
150 | ||
151 | // get/set the associated wxDataObject | |
152 | wxDataObject *GetDataObject(); | |
d14a1e28 RD |
153 | void SetDataObject(wxDataObject *dataObject); |
154 | ||
214c4fbe | 155 | %cleardisown( wxDataObject *dataObject ); |
8668c242 | 156 | |
a7a01418 RD |
157 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); |
158 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
159 | void OnLeave(); | |
160 | bool OnDrop(wxCoord x, wxCoord y); | |
d14a1e28 | 161 | |
a7a01418 RD |
162 | %MAKE_BASE_FUNC(DropTarget, OnEnter); |
163 | %MAKE_BASE_FUNC(DropTarget, OnDragOver); | |
164 | %MAKE_BASE_FUNC(DropTarget, OnLeave); | |
165 | %MAKE_BASE_FUNC(DropTarget, OnDrop); | |
166 | ||
167 | ||
d14a1e28 | 168 | // may be called *only* from inside OnData() and will fill m_dataObject |
dd9f7fea | 169 | // with the data from the drop source if it returns True |
d14a1e28 RD |
170 | bool GetData(); |
171 | ||
303f572e RD |
172 | // sets the default action for drag and drop: |
173 | // use wxDragMove or wxDragCopy to set deafult action to move or copy | |
174 | // and use wxDragNone (default) to set default action specified by | |
175 | // initialization of draging (see wxDropSourceBase::DoDragDrop()) | |
176 | void SetDefaultAction(wxDragResult action); | |
177 | ||
178 | // returns default action for drag and drop or | |
179 | // wxDragNone if this not specified | |
180 | wxDragResult GetDefaultAction(); | |
0eae5d09 | 181 | |
0eae5d09 RD |
182 | %property(DataObject, GetDataObject, SetDataObject, doc="See `GetDataObject` and `SetDataObject`"); |
183 | %property(DefaultAction, GetDefaultAction, SetDefaultAction, doc="See `GetDefaultAction` and `SetDefaultAction`"); | |
d14a1e28 RD |
184 | }; |
185 | ||
186 | ||
187 | %pythoncode { PyDropTarget = DropTarget } | |
188 | ||
189 | //--------------------------------------------------------------------------- | |
190 | ||
191 | // A simple wxDropTarget derived class for text data: you only need to | |
192 | // override OnDropText() to get something working | |
193 | ||
194 | ||
195 | %{ | |
196 | class wxPyTextDropTarget : public wxTextDropTarget { | |
197 | public: | |
198 | wxPyTextDropTarget() {} | |
199 | ||
200 | DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText); | |
201 | ||
202 | DEC_PYCALLBACK__(OnLeave); | |
203 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
204 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
205 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
206 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
207 | ||
208 | PYPRIVATE; | |
209 | }; | |
210 | ||
211 | IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText); | |
212 | IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave); | |
213 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter); | |
214 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver); | |
215 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData); | |
216 | IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop); | |
217 | ||
218 | %} | |
219 | ||
1b8c7ba6 RD |
220 | %rename(TextDropTarget) wxPyTextDropTarget; |
221 | class wxPyTextDropTarget : public wxPyDropTarget { | |
d14a1e28 | 222 | public: |
2b9048c5 | 223 | %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)" |
d14a1e28 RD |
224 | |
225 | wxPyTextDropTarget(); | |
226 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
227 | ||
a7a01418 RD |
228 | bool OnDropText(wxCoord x, wxCoord y, const wxString& text); |
229 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
230 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
231 | void OnLeave(); | |
232 | bool OnDrop(wxCoord x, wxCoord y); | |
233 | wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); | |
234 | ||
235 | %MAKE_BASE_FUNC(TextDropTarget, OnDropText); | |
236 | %MAKE_BASE_FUNC(TextDropTarget, OnEnter); | |
237 | %MAKE_BASE_FUNC(TextDropTarget, OnDragOver); | |
238 | %MAKE_BASE_FUNC(TextDropTarget, OnLeave); | |
239 | %MAKE_BASE_FUNC(TextDropTarget, OnDrop); | |
240 | %MAKE_BASE_FUNC(TextDropTarget, OnData); | |
d14a1e28 RD |
241 | }; |
242 | ||
243 | //--------------------------------------------------------------------------- | |
244 | ||
245 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
246 | ||
247 | ||
248 | %{ | |
249 | class wxPyFileDropTarget : public wxFileDropTarget { | |
250 | public: | |
251 | wxPyFileDropTarget() {} | |
252 | ||
253 | virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
254 | ||
255 | DEC_PYCALLBACK__(OnLeave); | |
256 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
257 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
258 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
259 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
260 | ||
261 | PYPRIVATE; | |
262 | }; | |
263 | ||
264 | bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, | |
265 | const wxArrayString& filenames) { | |
a72f4631 | 266 | bool rval = false; |
6e6b3557 | 267 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
268 | if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) { |
269 | PyObject* list = wxArrayString2PyList_helper(filenames); | |
270 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list)); | |
271 | Py_DECREF(list); | |
272 | } | |
da32eb53 | 273 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
274 | return rval; |
275 | } | |
276 | ||
277 | ||
278 | ||
279 | IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave); | |
280 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter); | |
281 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver); | |
282 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData); | |
283 | IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop); | |
284 | ||
285 | %} | |
286 | ||
287 | ||
1b8c7ba6 RD |
288 | %rename(FileDropTarget) wxPyFileDropTarget; |
289 | class wxPyFileDropTarget : public wxPyDropTarget | |
d14a1e28 RD |
290 | { |
291 | public: | |
2b9048c5 | 292 | %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)" |
d14a1e28 RD |
293 | |
294 | wxPyFileDropTarget(); | |
295 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
296 | ||
a7a01418 RD |
297 | bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); |
298 | wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
299 | wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
300 | void OnLeave(); | |
301 | bool OnDrop(wxCoord x, wxCoord y); | |
302 | wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); | |
303 | ||
304 | %MAKE_BASE_FUNC(FileDropTarget, OnDropFiles); | |
305 | %MAKE_BASE_FUNC(FileDropTarget, OnEnter); | |
306 | %MAKE_BASE_FUNC(FileDropTarget, OnDragOver); | |
307 | %MAKE_BASE_FUNC(FileDropTarget, OnLeave); | |
308 | %MAKE_BASE_FUNC(FileDropTarget, OnDrop); | |
309 | %MAKE_BASE_FUNC(FileDropTarget, OnData); | |
d14a1e28 RD |
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 | //--------------------------------------------------------------------------- | |
f87da722 RD |
321 | |
322 | #endif |