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);
115 // TODO: Fix these two to be usable from wxPython.
116 void GetAllFormats(wxDataFormat *formats,
117 Direction dir = wxDataObject::Get);
118 bool GetDataHere(const wxDataFormat& format, void *buf);
120 size_t GetDataSize(const wxDataFormat& format);
121 bool SetData(const wxDataFormat& format,
122 size_t len, const void * buf);
123 bool IsSupportedFormat(const wxDataFormat& format);
126 //----------------------------------------------------------------------
128 class wxDataObjectSimple : public wxDataObject {
130 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
132 const wxDataFormat& GetFormat();
133 void SetFormat(const wxDataFormat& format);
138 %{ // Create a new class for wxPython to use
139 class wxPyDataObjectSimple : public wxDataObjectSimple {
141 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
142 : wxDataObjectSimple(format) {}
144 DEC_PYCALLBACK_SIZET_(GetDataSize);
145 bool GetDataHere(void *buf);
146 bool SetData(size_t len, const void *buf);
150 IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
152 bool wxPyDataObjectSimple::GetDataHere(void *buf) {
153 // We need to get the data for this object and write it to buf. I think
154 // the best way to do this for wxPython is to have the Python method
155 // return either a string or None and then act appropriately with the
159 wxPyBeginBlockThreads();
160 if (m_myInst.findCallback("GetDataHere")) {
162 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
164 rval = (ro != Py_None && PyString_Check(ro));
166 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
170 wxPyEndBlockThreads();
174 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
175 // For this one we simply need to make a string from buf and len
176 // and send it to the Python method.
178 wxPyBeginBlockThreads();
179 if (m_myInst.findCallback("SetData")) {
180 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
181 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
184 wxPyEndBlockThreads();
191 // Now define it for SWIG
192 class wxPyDataObjectSimple : public wxDataObjectSimple {
194 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
195 void _setCallbackInfo(PyObject* self, PyObject* _class);
196 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
199 //----------------------------------------------------------------------
201 class wxDataObjectComposite : public wxDataObject {
203 wxDataObjectComposite();
205 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
206 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
211 //----------------------------------------------------------------------
213 class wxTextDataObject : public wxDataObjectSimple {
215 wxTextDataObject(const wxString& text = wxPyEmptyString);
217 size_t GetTextLength();
219 void SetText(const wxString& text);
224 %{ // Create a new class for wxPython to use
225 class wxPyTextDataObject : public wxTextDataObject {
227 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
228 : wxTextDataObject(text) {}
230 DEC_PYCALLBACK_SIZET_(GetTextLength);
231 DEC_PYCALLBACK_STRING_(GetText);
232 DEC_PYCALLBACK__STRING(SetText);
236 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
237 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
238 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
243 // Now define it for SWIG
244 class wxPyTextDataObject : public wxTextDataObject {
246 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
247 void _setCallbackInfo(PyObject* self, PyObject* _class);
248 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
251 //----------------------------------------------------------------------
253 class wxBitmapDataObject : public wxDataObjectSimple {
255 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
257 wxBitmap GetBitmap();
258 void SetBitmap(const wxBitmap& bitmap);
263 %{ // Create a new class for wxPython to use
264 class wxPyBitmapDataObject : public wxBitmapDataObject {
266 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
267 : wxBitmapDataObject(bitmap) {}
269 wxBitmap GetBitmap();
270 void SetBitmap(const wxBitmap& bitmap);
274 wxBitmap wxPyBitmapDataObject::GetBitmap() {
275 wxBitmap* rval = &wxNullBitmap;
276 wxPyBeginBlockThreads();
277 if (m_myInst.findCallback("GetBitmap")) {
280 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
282 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
287 wxPyEndBlockThreads();
291 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
292 wxPyBeginBlockThreads();
293 if (m_myInst.findCallback("SetBitmap")) {
294 PyObject* bo = wxPyConstructObject((void*)&bitmap, wxT("wxBitmap"));
295 m_myInst.callCallback(Py_BuildValue("(O)", bo));
298 wxPyEndBlockThreads();
304 // Now define it for SWIG
305 class wxPyBitmapDataObject : public wxBitmapDataObject {
307 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
308 void _setCallbackInfo(PyObject* self, PyObject* _class);
309 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
313 //----------------------------------------------------------------------
315 class wxFileDataObject : public wxDataObjectSimple
320 //const wxArrayString& GetFilenames();
322 PyObject* GetFilenames() {
323 const wxArrayString& strings = self->GetFilenames();
324 return wxArrayString2PyList_helper(strings);
328 void AddFile(const wxString &filename);
333 //----------------------------------------------------------------------
335 class wxCustomDataObject : public wxDataObjectSimple {
337 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
339 //void TakeData(size_t size, void *data);
340 //bool SetData(size_t size, const void *buf);
342 void TakeData(PyObject* data) {
343 if (PyString_Check(data)) {
344 self->SetData(PyString_Size(data), PyString_AsString(data));
347 bool SetData(PyObject* data) {
348 if (PyString_Check(data)) {
349 return self->SetData(PyString_Size(data), PyString_AsString(data));
359 PyObject* GetData() {
360 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
368 //----------------------------------------------------------------------
370 class wxURLDataObject : public wxDataObjectComposite {
375 void SetURL(const wxString& url);
378 //----------------------------------------------------------------------
383 #include <wx/metafile.h>
386 class wxMetafileDataObject : public wxDataObjectSimple
389 wxMetafileDataObject();
391 void SetMetafile(const wxMetafile& metafile);
392 wxMetafile GetMetafile() const;
397 //----------------------------------------------------------------------
398 //----------------------------------------------------------------------
399 //----------------------------------------------------------------------
401 class wxClipboard : public wxObject {
407 bool IsOpened() const;
409 bool AddData( wxDataObject *data );
410 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
411 bool SetData( wxDataObject *data );
412 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
414 bool IsSupported( const wxDataFormat& format );
415 bool GetData( wxDataObject& data );
418 void UsePrimarySelection( int primary = FALSE );
422 // See below in the init function...
423 wxClipboard* wxPyTheClipboard;
426 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
429 //----------------------------------------------------------------------
430 //----------------------------------------------------------------------
432 // flags for wxDropSource::DoDragDrop()
436 wxDrag_CopyOnly = 0, // allow only copying
437 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
438 wxDrag_DefaultMove = 3 // the default operation is move, not copy
443 wxDragError, // error prevented the d&d operation from completing
444 wxDragNone, // drag target didn't accept the data
445 wxDragCopy, // the data was successfully copied
446 wxDragMove, // the data was successfully moved (MSW only)
447 wxDragLink, // operation is a drag-link
448 wxDragCancel // the operation was cancelled by user (not an error)
451 bool wxIsDragResultOk(wxDragResult res);
453 //----------------------------------------------------------------------
455 class wxPyDropSource : public wxDropSource {
458 wxPyDropSource(wxWindow *win = NULL,
459 const wxCursor © = wxNullCursor,
460 const wxCursor &move = wxNullCursor,
461 const wxCursor &none = wxNullCursor)
462 : wxDropSource(win, copy, move, none) {}
464 wxPyDropSource(wxWindow *win = NULL,
465 const wxIcon& copy = wxNullIcon,
466 const wxIcon& move = wxNullIcon,
467 const wxIcon& none = wxNullIcon)
468 : wxDropSource(win, copy, move, none) {}
470 ~wxPyDropSource() { }
472 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
476 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
481 %name(wxDropSource) class wxPyDropSource {
484 wxPyDropSource(wxWindow *win = NULL,
485 const wxCursor © = wxNullCursor,
486 const wxCursor &move = wxNullCursor,
487 const wxCursor &none = wxNullCursor);
489 wxPyDropSource(wxWindow *win = NULL,
490 const wxIcon& copy = wxNullIcon,
491 const wxIcon& move = wxNullIcon,
492 const wxIcon& none = wxNullIcon);
495 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
496 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
499 void SetData(wxDataObject& data);
500 wxDataObject *GetDataObject();
501 void SetCursor(wxDragResult res, const wxCursor& cursor);
502 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
504 bool base_GiveFeedback(wxDragResult effect);
507 //----------------------------------------------------------------------
509 // Just a place holder for the type system. The real base class for
510 // wxPython is wxPyDropTarget
517 class wxPyDropTarget : public wxDropTarget {
519 wxPyDropTarget(wxDataObject *dataObject = NULL)
520 : wxDropTarget(dataObject) {}
522 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
523 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
525 DEC_PYCALLBACK__(OnLeave);
526 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
527 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
528 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
529 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
534 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
535 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
537 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
538 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
539 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
540 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
541 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
546 class wxPyDropTarget : public wxDropTarget {
548 wxPyDropTarget(wxDataObject *dataObject = NULL);
549 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
550 void _setCallbackInfo(PyObject* self, PyObject* _class);
551 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
555 wxDataObject *GetDataObject();
556 void SetDataObject(wxDataObject *dataObject);
557 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
559 // size_t base_GetFormatCount();
560 // wxDataFormat base_GetFormat(size_t n);
562 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
563 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
565 bool base_OnDrop(wxCoord x, wxCoord y);
566 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
568 // **** not sure about this one
574 //----------------------------------------------------------------------
577 class wxPyTextDropTarget : public wxTextDropTarget {
579 wxPyTextDropTarget() {}
581 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
583 DEC_PYCALLBACK__(OnLeave);
584 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
585 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
586 DEC_PYCALLBACK_DR_2WXCDR(OnData);
587 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
592 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
593 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
594 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
595 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
596 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
597 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
601 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
603 wxPyTextDropTarget();
604 void _setCallbackInfo(PyObject* self, PyObject* _class);
605 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
607 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
608 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
609 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
611 bool base_OnDrop(wxCoord x, wxCoord y);
612 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
615 //----------------------------------------------------------------------
617 class wxPyFileDropTarget : public wxFileDropTarget {
619 wxPyFileDropTarget() {}
621 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
623 DEC_PYCALLBACK__(OnLeave);
624 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
625 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
626 DEC_PYCALLBACK_DR_2WXCDR(OnData);
627 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
632 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
633 const wxArrayString& filenames) {
635 wxPyBeginBlockThreads();
636 if (m_myInst.findCallback("OnDropFiles")) {
637 PyObject* list = wxArrayString2PyList_helper(filenames);
638 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
641 wxPyEndBlockThreads();
647 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
648 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
649 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
650 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
651 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
656 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
659 wxPyFileDropTarget();
660 void _setCallbackInfo(PyObject* self, PyObject* _class);
661 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
663 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
664 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
665 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
667 bool base_OnDrop(wxCoord x, wxCoord y);
668 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
671 //----------------------------------------------------------------------
672 //----------------------------------------------------------------------
673 //----------------------------------------------------------------------
677 wxPyTheClipboard = wxTheClipboard;
678 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
679 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
680 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
683 //----------------------------------------------------------------------