]>
Commit | Line | Data |
---|---|---|
b1462dfa RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: clip_dnd.i | |
3 | // Purpose: SWIG definitions for the Clipboard and Drag-n-drop classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 31-October-1999 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1999 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | ||
14 | %module clip_dnd | |
15 | ||
16 | %{ | |
17 | #include "helpers.h" | |
18 | #include <wx/dataobj.h> | |
19 | #include <wx/clipbrd.h> | |
20 | #include <wx/dnd.h> | |
21 | %} | |
22 | ||
23 | //---------------------------------------------------------------------- | |
24 | ||
25 | %include typemaps.i | |
26 | %include my_typemaps.i | |
27 | ||
28 | // Import some definitions of other classes, etc. | |
29 | %import _defs.i | |
30 | %import misc.i | |
31 | %import gdi.i | |
32 | ||
33 | ||
34 | %pragma(python) code = "import wx" | |
35 | ||
36 | //---------------------------------------------------------------------- | |
37 | ||
38 | ||
39 | enum wxDataFormatId | |
40 | { | |
41 | wxDF_INVALID = 0, | |
42 | wxDF_TEXT = 1, /* CF_TEXT */ | |
43 | wxDF_BITMAP = 2, /* CF_BITMAP */ | |
44 | wxDF_METAFILE = 3, /* CF_METAFILEPICT */ | |
45 | wxDF_SYLK = 4, | |
46 | wxDF_DIF = 5, | |
47 | wxDF_TIFF = 6, | |
48 | wxDF_OEMTEXT = 7, /* CF_OEMTEXT */ | |
49 | wxDF_DIB = 8, /* CF_DIB */ | |
50 | wxDF_PALETTE = 9, | |
51 | wxDF_PENDATA = 10, | |
52 | wxDF_RIFF = 11, | |
53 | wxDF_WAVE = 12, | |
54 | wxDF_UNICODETEXT = 13, | |
55 | wxDF_ENHMETAFILE = 14, | |
56 | wxDF_FILENAME = 15, /* CF_HDROP */ | |
57 | wxDF_LOCALE = 16, | |
58 | wxDF_PRIVATE = 20, | |
59 | wxDF_MAX | |
60 | }; | |
61 | ||
62 | //---------------------------------------------------------------------- | |
63 | ||
64 | class wxDataFormat { | |
65 | public: | |
66 | wxDataFormat( wxDataFormatId type ); | |
67 | ~wxDataFormat(); | |
68 | ||
69 | void SetType(wxDataFormatId format); | |
70 | wxDataFormatId GetType() const; | |
71 | ||
72 | wxString GetId() const; | |
73 | void SetId(const char *format); | |
74 | }; | |
75 | ||
76 | %new wxDataFormat* wxCustomDataFormat(const wxString &id); | |
77 | %{ // An alternate constructor... | |
78 | wxDataFormat* wxCustomDataFormat(const wxString &id) { | |
79 | return new wxDataFormat(id); | |
80 | } | |
81 | %} | |
82 | ||
83 | ||
84 | %{ | |
85 | wxDataFormat wxPyFormatInvalid; | |
86 | %} | |
87 | %readonly | |
88 | %name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid; | |
89 | %readwrite | |
90 | ||
91 | ||
92 | //---------------------------------------------------------------------- | |
93 | ||
94 | ||
95 | ||
96 | class wxDataObject { // An abstract base class | |
97 | public: | |
98 | enum Direction { | |
99 | Get = 0x01, // format is supported by GetDataHere() | |
100 | Set = 0x02, // format is supported by SetData() | |
101 | Both = 0x03 // format is supported by both (unused currently) | |
102 | }; | |
103 | ||
104 | ~wxDataObject(); | |
105 | ||
106 | wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get); | |
107 | size_t GetFormatCount(Direction dir = wxDataObject::Get); | |
108 | void GetAllFormats(wxDataFormat *formats, | |
109 | Direction dir = wxDataObject::Get); | |
110 | size_t GetDataSize(const wxDataFormat& format); | |
111 | bool GetDataHere(const wxDataFormat& format, void *buf); | |
112 | bool SetData(const wxDataFormat& format, | |
113 | size_t len, const void * buf); | |
114 | bool IsSupportedFormat(const wxDataFormat& format); | |
115 | }; | |
116 | ||
117 | //---------------------------------------------------------------------- | |
118 | ||
119 | class wxDataObjectSimple : public wxDataObject { | |
120 | public: | |
121 | wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid); | |
122 | ||
123 | const wxDataFormat& GetFormat(); | |
124 | void SetFormat(const wxDataFormat& format); | |
125 | ||
126 | }; | |
127 | ||
128 | ||
129 | %{ // Create a new class for wxPython to use | |
130 | class wxPyDataObjectSimple : public wxDataObjectSimple { | |
131 | public: | |
132 | wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid) | |
133 | : wxDataObjectSimple(format) {} | |
134 | ||
135 | DEC_PYCALLBACK_SIZET_(GetDataSize); | |
136 | bool GetDataHere(void *buf); | |
137 | bool SetData(size_t len, const void *buf); | |
138 | PYPRIVATE; | |
139 | }; | |
140 | ||
141 | IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize); | |
142 | ||
143 | bool wxPyDataObjectSimple::GetDataHere(void *buf) { | |
144 | // We need to get the data for this object and write it to buf. I think | |
145 | // the best way to do this for wxPython is to have the Python method | |
146 | // return either a string or None and then act appropriately with the | |
147 | // C++ version. | |
148 | ||
149 | bool rval = FALSE; | |
19a97bd6 | 150 | wxPyTState* state = wxPyBeginBlockThreads(); |
b1462dfa RD |
151 | if (m_myInst.findCallback("GetDataHere")) { |
152 | PyObject* ro; | |
153 | ro = m_myInst.callCallbackObj(Py_BuildValue("()")); | |
f6bcfd97 BP |
154 | if (ro) { |
155 | rval = (ro != Py_None && PyString_Check(ro)); | |
156 | if (rval) | |
157 | memcpy(buf, PyString_AsString(ro), PyString_Size(ro)); | |
158 | Py_DECREF(ro); | |
159 | } | |
b1462dfa | 160 | } |
19a97bd6 | 161 | wxPyEndBlockThreads(state); |
b1462dfa RD |
162 | return rval; |
163 | } | |
164 | ||
165 | bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) { | |
166 | // For this one we simply need to make a string from buf and len | |
167 | // and send it to the Python method. | |
168 | bool rval = FALSE; | |
19a97bd6 | 169 | wxPyTState* state = wxPyBeginBlockThreads(); |
b1462dfa RD |
170 | if (m_myInst.findCallback("SetData")) { |
171 | PyObject* data = PyString_FromStringAndSize((char*)buf, len); | |
172 | rval = m_myInst.callCallback(Py_BuildValue("(O)", data)); | |
173 | Py_DECREF(data); | |
174 | } | |
19a97bd6 | 175 | wxPyEndBlockThreads(state); |
b1462dfa RD |
176 | return rval; |
177 | } | |
178 | %} | |
179 | ||
180 | ||
181 | ||
182 | // Now define it for SWIG | |
183 | class wxPyDataObjectSimple : public wxDataObjectSimple { | |
184 | public: | |
185 | wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid); | |
0122b7e3 RD |
186 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
187 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)" | |
b1462dfa RD |
188 | }; |
189 | ||
190 | //---------------------------------------------------------------------- | |
191 | ||
192 | class wxDataObjectComposite : public wxDataObject { | |
193 | public: | |
194 | wxDataObjectComposite(); | |
195 | ||
196 | void Add(wxDataObjectSimple *dataObject, int preferred = FALSE); | |
197 | %pragma(python) addtomethod = "Add:_args[0].thisown = 0" | |
198 | ||
199 | }; | |
200 | ||
201 | ||
202 | //---------------------------------------------------------------------- | |
203 | ||
204 | class wxTextDataObject : public wxDataObjectSimple { | |
205 | public: | |
206 | wxTextDataObject(const wxString& text = wxEmptyString); | |
207 | ||
208 | size_t GetTextLength(); | |
209 | wxString GetText(); | |
210 | void SetText(const wxString& text); | |
211 | }; | |
212 | ||
213 | ||
214 | ||
215 | %{ // Create a new class for wxPython to use | |
216 | class wxPyTextDataObject : public wxTextDataObject { | |
217 | public: | |
218 | wxPyTextDataObject(const wxString& text = wxEmptyString) | |
219 | : wxTextDataObject(text) {} | |
220 | ||
221 | DEC_PYCALLBACK_SIZET_(GetTextLength); | |
222 | DEC_PYCALLBACK_STRING_(GetText); | |
223 | DEC_PYCALLBACK__STRING(SetText); | |
224 | PYPRIVATE; | |
225 | }; | |
226 | ||
227 | IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength); | |
228 | IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText); | |
229 | IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText); | |
230 | ||
231 | %} | |
232 | ||
233 | ||
234 | // Now define it for SWIG | |
235 | class wxPyTextDataObject : public wxTextDataObject { | |
236 | public: | |
237 | wxPyTextDataObject(const wxString& text = wxEmptyString); | |
0122b7e3 RD |
238 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
239 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)" | |
b1462dfa RD |
240 | }; |
241 | ||
242 | //---------------------------------------------------------------------- | |
243 | ||
244 | class wxBitmapDataObject : public wxDataObjectSimple { | |
245 | public: | |
246 | wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap); | |
247 | ||
248 | wxBitmap GetBitmap(); | |
249 | void SetBitmap(const wxBitmap& bitmap); | |
250 | }; | |
251 | ||
252 | ||
253 | ||
254 | %{ // Create a new class for wxPython to use | |
255 | class wxPyBitmapDataObject : public wxBitmapDataObject { | |
256 | public: | |
257 | wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap) | |
258 | : wxBitmapDataObject(bitmap) {} | |
259 | ||
260 | wxBitmap GetBitmap(); | |
261 | void SetBitmap(const wxBitmap& bitmap); | |
262 | PYPRIVATE; | |
263 | }; | |
264 | ||
265 | wxBitmap wxPyBitmapDataObject::GetBitmap() { | |
266 | wxBitmap* rval = &wxNullBitmap; | |
19a97bd6 | 267 | wxPyTState* state = wxPyBeginBlockThreads(); |
b1462dfa RD |
268 | if (m_myInst.findCallback("GetBitmap")) { |
269 | PyObject* ro; | |
270 | wxBitmap* ptr; | |
271 | ro = m_myInst.callCallbackObj(Py_BuildValue("()")); | |
f6bcfd97 BP |
272 | if (ro) { |
273 | if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p")) | |
274 | rval = ptr; | |
275 | Py_DECREF(ro); | |
276 | } | |
b1462dfa | 277 | } |
19a97bd6 | 278 | wxPyEndBlockThreads(state); |
b1462dfa RD |
279 | return *rval; |
280 | } | |
281 | ||
282 | void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) { | |
19a97bd6 | 283 | wxPyTState* state = wxPyBeginBlockThreads(); |
b1462dfa RD |
284 | if (m_myInst.findCallback("SetBitmap")) { |
285 | m_myInst.callCallback(Py_BuildValue("(O)", | |
286 | wxPyConstructObject((void*)&bitmap, "wxBitmap"))); | |
287 | } | |
19a97bd6 | 288 | wxPyEndBlockThreads(state); |
b1462dfa RD |
289 | } |
290 | %} | |
291 | ||
292 | ||
293 | ||
294 | // Now define it for SWIG | |
295 | class wxPyBitmapDataObject : public wxBitmapDataObject { | |
296 | public: | |
297 | wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap); | |
0122b7e3 RD |
298 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
299 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)" | |
b1462dfa RD |
300 | }; |
301 | ||
302 | ||
303 | //---------------------------------------------------------------------- | |
304 | ||
305 | class wxFileDataObject : public wxDataObjectSimple | |
306 | { | |
307 | public: | |
308 | wxFileDataObject(); | |
309 | ||
310 | //const wxArrayString& GetFilenames(); | |
311 | %addmethods { | |
312 | PyObject* GetFilenames() { | |
313 | const wxArrayString& strings = self->GetFilenames(); | |
314 | PyObject* list = PyList_New(0); | |
315 | for (size_t x=0; x<strings.GetCount(); x++) | |
316 | PyList_Append(list, PyString_FromString(strings[x])); | |
317 | return list; | |
318 | } | |
319 | } | |
3ca6a5f0 BP |
320 | #ifdef __WXMSW__ |
321 | void AddFile(const wxString &filename); | |
322 | #endif | |
b1462dfa RD |
323 | }; |
324 | ||
325 | ||
326 | //---------------------------------------------------------------------- | |
327 | ||
328 | class wxCustomDataObject : public wxDataObjectSimple { | |
329 | public: | |
330 | wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid); | |
331 | ||
332 | //void TakeData(size_t size, void *data); | |
333 | //bool SetData(size_t size, const void *buf); | |
334 | %addmethods { | |
335 | void TakeData(PyObject* data) { | |
336 | if (PyString_Check(data)) { | |
337 | self->SetData(PyString_Size(data), PyString_AsString(data)); | |
338 | } | |
339 | } | |
340 | bool SetData(PyObject* data) { | |
341 | if (PyString_Check(data)) { | |
342 | return self->SetData(PyString_Size(data), PyString_AsString(data)); | |
343 | } | |
344 | return FALSE; | |
345 | } | |
346 | } | |
347 | ||
348 | size_t GetSize(); | |
c368d904 | 349 | |
b1462dfa RD |
350 | //void *GetData(); |
351 | %addmethods { | |
352 | PyObject* GetData() { | |
353 | return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize()); | |
354 | } | |
355 | } | |
356 | ||
357 | ||
358 | }; | |
359 | ||
360 | ||
c9a1416a RD |
361 | //---------------------------------------------------------------------- |
362 | ||
363 | class wxURLDataObject : public wxDataObjectComposite { | |
364 | public: | |
365 | wxURLDataObject(); | |
366 | ||
367 | wxString GetURL(); | |
368 | void SetURL(const wxString& url); | |
369 | }; | |
b1462dfa RD |
370 | |
371 | //---------------------------------------------------------------------- | |
372 | //---------------------------------------------------------------------- | |
373 | //---------------------------------------------------------------------- | |
374 | ||
9416aa89 | 375 | class wxClipboard : public wxObject { |
b1462dfa RD |
376 | public: |
377 | wxClipboard(); | |
378 | ||
379 | bool Open(); | |
380 | void Close(); | |
381 | bool IsOpened() const; | |
382 | ||
383 | bool AddData( wxDataObject *data ); | |
384 | %pragma(python) addtomethod = "AddData:_args[0].thisown = 0" | |
385 | bool SetData( wxDataObject *data ); | |
386 | %pragma(python) addtomethod = "SetData:_args[0].thisown = 0" | |
387 | ||
388 | bool IsSupported( const wxDataFormat& format ); | |
389 | bool GetData( wxDataObject& data ); | |
390 | void Clear(); | |
391 | bool Flush(); | |
392 | void UsePrimarySelection( int primary = FALSE ); | |
393 | }; | |
394 | ||
395 | %{ | |
6999b0d8 | 396 | // See below in the init function... |
b1462dfa RD |
397 | wxClipboard* wxPyTheClipboard; |
398 | %} | |
399 | %readonly | |
400 | %name(wxTheClipboard) wxClipboard* wxPyTheClipboard; | |
401 | %readwrite | |
402 | ||
403 | //---------------------------------------------------------------------- | |
404 | //---------------------------------------------------------------------- | |
405 | ||
406 | enum wxDragResult | |
407 | { | |
408 | wxDragError, // error prevented the d&d operation from completing | |
409 | wxDragNone, // drag target didn't accept the data | |
410 | wxDragCopy, // the data was successfully copied | |
411 | wxDragMove, // the data was successfully moved (MSW only) | |
c9a1416a | 412 | wxDragLink, // operation is a drag-link |
b1462dfa RD |
413 | wxDragCancel // the operation was cancelled by user (not an error) |
414 | }; | |
415 | ||
416 | bool wxIsDragResultOk(wxDragResult res); | |
417 | ||
418 | //---------------------------------------------------------------------- | |
419 | %{ | |
420 | class wxPyDropSource : public wxDropSource { | |
421 | public: | |
4120ef2b | 422 | #ifdef __WXMSW__ |
b1462dfa RD |
423 | wxPyDropSource(wxWindow *win = NULL, |
424 | const wxCursor &cursorCopy = wxNullCursor, | |
425 | const wxCursor &cursorMove = wxNullCursor, | |
426 | const wxCursor &cursorStop = wxNullCursor) | |
427 | : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {} | |
4120ef2b RD |
428 | #else |
429 | wxPyDropSource(wxWindow *win = NULL, | |
430 | const wxIcon &go = wxNullIcon) | |
431 | : wxDropSource(win, go) {} | |
432 | #endif | |
077def0b | 433 | ~wxPyDropSource() { } |
dafb483b | 434 | |
b1462dfa RD |
435 | DEC_PYCALLBACK_BOOL_DR(GiveFeedback); |
436 | PYPRIVATE; | |
437 | }; | |
438 | ||
439 | IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback); | |
440 | ||
441 | %} | |
442 | ||
443 | ||
444 | %name(wxDropSource) class wxPyDropSource { | |
445 | public: | |
4120ef2b | 446 | #ifdef __WXMSW__ |
b1462dfa RD |
447 | wxPyDropSource(wxWindow *win = NULL, |
448 | const wxCursor &cursorCopy = wxNullCursor, | |
449 | const wxCursor &cursorMove = wxNullCursor, | |
450 | const wxCursor &cursorStop = wxNullCursor); | |
4120ef2b RD |
451 | #else |
452 | wxPyDropSource(wxWindow *win = NULL, | |
453 | const wxIcon &go = wxNullIcon); | |
454 | #endif | |
455 | ||
0122b7e3 RD |
456 | void _setCallbackInfo(PyObject* self, PyObject* _class, int incref); |
457 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)" | |
b1462dfa RD |
458 | ~wxPyDropSource(); |
459 | ||
460 | void SetData(wxDataObject& data); | |
461 | wxDataObject *GetDataObject(); | |
462 | void SetCursor(wxDragResult res, const wxCursor& cursor); | |
463 | wxDragResult DoDragDrop(int bAllowMove = FALSE); | |
464 | ||
465 | bool base_GiveFeedback(wxDragResult effect); | |
466 | }; | |
467 | ||
468 | //---------------------------------------------------------------------- | |
469 | ||
470 | // Just a place holder for the type system. The real base class for | |
471 | // wxPython is wxPyDropTarget | |
472 | class wxDropTarget { | |
473 | public: | |
474 | }; | |
475 | ||
476 | ||
477 | %{ | |
478 | class wxPyDropTarget : public wxDropTarget { | |
479 | public: | |
480 | wxPyDropTarget(wxDataObject *dataObject = NULL) | |
481 | : wxDropTarget(dataObject) {} | |
482 | ||
483 | // DEC_PYCALLBACK_SIZET_(GetFormatCount); | |
484 | // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat); | |
485 | ||
486 | DEC_PYCALLBACK__(OnLeave); | |
487 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
488 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
489 | DEC_PYCALLBACK_DR_2WXCDR_pure(OnData); | |
490 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
491 | ||
492 | PYPRIVATE; | |
493 | }; | |
494 | ||
495 | // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount); | |
496 | // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat); | |
497 | ||
498 | IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave); | |
499 | IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter); | |
500 | IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver); | |
501 | IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData); | |
502 | IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop); | |
503 | ||
504 | %} | |
505 | ||
506 | ||
507 | class wxPyDropTarget : public wxDropTarget { | |
508 | public: | |
509 | wxPyDropTarget(wxDataObject *dataObject = NULL); | |
510 | %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0" | |
0122b7e3 RD |
511 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
512 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)" | |
b1462dfa RD |
513 | |
514 | ~wxPyDropTarget(); | |
515 | ||
516 | wxDataObject *GetDataObject(); | |
517 | void SetDataObject(wxDataObject *dataObject); | |
518 | %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0" | |
519 | ||
520 | // size_t base_GetFormatCount(); | |
521 | // wxDataFormat base_GetFormat(size_t n); | |
522 | ||
523 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
524 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
525 | void base_OnLeave(); | |
526 | bool base_OnDrop(wxCoord x, wxCoord y); | |
527 | //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0; | |
528 | ||
529 | // **** not sure about this one | |
530 | bool GetData(); | |
531 | ||
532 | }; | |
533 | ||
534 | ||
535 | //---------------------------------------------------------------------- | |
536 | ||
537 | %{ | |
538 | class wxPyTextDropTarget : public wxTextDropTarget { | |
539 | public: | |
540 | wxPyTextDropTarget() {} | |
541 | ||
542 | DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText); | |
543 | ||
544 | DEC_PYCALLBACK__(OnLeave); | |
545 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
546 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
547 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
548 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
549 | ||
550 | PYPRIVATE; | |
551 | }; | |
552 | ||
553 | IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText); | |
554 | IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave); | |
555 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter); | |
556 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver); | |
557 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData); | |
558 | IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop); | |
559 | ||
560 | %} | |
561 | ||
562 | %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget { | |
563 | public: | |
564 | wxPyTextDropTarget(); | |
0122b7e3 RD |
565 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
566 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)" | |
b1462dfa RD |
567 | |
568 | //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0; | |
569 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
570 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
571 | void base_OnLeave(); | |
572 | bool base_OnDrop(wxCoord x, wxCoord y); | |
573 | wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); | |
574 | }; | |
575 | ||
576 | //---------------------------------------------------------------------- | |
577 | %{ | |
578 | class wxPyFileDropTarget : public wxFileDropTarget { | |
579 | public: | |
580 | wxPyFileDropTarget() {} | |
581 | ||
582 | virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
583 | ||
584 | DEC_PYCALLBACK__(OnLeave); | |
585 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
586 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
587 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
588 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
589 | ||
590 | PYPRIVATE; | |
591 | }; | |
592 | ||
593 | bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, | |
594 | const wxArrayString& filenames) { | |
595 | bool rval = FALSE; | |
19a97bd6 | 596 | wxPyTState* state = wxPyBeginBlockThreads(); |
b1462dfa RD |
597 | PyObject* list = PyList_New(0); |
598 | for (size_t i=0; i<filenames.GetCount(); i++) { | |
599 | PyObject* str = PyString_FromString(filenames[i].c_str()); | |
600 | PyList_Append(list, str); | |
601 | } | |
602 | if (m_myInst.findCallback("OnDropFiles")) | |
603 | rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list)); | |
604 | Py_DECREF(list); | |
19a97bd6 | 605 | wxPyEndBlockThreads(state); |
b1462dfa RD |
606 | return rval; |
607 | } | |
608 | ||
609 | ||
610 | ||
611 | IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave); | |
612 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter); | |
613 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver); | |
614 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData); | |
615 | IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop); | |
616 | ||
617 | %} | |
618 | ||
619 | ||
620 | %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget | |
621 | { | |
622 | public: | |
623 | wxPyFileDropTarget(); | |
0122b7e3 RD |
624 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
625 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)" | |
b1462dfa RD |
626 | |
627 | // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0; | |
628 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
629 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
630 | void base_OnLeave(); | |
631 | bool base_OnDrop(wxCoord x, wxCoord y); | |
632 | wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); | |
633 | }; | |
634 | ||
635 | //---------------------------------------------------------------------- | |
636 | //---------------------------------------------------------------------- | |
637 | //---------------------------------------------------------------------- | |
638 | ||
639 | %init %{ | |
640 | ||
641 | wxPyTheClipboard = wxTheClipboard; | |
9416aa89 RD |
642 | wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource"); |
643 | wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget"); | |
644 | wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget"); | |
b1462dfa RD |
645 | %} |
646 | ||
647 | //---------------------------------------------------------------------- | |
648 |