1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the Clipboard and Drag-n-drop classes
7 // Created: 31-October-1999
9 // Copyright: (c) 1999 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
20 #include <wx/dataobj.h>
21 #include <wx/clipbrd.h>
25 //----------------------------------------------------------------------
28 %include my_typemaps.i
30 // Import some definitions of other classes, etc.
36 %pragma(python) code = "import wx"
38 //---------------------------------------------------------------------------
40 // Put some wx default wxChar* values into wxStrings.
41 static const wxString wxPyEmptyString(wxT(""));
43 //----------------------------------------------------------------------
70 //----------------------------------------------------------------------
74 wxDataFormat( wxDataFormatId type );
77 void SetType(wxDataFormatId format);
78 wxDataFormatId GetType() const;
80 wxString GetId() const;
81 void SetId(const wxString& format);
84 %new wxDataFormat* wxCustomDataFormat(const wxString &id);
85 %{ // An alternate constructor...
86 wxDataFormat* wxCustomDataFormat(const wxString &id) {
87 return new wxDataFormat(id);
93 wxDataFormat wxPyFormatInvalid;
96 %name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
100 //----------------------------------------------------------------------
104 class wxDataObject { // An abstract base class
107 Get = 0x01, // format is supported by GetDataHere()
108 Set = 0x02, // format is supported by SetData()
109 Both = 0x03 // format is supported by both (unused currently)
114 wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get);
115 size_t GetFormatCount(Direction dir = wxDataObject::Get);
116 void GetAllFormats(wxDataFormat *formats,
117 Direction dir = wxDataObject::Get);
118 size_t GetDataSize(const wxDataFormat& format);
119 bool GetDataHere(const wxDataFormat& format, void *buf);
120 bool SetData(const wxDataFormat& format,
121 size_t len, const void * buf);
122 bool IsSupportedFormat(const wxDataFormat& format);
125 //----------------------------------------------------------------------
127 class wxDataObjectSimple : public wxDataObject {
129 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
131 const wxDataFormat& GetFormat();
132 void SetFormat(const wxDataFormat& format);
137 %{ // Create a new class for wxPython to use
138 class wxPyDataObjectSimple : public wxDataObjectSimple {
140 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
141 : wxDataObjectSimple(format) {}
143 DEC_PYCALLBACK_SIZET_(GetDataSize);
144 bool GetDataHere(void *buf);
145 bool SetData(size_t len, const void *buf);
149 IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
151 bool wxPyDataObjectSimple::GetDataHere(void *buf) {
152 // We need to get the data for this object and write it to buf. I think
153 // the best way to do this for wxPython is to have the Python method
154 // return either a string or None and then act appropriately with the
158 wxPyBeginBlockThreads();
159 if (m_myInst.findCallback("GetDataHere")) {
161 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
163 rval = (ro != Py_None && PyString_Check(ro));
165 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
169 wxPyEndBlockThreads();
173 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
174 // For this one we simply need to make a string from buf and len
175 // and send it to the Python method.
177 wxPyBeginBlockThreads();
178 if (m_myInst.findCallback("SetData")) {
179 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
180 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
183 wxPyEndBlockThreads();
190 // Now define it for SWIG
191 class wxPyDataObjectSimple : public wxDataObjectSimple {
193 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
194 void _setCallbackInfo(PyObject* self, PyObject* _class);
195 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
198 //----------------------------------------------------------------------
200 class wxDataObjectComposite : public wxDataObject {
202 wxDataObjectComposite();
204 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
205 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
210 //----------------------------------------------------------------------
212 class wxTextDataObject : public wxDataObjectSimple {
214 wxTextDataObject(const wxString& text = wxPyEmptyString);
216 size_t GetTextLength();
218 void SetText(const wxString& text);
223 %{ // Create a new class for wxPython to use
224 class wxPyTextDataObject : public wxTextDataObject {
226 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
227 : wxTextDataObject(text) {}
229 DEC_PYCALLBACK_SIZET_(GetTextLength);
230 DEC_PYCALLBACK_STRING_(GetText);
231 DEC_PYCALLBACK__STRING(SetText);
235 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
236 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
237 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
242 // Now define it for SWIG
243 class wxPyTextDataObject : public wxTextDataObject {
245 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
246 void _setCallbackInfo(PyObject* self, PyObject* _class);
247 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
250 //----------------------------------------------------------------------
252 class wxBitmapDataObject : public wxDataObjectSimple {
254 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
256 wxBitmap GetBitmap();
257 void SetBitmap(const wxBitmap& bitmap);
262 %{ // Create a new class for wxPython to use
263 class wxPyBitmapDataObject : public wxBitmapDataObject {
265 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
266 : wxBitmapDataObject(bitmap) {}
268 wxBitmap GetBitmap();
269 void SetBitmap(const wxBitmap& bitmap);
273 wxBitmap wxPyBitmapDataObject::GetBitmap() {
274 wxBitmap* rval = &wxNullBitmap;
275 wxPyBeginBlockThreads();
276 if (m_myInst.findCallback("GetBitmap")) {
279 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
281 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
286 wxPyEndBlockThreads();
290 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
291 wxPyBeginBlockThreads();
292 if (m_myInst.findCallback("SetBitmap")) {
293 m_myInst.callCallback(Py_BuildValue("(O)",
294 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
296 wxPyEndBlockThreads();
302 // Now define it for SWIG
303 class wxPyBitmapDataObject : public wxBitmapDataObject {
305 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
306 void _setCallbackInfo(PyObject* self, PyObject* _class);
307 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
311 //----------------------------------------------------------------------
313 class wxFileDataObject : public wxDataObjectSimple
318 //const wxArrayString& GetFilenames();
320 PyObject* GetFilenames() {
321 const wxArrayString& strings = self->GetFilenames();
322 return wxArrayString2PyList_helper(strings);
326 void AddFile(const wxString &filename);
331 //----------------------------------------------------------------------
333 class wxCustomDataObject : public wxDataObjectSimple {
335 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
337 //void TakeData(size_t size, void *data);
338 //bool SetData(size_t size, const void *buf);
340 void TakeData(PyObject* data) {
341 if (PyString_Check(data)) {
342 self->SetData(PyString_Size(data), PyString_AsString(data));
345 bool SetData(PyObject* data) {
346 if (PyString_Check(data)) {
347 return self->SetData(PyString_Size(data), PyString_AsString(data));
357 PyObject* GetData() {
358 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
366 //----------------------------------------------------------------------
368 class wxURLDataObject : public wxDataObjectComposite {
373 void SetURL(const wxString& url);
376 //----------------------------------------------------------------------
381 #include <wx/metafile.h>
384 class wxMetafileDataObject : public wxDataObjectSimple
387 wxMetafileDataObject();
389 void SetMetafile(const wxMetafile& metafile);
390 wxMetafile GetMetafile() const;
395 //----------------------------------------------------------------------
396 //----------------------------------------------------------------------
397 //----------------------------------------------------------------------
399 class wxClipboard : public wxObject {
405 bool IsOpened() const;
407 bool AddData( wxDataObject *data );
408 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
409 bool SetData( wxDataObject *data );
410 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
412 bool IsSupported( const wxDataFormat& format );
413 bool GetData( wxDataObject& data );
416 void UsePrimarySelection( int primary = FALSE );
420 // See below in the init function...
421 wxClipboard* wxPyTheClipboard;
424 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
427 //----------------------------------------------------------------------
428 //----------------------------------------------------------------------
430 // flags for wxDropSource::DoDragDrop()
434 wxDrag_CopyOnly = 0, // allow only copying
435 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
436 wxDrag_DefaultMove = 3 // the default operation is move, not copy
441 wxDragError, // error prevented the d&d operation from completing
442 wxDragNone, // drag target didn't accept the data
443 wxDragCopy, // the data was successfully copied
444 wxDragMove, // the data was successfully moved (MSW only)
445 wxDragLink, // operation is a drag-link
446 wxDragCancel // the operation was cancelled by user (not an error)
449 bool wxIsDragResultOk(wxDragResult res);
451 //----------------------------------------------------------------------
453 class wxPyDropSource : public wxDropSource {
456 wxPyDropSource(wxWindow *win = NULL,
457 const wxCursor &cursorCopy = wxNullCursor,
458 const wxCursor &cursorMove = wxNullCursor,
459 const wxCursor &cursorStop = wxNullCursor)
460 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
462 wxPyDropSource(wxWindow *win = NULL,
463 const wxIcon &go = wxNullIcon)
464 : wxDropSource(win, go) {}
466 ~wxPyDropSource() { }
468 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
472 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
477 %name(wxDropSource) class wxPyDropSource {
480 wxPyDropSource(wxWindow *win = NULL,
481 const wxCursor &cursorCopy = wxNullCursor,
482 const wxCursor &cursorMove = wxNullCursor,
483 const wxCursor &cursorStop = wxNullCursor);
485 wxPyDropSource(wxWindow *win = NULL,
486 const wxIcon &go = wxNullIcon);
489 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
490 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
493 void SetData(wxDataObject& data);
494 wxDataObject *GetDataObject();
495 void SetCursor(wxDragResult res, const wxCursor& cursor);
496 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
498 bool base_GiveFeedback(wxDragResult effect);
501 //----------------------------------------------------------------------
503 // Just a place holder for the type system. The real base class for
504 // wxPython is wxPyDropTarget
511 class wxPyDropTarget : public wxDropTarget {
513 wxPyDropTarget(wxDataObject *dataObject = NULL)
514 : wxDropTarget(dataObject) {}
516 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
517 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
519 DEC_PYCALLBACK__(OnLeave);
520 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
521 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
522 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
523 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
528 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
529 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
531 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
532 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
533 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
534 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
535 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
540 class wxPyDropTarget : public wxDropTarget {
542 wxPyDropTarget(wxDataObject *dataObject = NULL);
543 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
544 void _setCallbackInfo(PyObject* self, PyObject* _class);
545 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
549 wxDataObject *GetDataObject();
550 void SetDataObject(wxDataObject *dataObject);
551 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
553 // size_t base_GetFormatCount();
554 // wxDataFormat base_GetFormat(size_t n);
556 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
557 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
559 bool base_OnDrop(wxCoord x, wxCoord y);
560 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
562 // **** not sure about this one
568 //----------------------------------------------------------------------
571 class wxPyTextDropTarget : public wxTextDropTarget {
573 wxPyTextDropTarget() {}
575 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
577 DEC_PYCALLBACK__(OnLeave);
578 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
579 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
580 DEC_PYCALLBACK_DR_2WXCDR(OnData);
581 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
586 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
587 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
588 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
589 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
590 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
591 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
595 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
597 wxPyTextDropTarget();
598 void _setCallbackInfo(PyObject* self, PyObject* _class);
599 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
601 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
602 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
603 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
605 bool base_OnDrop(wxCoord x, wxCoord y);
606 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
609 //----------------------------------------------------------------------
611 class wxPyFileDropTarget : public wxFileDropTarget {
613 wxPyFileDropTarget() {}
615 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
617 DEC_PYCALLBACK__(OnLeave);
618 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
619 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
620 DEC_PYCALLBACK_DR_2WXCDR(OnData);
621 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
626 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
627 const wxArrayString& filenames) {
629 wxPyBeginBlockThreads();
630 PyObject* list = wxArrayString2PyList_helper(filenames);
631 if (m_myInst.findCallback("OnDropFiles"))
632 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
634 wxPyEndBlockThreads();
640 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
641 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
642 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
643 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
644 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
649 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
652 wxPyFileDropTarget();
653 void _setCallbackInfo(PyObject* self, PyObject* _class);
654 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
656 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
657 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
658 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
660 bool base_OnDrop(wxCoord x, wxCoord y);
661 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
664 //----------------------------------------------------------------------
665 //----------------------------------------------------------------------
666 //----------------------------------------------------------------------
670 wxPyTheClipboard = wxTheClipboard;
671 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
672 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
673 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
676 //----------------------------------------------------------------------