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 //----------------------------------------------------------------------
42 wxDF_TEXT = 1, /* CF_TEXT */
43 wxDF_BITMAP = 2, /* CF_BITMAP */
44 wxDF_METAFILE = 3, /* CF_METAFILEPICT */
48 wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
49 wxDF_DIB = 8, /* CF_DIB */
54 wxDF_UNICODETEXT = 13,
55 wxDF_ENHMETAFILE = 14,
56 wxDF_FILENAME = 15, /* CF_HDROP */
62 //----------------------------------------------------------------------
66 wxDataFormat( wxDataFormatId type );
69 void SetType(wxDataFormatId format);
70 wxDataFormatId GetType() const;
72 wxString GetId() const;
73 void SetId(const char *format);
76 %new wxDataFormat* wxCustomDataFormat(const wxString &id);
77 %{ // An alternate constructor...
78 wxDataFormat* wxCustomDataFormat(const wxString &id) {
79 return new wxDataFormat(id);
85 wxDataFormat wxPyFormatInvalid;
88 %name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
92 //----------------------------------------------------------------------
96 class wxDataObject { // An abstract base class
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)
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);
117 //----------------------------------------------------------------------
119 class wxDataObjectSimple : public wxDataObject {
121 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
123 const wxDataFormat& GetFormat();
124 void SetFormat(const wxDataFormat& format);
129 %{ // Create a new class for wxPython to use
130 class wxPyDataObjectSimple : public wxDataObjectSimple {
132 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
133 : wxDataObjectSimple(format) {}
135 DEC_PYCALLBACK_SIZET_(GetDataSize);
136 bool GetDataHere(void *buf);
137 bool SetData(size_t len, const void *buf);
141 IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
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
150 bool doSave = wxPyRestoreThread();
151 if (m_myInst.findCallback("GetDataHere")) {
153 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
154 rval = (ro != Py_None && PyString_Check(ro));
156 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
158 wxPySaveThread(doSave);
162 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
163 // For this one we simply need to make a string from buf and len
164 // and send it to the Python method.
166 bool doSave = wxPyRestoreThread();
167 if (m_myInst.findCallback("SetData")) {
168 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
169 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
172 wxPySaveThread(doSave);
179 // Now define it for SWIG
180 class wxPyDataObjectSimple : public wxDataObjectSimple {
182 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
183 void _setSelf(PyObject* self);
184 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
187 //----------------------------------------------------------------------
189 class wxDataObjectComposite : public wxDataObject {
191 wxDataObjectComposite();
193 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
194 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
199 //----------------------------------------------------------------------
201 class wxTextDataObject : public wxDataObjectSimple {
203 wxTextDataObject(const wxString& text = wxEmptyString);
205 size_t GetTextLength();
207 void SetText(const wxString& text);
212 %{ // Create a new class for wxPython to use
213 class wxPyTextDataObject : public wxTextDataObject {
215 wxPyTextDataObject(const wxString& text = wxEmptyString)
216 : wxTextDataObject(text) {}
218 DEC_PYCALLBACK_SIZET_(GetTextLength);
219 DEC_PYCALLBACK_STRING_(GetText);
220 DEC_PYCALLBACK__STRING(SetText);
224 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
225 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
226 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
231 // Now define it for SWIG
232 class wxPyTextDataObject : public wxTextDataObject {
234 wxPyTextDataObject(const wxString& text = wxEmptyString);
235 void _setSelf(PyObject* self);
236 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
239 //----------------------------------------------------------------------
241 class wxBitmapDataObject : public wxDataObjectSimple {
243 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
245 wxBitmap GetBitmap();
246 void SetBitmap(const wxBitmap& bitmap);
251 %{ // Create a new class for wxPython to use
252 class wxPyBitmapDataObject : public wxBitmapDataObject {
254 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
255 : wxBitmapDataObject(bitmap) {}
257 wxBitmap GetBitmap();
258 void SetBitmap(const wxBitmap& bitmap);
262 wxBitmap wxPyBitmapDataObject::GetBitmap() {
263 wxBitmap* rval = &wxNullBitmap;
264 bool doSave = wxPyRestoreThread();
265 if (m_myInst.findCallback("GetBitmap")) {
268 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
269 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
272 wxPySaveThread(doSave);
276 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
277 bool doSave = wxPyRestoreThread();
278 if (m_myInst.findCallback("SetBitmap")) {
279 m_myInst.callCallback(Py_BuildValue("(O)",
280 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
282 wxPySaveThread(doSave);
288 // Now define it for SWIG
289 class wxPyBitmapDataObject : public wxBitmapDataObject {
291 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
292 void _setSelf(PyObject* self);
293 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
297 //----------------------------------------------------------------------
299 class wxFileDataObject : public wxDataObjectSimple
304 //const wxArrayString& GetFilenames();
306 PyObject* GetFilenames() {
307 const wxArrayString& strings = self->GetFilenames();
308 PyObject* list = PyList_New(0);
309 for (size_t x=0; x<strings.GetCount(); x++)
310 PyList_Append(list, PyString_FromString(strings[x]));
315 //void AddFile(const wxString &filename);
319 //----------------------------------------------------------------------
321 class wxCustomDataObject : public wxDataObjectSimple {
323 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
325 //void TakeData(size_t size, void *data);
326 //bool SetData(size_t size, const void *buf);
328 void TakeData(PyObject* data) {
329 if (PyString_Check(data)) {
330 self->SetData(PyString_Size(data), PyString_AsString(data));
333 bool SetData(PyObject* data) {
334 if (PyString_Check(data)) {
335 return self->SetData(PyString_Size(data), PyString_AsString(data));
344 PyObject* GetData() {
345 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
354 //----------------------------------------------------------------------
355 //----------------------------------------------------------------------
356 //----------------------------------------------------------------------
364 bool IsOpened() const;
366 bool AddData( wxDataObject *data );
367 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
368 bool SetData( wxDataObject *data );
369 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
371 bool IsSupported( const wxDataFormat& format );
372 bool GetData( wxDataObject& data );
375 void UsePrimarySelection( int primary = FALSE );
379 wxClipboard* wxPyTheClipboard;
382 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
385 //----------------------------------------------------------------------
386 //----------------------------------------------------------------------
390 wxDragError, // error prevented the d&d operation from completing
391 wxDragNone, // drag target didn't accept the data
392 wxDragCopy, // the data was successfully copied
393 wxDragMove, // the data was successfully moved (MSW only)
394 wxDragCancel // the operation was cancelled by user (not an error)
397 bool wxIsDragResultOk(wxDragResult res);
399 //----------------------------------------------------------------------
401 class wxPyDropSource : public wxDropSource {
404 wxPyDropSource(wxWindow *win = NULL,
405 const wxCursor &cursorCopy = wxNullCursor,
406 const wxCursor &cursorMove = wxNullCursor,
407 const wxCursor &cursorStop = wxNullCursor)
408 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
410 wxPyDropSource(wxWindow *win = NULL,
411 const wxIcon &go = wxNullIcon)
412 : wxDropSource(win, go) {}
414 ~wxPyDropSource() { }
416 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
420 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
425 %name(wxDropSource) class wxPyDropSource {
428 wxPyDropSource(wxWindow *win = NULL,
429 const wxCursor &cursorCopy = wxNullCursor,
430 const wxCursor &cursorMove = wxNullCursor,
431 const wxCursor &cursorStop = wxNullCursor);
433 wxPyDropSource(wxWindow *win = NULL,
434 const wxIcon &go = wxNullIcon);
437 void _setSelf(PyObject* self, int incref);
438 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
441 void SetData(wxDataObject& data);
442 wxDataObject *GetDataObject();
443 void SetCursor(wxDragResult res, const wxCursor& cursor);
444 wxDragResult DoDragDrop(int bAllowMove = FALSE);
446 bool base_GiveFeedback(wxDragResult effect);
449 //----------------------------------------------------------------------
451 // Just a place holder for the type system. The real base class for
452 // wxPython is wxPyDropTarget
459 class wxPyDropTarget : public wxDropTarget {
461 wxPyDropTarget(wxDataObject *dataObject = NULL)
462 : wxDropTarget(dataObject) {}
464 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
465 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
467 DEC_PYCALLBACK__(OnLeave);
468 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
469 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
470 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
471 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
476 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
477 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
479 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
480 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
481 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
482 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
483 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
488 class wxPyDropTarget : public wxDropTarget {
490 wxPyDropTarget(wxDataObject *dataObject = NULL);
491 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
492 void _setSelf(PyObject* self);
493 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
497 wxDataObject *GetDataObject();
498 void SetDataObject(wxDataObject *dataObject);
499 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
501 // size_t base_GetFormatCount();
502 // wxDataFormat base_GetFormat(size_t n);
504 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
505 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
507 bool base_OnDrop(wxCoord x, wxCoord y);
508 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
510 // **** not sure about this one
516 //----------------------------------------------------------------------
519 class wxPyTextDropTarget : public wxTextDropTarget {
521 wxPyTextDropTarget() {}
523 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
525 DEC_PYCALLBACK__(OnLeave);
526 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
527 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
528 DEC_PYCALLBACK_DR_2WXCDR(OnData);
529 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
534 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
535 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
536 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
537 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
538 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
539 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
543 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
545 wxPyTextDropTarget();
546 void _setSelf(PyObject* self);
547 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
549 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
550 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
551 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
553 bool base_OnDrop(wxCoord x, wxCoord y);
554 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
557 //----------------------------------------------------------------------
559 class wxPyFileDropTarget : public wxFileDropTarget {
561 wxPyFileDropTarget() {}
563 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
565 DEC_PYCALLBACK__(OnLeave);
566 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
567 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
568 DEC_PYCALLBACK_DR_2WXCDR(OnData);
569 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
574 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
575 const wxArrayString& filenames) {
577 bool doSave = wxPyRestoreThread();
578 PyObject* list = PyList_New(0);
579 for (size_t i=0; i<filenames.GetCount(); i++) {
580 PyObject* str = PyString_FromString(filenames[i].c_str());
581 PyList_Append(list, str);
583 if (m_myInst.findCallback("OnDropFiles"))
584 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
586 wxPySaveThread(doSave);
592 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
593 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
594 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
595 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
596 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
601 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
604 wxPyFileDropTarget();
605 void _setSelf(PyObject* self);
606 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
608 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
609 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
610 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
612 bool base_OnDrop(wxCoord x, wxCoord y);
613 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
616 //----------------------------------------------------------------------
617 //----------------------------------------------------------------------
618 //----------------------------------------------------------------------
622 wxPyTheClipboard = wxTheClipboard;
626 //----------------------------------------------------------------------