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 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/dataobj.h>
19 #include <wx/clipbrd.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
34 %pragma(python) code = "import wx"
36 //---------------------------------------------------------------------------
38 // Put some wx default wxChar* values into wxStrings.
39 static const wxString wxPyEmptyString(wxT(""));
41 //----------------------------------------------------------------------
68 //----------------------------------------------------------------------
72 wxDataFormat( wxDataFormatId type );
75 void SetType(wxDataFormatId format);
76 wxDataFormatId GetType() const;
78 wxString GetId() const;
79 void SetId(const wxString& format);
82 %new wxDataFormat* wxCustomDataFormat(const wxString &id);
83 %{ // An alternate constructor...
84 wxDataFormat* wxCustomDataFormat(const wxString &id) {
85 return new wxDataFormat(id);
91 wxDataFormat wxPyFormatInvalid;
94 %name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
98 //----------------------------------------------------------------------
102 class wxDataObject { // An abstract base class
105 Get = 0x01, // format is supported by GetDataHere()
106 Set = 0x02, // format is supported by SetData()
107 Both = 0x03 // format is supported by both (unused currently)
112 wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get);
113 size_t GetFormatCount(Direction dir = wxDataObject::Get);
114 void GetAllFormats(wxDataFormat *formats,
115 Direction dir = wxDataObject::Get);
116 size_t GetDataSize(const wxDataFormat& format);
117 bool GetDataHere(const wxDataFormat& format, void *buf);
118 bool SetData(const wxDataFormat& format,
119 size_t len, const void * buf);
120 bool IsSupportedFormat(const wxDataFormat& format);
123 //----------------------------------------------------------------------
125 class wxDataObjectSimple : public wxDataObject {
127 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
129 const wxDataFormat& GetFormat();
130 void SetFormat(const wxDataFormat& format);
135 %{ // Create a new class for wxPython to use
136 class wxPyDataObjectSimple : public wxDataObjectSimple {
138 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
139 : wxDataObjectSimple(format) {}
141 DEC_PYCALLBACK_SIZET_(GetDataSize);
142 bool GetDataHere(void *buf);
143 bool SetData(size_t len, const void *buf);
147 IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
149 bool wxPyDataObjectSimple::GetDataHere(void *buf) {
150 // We need to get the data for this object and write it to buf. I think
151 // the best way to do this for wxPython is to have the Python method
152 // return either a string or None and then act appropriately with the
156 wxPyBeginBlockThreads();
157 if (m_myInst.findCallback("GetDataHere")) {
159 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
161 rval = (ro != Py_None && PyString_Check(ro));
163 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
167 wxPyEndBlockThreads();
171 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
172 // For this one we simply need to make a string from buf and len
173 // and send it to the Python method.
175 wxPyBeginBlockThreads();
176 if (m_myInst.findCallback("SetData")) {
177 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
178 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
181 wxPyEndBlockThreads();
188 // Now define it for SWIG
189 class wxPyDataObjectSimple : public wxDataObjectSimple {
191 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
192 void _setCallbackInfo(PyObject* self, PyObject* _class);
193 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
196 //----------------------------------------------------------------------
198 class wxDataObjectComposite : public wxDataObject {
200 wxDataObjectComposite();
202 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
203 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
208 //----------------------------------------------------------------------
210 class wxTextDataObject : public wxDataObjectSimple {
212 wxTextDataObject(const wxString& text = wxPyEmptyString);
214 size_t GetTextLength();
216 void SetText(const wxString& text);
221 %{ // Create a new class for wxPython to use
222 class wxPyTextDataObject : public wxTextDataObject {
224 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
225 : wxTextDataObject(text) {}
227 DEC_PYCALLBACK_SIZET_(GetTextLength);
228 DEC_PYCALLBACK_STRING_(GetText);
229 DEC_PYCALLBACK__STRING(SetText);
233 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
234 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
235 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
240 // Now define it for SWIG
241 class wxPyTextDataObject : public wxTextDataObject {
243 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
244 void _setCallbackInfo(PyObject* self, PyObject* _class);
245 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
248 //----------------------------------------------------------------------
250 class wxBitmapDataObject : public wxDataObjectSimple {
252 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
254 wxBitmap GetBitmap();
255 void SetBitmap(const wxBitmap& bitmap);
260 %{ // Create a new class for wxPython to use
261 class wxPyBitmapDataObject : public wxBitmapDataObject {
263 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
264 : wxBitmapDataObject(bitmap) {}
266 wxBitmap GetBitmap();
267 void SetBitmap(const wxBitmap& bitmap);
271 wxBitmap wxPyBitmapDataObject::GetBitmap() {
272 wxBitmap* rval = &wxNullBitmap;
273 wxPyBeginBlockThreads();
274 if (m_myInst.findCallback("GetBitmap")) {
277 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
279 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
284 wxPyEndBlockThreads();
288 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
289 wxPyBeginBlockThreads();
290 if (m_myInst.findCallback("SetBitmap")) {
291 m_myInst.callCallback(Py_BuildValue("(O)",
292 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
294 wxPyEndBlockThreads();
300 // Now define it for SWIG
301 class wxPyBitmapDataObject : public wxBitmapDataObject {
303 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
304 void _setCallbackInfo(PyObject* self, PyObject* _class);
305 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
309 //----------------------------------------------------------------------
311 class wxFileDataObject : public wxDataObjectSimple
316 //const wxArrayString& GetFilenames();
318 PyObject* GetFilenames() {
319 const wxArrayString& strings = self->GetFilenames();
320 return wxArrayString2PyList_helper(strings);
324 void AddFile(const wxString &filename);
329 //----------------------------------------------------------------------
331 class wxCustomDataObject : public wxDataObjectSimple {
333 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
335 //void TakeData(size_t size, void *data);
336 //bool SetData(size_t size, const void *buf);
338 void TakeData(PyObject* data) {
339 if (PyString_Check(data)) {
340 self->SetData(PyString_Size(data), PyString_AsString(data));
343 bool SetData(PyObject* data) {
344 if (PyString_Check(data)) {
345 return self->SetData(PyString_Size(data), PyString_AsString(data));
355 PyObject* GetData() {
356 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
364 //----------------------------------------------------------------------
366 class wxURLDataObject : public wxDataObjectComposite {
371 void SetURL(const wxString& url);
374 //----------------------------------------------------------------------
379 #include <wx/metafile.h>
382 class wxMetafileDataObject : public wxDataObjectSimple
385 wxMetafileDataObject();
387 void SetMetafile(const wxMetafile& metafile);
388 wxMetafile GetMetafile() const;
393 //----------------------------------------------------------------------
394 //----------------------------------------------------------------------
395 //----------------------------------------------------------------------
397 class wxClipboard : public wxObject {
403 bool IsOpened() const;
405 bool AddData( wxDataObject *data );
406 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
407 bool SetData( wxDataObject *data );
408 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
410 bool IsSupported( const wxDataFormat& format );
411 bool GetData( wxDataObject& data );
414 void UsePrimarySelection( int primary = FALSE );
418 // See below in the init function...
419 wxClipboard* wxPyTheClipboard;
422 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
425 //----------------------------------------------------------------------
426 //----------------------------------------------------------------------
428 // flags for wxDropSource::DoDragDrop()
432 wxDrag_CopyOnly = 0, // allow only copying
433 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
434 wxDrag_DefaultMove = 3 // the default operation is move, not copy
439 wxDragError, // error prevented the d&d operation from completing
440 wxDragNone, // drag target didn't accept the data
441 wxDragCopy, // the data was successfully copied
442 wxDragMove, // the data was successfully moved (MSW only)
443 wxDragLink, // operation is a drag-link
444 wxDragCancel // the operation was cancelled by user (not an error)
447 bool wxIsDragResultOk(wxDragResult res);
449 //----------------------------------------------------------------------
451 class wxPyDropSource : public wxDropSource {
454 wxPyDropSource(wxWindow *win = NULL,
455 const wxCursor &cursorCopy = wxNullCursor,
456 const wxCursor &cursorMove = wxNullCursor,
457 const wxCursor &cursorStop = wxNullCursor)
458 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
460 wxPyDropSource(wxWindow *win = NULL,
461 const wxIcon &go = wxNullIcon)
462 : wxDropSource(win, go) {}
464 ~wxPyDropSource() { }
466 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
470 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
475 %name(wxDropSource) class wxPyDropSource {
478 wxPyDropSource(wxWindow *win = NULL,
479 const wxCursor &cursorCopy = wxNullCursor,
480 const wxCursor &cursorMove = wxNullCursor,
481 const wxCursor &cursorStop = wxNullCursor);
483 wxPyDropSource(wxWindow *win = NULL,
484 const wxIcon &go = wxNullIcon);
487 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
488 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
491 void SetData(wxDataObject& data);
492 wxDataObject *GetDataObject();
493 void SetCursor(wxDragResult res, const wxCursor& cursor);
494 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
496 bool base_GiveFeedback(wxDragResult effect);
499 //----------------------------------------------------------------------
501 // Just a place holder for the type system. The real base class for
502 // wxPython is wxPyDropTarget
509 class wxPyDropTarget : public wxDropTarget {
511 wxPyDropTarget(wxDataObject *dataObject = NULL)
512 : wxDropTarget(dataObject) {}
514 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
515 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
517 DEC_PYCALLBACK__(OnLeave);
518 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
519 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
520 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
521 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
526 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
527 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
529 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
530 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
531 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
532 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
533 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
538 class wxPyDropTarget : public wxDropTarget {
540 wxPyDropTarget(wxDataObject *dataObject = NULL);
541 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
542 void _setCallbackInfo(PyObject* self, PyObject* _class);
543 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
547 wxDataObject *GetDataObject();
548 void SetDataObject(wxDataObject *dataObject);
549 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
551 // size_t base_GetFormatCount();
552 // wxDataFormat base_GetFormat(size_t n);
554 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
555 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
557 bool base_OnDrop(wxCoord x, wxCoord y);
558 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
560 // **** not sure about this one
566 //----------------------------------------------------------------------
569 class wxPyTextDropTarget : public wxTextDropTarget {
571 wxPyTextDropTarget() {}
573 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
575 DEC_PYCALLBACK__(OnLeave);
576 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
577 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
578 DEC_PYCALLBACK_DR_2WXCDR(OnData);
579 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
584 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
585 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
586 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
587 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
588 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
589 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
593 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
595 wxPyTextDropTarget();
596 void _setCallbackInfo(PyObject* self, PyObject* _class);
597 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
599 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
600 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
601 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
603 bool base_OnDrop(wxCoord x, wxCoord y);
604 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
607 //----------------------------------------------------------------------
609 class wxPyFileDropTarget : public wxFileDropTarget {
611 wxPyFileDropTarget() {}
613 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
615 DEC_PYCALLBACK__(OnLeave);
616 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
617 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
618 DEC_PYCALLBACK_DR_2WXCDR(OnData);
619 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
624 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
625 const wxArrayString& filenames) {
627 wxPyBeginBlockThreads();
628 PyObject* list = wxArrayString2PyList_helper(filenames);
629 if (m_myInst.findCallback("OnDropFiles"))
630 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
632 wxPyEndBlockThreads();
638 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
639 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
640 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
641 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
642 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
647 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
650 wxPyFileDropTarget();
651 void _setCallbackInfo(PyObject* self, PyObject* _class);
652 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
654 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
655 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
656 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
658 bool base_OnDrop(wxCoord x, wxCoord y);
659 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
662 //----------------------------------------------------------------------
663 //----------------------------------------------------------------------
664 //----------------------------------------------------------------------
668 wxPyTheClipboard = wxTheClipboard;
669 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
670 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
671 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
674 //----------------------------------------------------------------------