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 //----------------------------------------------------------------------
49 wxDF_TEXT = 1, /* CF_TEXT */
50 wxDF_BITMAP = 2, /* CF_BITMAP */
51 wxDF_METAFILE = 3, /* CF_METAFILEPICT */
55 wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
56 wxDF_DIB = 8, /* CF_DIB */
61 wxDF_UNICODETEXT = 13,
62 wxDF_ENHMETAFILE = 14,
63 wxDF_FILENAME = 15, /* CF_HDROP */
69 //----------------------------------------------------------------------
73 wxDataFormat( wxDataFormatId type );
76 void SetType(wxDataFormatId format);
77 wxDataFormatId GetType() const;
79 wxString GetId() const;
80 void SetId(const wxString& format);
83 %new wxDataFormat* wxCustomDataFormat(const wxString &id);
84 %{ // An alternate constructor...
85 wxDataFormat* wxCustomDataFormat(const wxString &id) {
86 return new wxDataFormat(id);
92 wxDataFormat wxPyFormatInvalid;
95 %name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
99 //----------------------------------------------------------------------
103 class wxDataObject { // An abstract base class
106 Get = 0x01, // format is supported by GetDataHere()
107 Set = 0x02, // format is supported by SetData()
108 Both = 0x03 // format is supported by both (unused currently)
113 wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get);
114 size_t GetFormatCount(Direction dir = wxDataObject::Get);
115 void GetAllFormats(wxDataFormat *formats,
116 Direction dir = wxDataObject::Get);
117 size_t GetDataSize(const wxDataFormat& format);
118 bool GetDataHere(const wxDataFormat& format, void *buf);
119 bool SetData(const wxDataFormat& format,
120 size_t len, const void * buf);
121 bool IsSupportedFormat(const wxDataFormat& format);
124 //----------------------------------------------------------------------
126 class wxDataObjectSimple : public wxDataObject {
128 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
130 const wxDataFormat& GetFormat();
131 void SetFormat(const wxDataFormat& format);
136 %{ // Create a new class for wxPython to use
137 class wxPyDataObjectSimple : public wxDataObjectSimple {
139 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
140 : wxDataObjectSimple(format) {}
142 DEC_PYCALLBACK_SIZET_(GetDataSize);
143 bool GetDataHere(void *buf);
144 bool SetData(size_t len, const void *buf);
148 IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
150 bool wxPyDataObjectSimple::GetDataHere(void *buf) {
151 // We need to get the data for this object and write it to buf. I think
152 // the best way to do this for wxPython is to have the Python method
153 // return either a string or None and then act appropriately with the
157 wxPyBeginBlockThreads();
158 if (m_myInst.findCallback("GetDataHere")) {
160 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
162 rval = (ro != Py_None && PyString_Check(ro));
164 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
168 wxPyEndBlockThreads();
172 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
173 // For this one we simply need to make a string from buf and len
174 // and send it to the Python method.
176 wxPyBeginBlockThreads();
177 if (m_myInst.findCallback("SetData")) {
178 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
179 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
182 wxPyEndBlockThreads();
189 // Now define it for SWIG
190 class wxPyDataObjectSimple : public wxDataObjectSimple {
192 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
193 void _setCallbackInfo(PyObject* self, PyObject* _class);
194 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
197 //----------------------------------------------------------------------
199 class wxDataObjectComposite : public wxDataObject {
201 wxDataObjectComposite();
203 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
204 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
209 //----------------------------------------------------------------------
211 class wxTextDataObject : public wxDataObjectSimple {
213 wxTextDataObject(const wxString& text = wxPyEmptyString);
215 size_t GetTextLength();
217 void SetText(const wxString& text);
222 %{ // Create a new class for wxPython to use
223 class wxPyTextDataObject : public wxTextDataObject {
225 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
226 : wxTextDataObject(text) {}
228 DEC_PYCALLBACK_SIZET_(GetTextLength);
229 DEC_PYCALLBACK_STRING_(GetText);
230 DEC_PYCALLBACK__STRING(SetText);
234 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
235 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
236 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
241 // Now define it for SWIG
242 class wxPyTextDataObject : public wxTextDataObject {
244 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
245 void _setCallbackInfo(PyObject* self, PyObject* _class);
246 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
249 //----------------------------------------------------------------------
251 class wxBitmapDataObject : public wxDataObjectSimple {
253 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
255 wxBitmap GetBitmap();
256 void SetBitmap(const wxBitmap& bitmap);
261 %{ // Create a new class for wxPython to use
262 class wxPyBitmapDataObject : public wxBitmapDataObject {
264 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
265 : wxBitmapDataObject(bitmap) {}
267 wxBitmap GetBitmap();
268 void SetBitmap(const wxBitmap& bitmap);
272 wxBitmap wxPyBitmapDataObject::GetBitmap() {
273 wxBitmap* rval = &wxNullBitmap;
274 wxPyBeginBlockThreads();
275 if (m_myInst.findCallback("GetBitmap")) {
278 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
280 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
285 wxPyEndBlockThreads();
289 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
290 wxPyBeginBlockThreads();
291 if (m_myInst.findCallback("SetBitmap")) {
292 m_myInst.callCallback(Py_BuildValue("(O)",
293 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
295 wxPyEndBlockThreads();
301 // Now define it for SWIG
302 class wxPyBitmapDataObject : public wxBitmapDataObject {
304 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
305 void _setCallbackInfo(PyObject* self, PyObject* _class);
306 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
310 //----------------------------------------------------------------------
312 class wxFileDataObject : public wxDataObjectSimple
317 //const wxArrayString& GetFilenames();
319 PyObject* GetFilenames() {
320 const wxArrayString& strings = self->GetFilenames();
321 return wxArrayString2PyList_helper(strings);
325 void AddFile(const wxString &filename);
330 //----------------------------------------------------------------------
332 class wxCustomDataObject : public wxDataObjectSimple {
334 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
336 //void TakeData(size_t size, void *data);
337 //bool SetData(size_t size, const void *buf);
339 void TakeData(PyObject* data) {
340 if (PyString_Check(data)) {
341 self->SetData(PyString_Size(data), PyString_AsString(data));
344 bool SetData(PyObject* data) {
345 if (PyString_Check(data)) {
346 return self->SetData(PyString_Size(data), PyString_AsString(data));
356 PyObject* GetData() {
357 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
365 //----------------------------------------------------------------------
367 class wxURLDataObject : public wxDataObjectComposite {
372 void SetURL(const wxString& url);
375 //----------------------------------------------------------------------
380 #include <wx/metafile.h>
383 class wxMetafileDataObject : public wxDataObjectSimple
386 wxMetafileDataObject();
388 void SetMetafile(const wxMetafile& metafile);
389 wxMetafile GetMetafile() const;
394 //----------------------------------------------------------------------
395 //----------------------------------------------------------------------
396 //----------------------------------------------------------------------
398 class wxClipboard : public wxObject {
404 bool IsOpened() const;
406 bool AddData( wxDataObject *data );
407 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
408 bool SetData( wxDataObject *data );
409 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
411 bool IsSupported( const wxDataFormat& format );
412 bool GetData( wxDataObject& data );
415 void UsePrimarySelection( int primary = FALSE );
419 // See below in the init function...
420 wxClipboard* wxPyTheClipboard;
423 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
426 //----------------------------------------------------------------------
427 //----------------------------------------------------------------------
431 wxDragError, // error prevented the d&d operation from completing
432 wxDragNone, // drag target didn't accept the data
433 wxDragCopy, // the data was successfully copied
434 wxDragMove, // the data was successfully moved (MSW only)
435 wxDragLink, // operation is a drag-link
436 wxDragCancel // the operation was cancelled by user (not an error)
439 bool wxIsDragResultOk(wxDragResult res);
441 //----------------------------------------------------------------------
443 class wxPyDropSource : public wxDropSource {
446 wxPyDropSource(wxWindow *win = NULL,
447 const wxCursor &cursorCopy = wxNullCursor,
448 const wxCursor &cursorMove = wxNullCursor,
449 const wxCursor &cursorStop = wxNullCursor)
450 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
452 wxPyDropSource(wxWindow *win = NULL,
453 const wxIcon &go = wxNullIcon)
454 : wxDropSource(win, go) {}
456 ~wxPyDropSource() { }
458 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
462 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
467 %name(wxDropSource) class wxPyDropSource {
470 wxPyDropSource(wxWindow *win = NULL,
471 const wxCursor &cursorCopy = wxNullCursor,
472 const wxCursor &cursorMove = wxNullCursor,
473 const wxCursor &cursorStop = wxNullCursor);
475 wxPyDropSource(wxWindow *win = NULL,
476 const wxIcon &go = wxNullIcon);
479 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
480 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
483 void SetData(wxDataObject& data);
484 wxDataObject *GetDataObject();
485 void SetCursor(wxDragResult res, const wxCursor& cursor);
486 wxDragResult DoDragDrop(int bAllowMove = FALSE);
488 bool base_GiveFeedback(wxDragResult effect);
491 //----------------------------------------------------------------------
493 // Just a place holder for the type system. The real base class for
494 // wxPython is wxPyDropTarget
501 class wxPyDropTarget : public wxDropTarget {
503 wxPyDropTarget(wxDataObject *dataObject = NULL)
504 : wxDropTarget(dataObject) {}
506 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
507 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
509 DEC_PYCALLBACK__(OnLeave);
510 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
511 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
512 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
513 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
518 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
519 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
521 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
522 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
523 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
524 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
525 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
530 class wxPyDropTarget : public wxDropTarget {
532 wxPyDropTarget(wxDataObject *dataObject = NULL);
533 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
534 void _setCallbackInfo(PyObject* self, PyObject* _class);
535 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
539 wxDataObject *GetDataObject();
540 void SetDataObject(wxDataObject *dataObject);
541 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
543 // size_t base_GetFormatCount();
544 // wxDataFormat base_GetFormat(size_t n);
546 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
547 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
549 bool base_OnDrop(wxCoord x, wxCoord y);
550 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
552 // **** not sure about this one
558 //----------------------------------------------------------------------
561 class wxPyTextDropTarget : public wxTextDropTarget {
563 wxPyTextDropTarget() {}
565 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
567 DEC_PYCALLBACK__(OnLeave);
568 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
569 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
570 DEC_PYCALLBACK_DR_2WXCDR(OnData);
571 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
576 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
577 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
578 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
579 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
580 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
581 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
585 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
587 wxPyTextDropTarget();
588 void _setCallbackInfo(PyObject* self, PyObject* _class);
589 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
591 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
592 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
593 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
595 bool base_OnDrop(wxCoord x, wxCoord y);
596 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
599 //----------------------------------------------------------------------
601 class wxPyFileDropTarget : public wxFileDropTarget {
603 wxPyFileDropTarget() {}
605 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
607 DEC_PYCALLBACK__(OnLeave);
608 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
609 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
610 DEC_PYCALLBACK_DR_2WXCDR(OnData);
611 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
616 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
617 const wxArrayString& filenames) {
619 wxPyBeginBlockThreads();
620 PyObject* list = wxArrayString2PyList_helper(filenames);
621 if (m_myInst.findCallback("OnDropFiles"))
622 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
624 wxPyEndBlockThreads();
630 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
631 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
632 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
633 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
634 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
639 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
642 wxPyFileDropTarget();
643 void _setCallbackInfo(PyObject* self, PyObject* _class);
644 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
646 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
647 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
648 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
650 bool base_OnDrop(wxCoord x, wxCoord y);
651 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
654 //----------------------------------------------------------------------
655 //----------------------------------------------------------------------
656 //----------------------------------------------------------------------
660 wxPyTheClipboard = wxTheClipboard;
661 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
662 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
663 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
666 //----------------------------------------------------------------------