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 //----------------------------------------------------------------------
432 wxDragError, // error prevented the d&d operation from completing
433 wxDragNone, // drag target didn't accept the data
434 wxDragCopy, // the data was successfully copied
435 wxDragMove, // the data was successfully moved (MSW only)
436 wxDragLink, // operation is a drag-link
437 wxDragCancel // the operation was cancelled by user (not an error)
440 bool wxIsDragResultOk(wxDragResult res);
442 //----------------------------------------------------------------------
444 class wxPyDropSource : public wxDropSource {
447 wxPyDropSource(wxWindow *win = NULL,
448 const wxCursor &cursorCopy = wxNullCursor,
449 const wxCursor &cursorMove = wxNullCursor,
450 const wxCursor &cursorStop = wxNullCursor)
451 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
453 wxPyDropSource(wxWindow *win = NULL,
454 const wxIcon &go = wxNullIcon)
455 : wxDropSource(win, go) {}
457 ~wxPyDropSource() { }
459 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
463 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
468 %name(wxDropSource) class wxPyDropSource {
471 wxPyDropSource(wxWindow *win = NULL,
472 const wxCursor &cursorCopy = wxNullCursor,
473 const wxCursor &cursorMove = wxNullCursor,
474 const wxCursor &cursorStop = wxNullCursor);
476 wxPyDropSource(wxWindow *win = NULL,
477 const wxIcon &go = wxNullIcon);
480 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
481 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
484 void SetData(wxDataObject& data);
485 wxDataObject *GetDataObject();
486 void SetCursor(wxDragResult res, const wxCursor& cursor);
487 wxDragResult DoDragDrop(int bAllowMove = FALSE);
489 bool base_GiveFeedback(wxDragResult effect);
492 //----------------------------------------------------------------------
494 // Just a place holder for the type system. The real base class for
495 // wxPython is wxPyDropTarget
502 class wxPyDropTarget : public wxDropTarget {
504 wxPyDropTarget(wxDataObject *dataObject = NULL)
505 : wxDropTarget(dataObject) {}
507 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
508 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
510 DEC_PYCALLBACK__(OnLeave);
511 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
512 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
513 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
514 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
519 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
520 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
522 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
523 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
524 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
525 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
526 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
531 class wxPyDropTarget : public wxDropTarget {
533 wxPyDropTarget(wxDataObject *dataObject = NULL);
534 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
535 void _setCallbackInfo(PyObject* self, PyObject* _class);
536 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
540 wxDataObject *GetDataObject();
541 void SetDataObject(wxDataObject *dataObject);
542 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
544 // size_t base_GetFormatCount();
545 // wxDataFormat base_GetFormat(size_t n);
547 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
548 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
550 bool base_OnDrop(wxCoord x, wxCoord y);
551 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
553 // **** not sure about this one
559 //----------------------------------------------------------------------
562 class wxPyTextDropTarget : public wxTextDropTarget {
564 wxPyTextDropTarget() {}
566 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
568 DEC_PYCALLBACK__(OnLeave);
569 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
570 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
571 DEC_PYCALLBACK_DR_2WXCDR(OnData);
572 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
577 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
578 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
579 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
580 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
581 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
582 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
586 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
588 wxPyTextDropTarget();
589 void _setCallbackInfo(PyObject* self, PyObject* _class);
590 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
592 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
593 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
594 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
596 bool base_OnDrop(wxCoord x, wxCoord y);
597 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
600 //----------------------------------------------------------------------
602 class wxPyFileDropTarget : public wxFileDropTarget {
604 wxPyFileDropTarget() {}
606 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
608 DEC_PYCALLBACK__(OnLeave);
609 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
610 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
611 DEC_PYCALLBACK_DR_2WXCDR(OnData);
612 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
617 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
618 const wxArrayString& filenames) {
620 wxPyBeginBlockThreads();
621 PyObject* list = wxArrayString2PyList_helper(filenames);
622 if (m_myInst.findCallback("OnDropFiles"))
623 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
625 wxPyEndBlockThreads();
631 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
632 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
633 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
634 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
635 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
640 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
643 wxPyFileDropTarget();
644 void _setCallbackInfo(PyObject* self, PyObject* _class);
645 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
647 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
648 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
649 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
651 bool base_OnDrop(wxCoord x, wxCoord y);
652 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
655 //----------------------------------------------------------------------
656 //----------------------------------------------------------------------
657 //----------------------------------------------------------------------
661 wxPyTheClipboard = wxTheClipboard;
662 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
663 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
664 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
667 //----------------------------------------------------------------------