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 //----------------------------------------------------------------------
44 wxDF_TEXT = 1, /* CF_TEXT */
45 wxDF_BITMAP = 2, /* CF_BITMAP */
46 wxDF_METAFILE = 3, /* CF_METAFILEPICT */
50 wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
51 wxDF_DIB = 8, /* CF_DIB */
56 wxDF_UNICODETEXT = 13,
57 wxDF_ENHMETAFILE = 14,
58 wxDF_FILENAME = 15, /* CF_HDROP */
64 //----------------------------------------------------------------------
68 wxDataFormat( wxDataFormatId type );
71 void SetType(wxDataFormatId format);
72 wxDataFormatId GetType() const;
74 wxString GetId() const;
75 void SetId(const char *format);
78 %new wxDataFormat* wxCustomDataFormat(const wxString &id);
79 %{ // An alternate constructor...
80 wxDataFormat* wxCustomDataFormat(const wxString &id) {
81 return new wxDataFormat(id);
87 wxDataFormat wxPyFormatInvalid;
90 %name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
94 //----------------------------------------------------------------------
98 class wxDataObject { // An abstract base class
101 Get = 0x01, // format is supported by GetDataHere()
102 Set = 0x02, // format is supported by SetData()
103 Both = 0x03 // format is supported by both (unused currently)
108 wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get);
109 size_t GetFormatCount(Direction dir = wxDataObject::Get);
110 void GetAllFormats(wxDataFormat *formats,
111 Direction dir = wxDataObject::Get);
112 size_t GetDataSize(const wxDataFormat& format);
113 bool GetDataHere(const wxDataFormat& format, void *buf);
114 bool SetData(const wxDataFormat& format,
115 size_t len, const void * buf);
116 bool IsSupportedFormat(const wxDataFormat& format);
119 //----------------------------------------------------------------------
121 class wxDataObjectSimple : public wxDataObject {
123 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
125 const wxDataFormat& GetFormat();
126 void SetFormat(const wxDataFormat& format);
131 %{ // Create a new class for wxPython to use
132 class wxPyDataObjectSimple : public wxDataObjectSimple {
134 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
135 : wxDataObjectSimple(format) {}
137 DEC_PYCALLBACK_SIZET_(GetDataSize);
138 bool GetDataHere(void *buf);
139 bool SetData(size_t len, const void *buf);
143 IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
145 bool wxPyDataObjectSimple::GetDataHere(void *buf) {
146 // We need to get the data for this object and write it to buf. I think
147 // the best way to do this for wxPython is to have the Python method
148 // return either a string or None and then act appropriately with the
152 wxPyBeginBlockThreads();
153 if (m_myInst.findCallback("GetDataHere")) {
155 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
157 rval = (ro != Py_None && PyString_Check(ro));
159 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
163 wxPyEndBlockThreads();
167 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
168 // For this one we simply need to make a string from buf and len
169 // and send it to the Python method.
171 wxPyBeginBlockThreads();
172 if (m_myInst.findCallback("SetData")) {
173 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
174 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
177 wxPyEndBlockThreads();
184 // Now define it for SWIG
185 class wxPyDataObjectSimple : public wxDataObjectSimple {
187 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
188 void _setCallbackInfo(PyObject* self, PyObject* _class);
189 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
192 //----------------------------------------------------------------------
194 class wxDataObjectComposite : public wxDataObject {
196 wxDataObjectComposite();
198 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
199 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
204 //----------------------------------------------------------------------
206 class wxTextDataObject : public wxDataObjectSimple {
208 wxTextDataObject(const wxString& text = wxEmptyString);
210 size_t GetTextLength();
212 void SetText(const wxString& text);
217 %{ // Create a new class for wxPython to use
218 class wxPyTextDataObject : public wxTextDataObject {
220 wxPyTextDataObject(const wxString& text = wxEmptyString)
221 : wxTextDataObject(text) {}
223 DEC_PYCALLBACK_SIZET_(GetTextLength);
224 DEC_PYCALLBACK_STRING_(GetText);
225 DEC_PYCALLBACK__STRING(SetText);
229 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
230 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
231 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
236 // Now define it for SWIG
237 class wxPyTextDataObject : public wxTextDataObject {
239 wxPyTextDataObject(const wxString& text = wxEmptyString);
240 void _setCallbackInfo(PyObject* self, PyObject* _class);
241 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
244 //----------------------------------------------------------------------
246 class wxBitmapDataObject : public wxDataObjectSimple {
248 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
250 wxBitmap GetBitmap();
251 void SetBitmap(const wxBitmap& bitmap);
256 %{ // Create a new class for wxPython to use
257 class wxPyBitmapDataObject : public wxBitmapDataObject {
259 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
260 : wxBitmapDataObject(bitmap) {}
262 wxBitmap GetBitmap();
263 void SetBitmap(const wxBitmap& bitmap);
267 wxBitmap wxPyBitmapDataObject::GetBitmap() {
268 wxBitmap* rval = &wxNullBitmap;
269 wxPyBeginBlockThreads();
270 if (m_myInst.findCallback("GetBitmap")) {
273 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
275 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
280 wxPyEndBlockThreads();
284 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
285 wxPyBeginBlockThreads();
286 if (m_myInst.findCallback("SetBitmap")) {
287 m_myInst.callCallback(Py_BuildValue("(O)",
288 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
290 wxPyEndBlockThreads();
296 // Now define it for SWIG
297 class wxPyBitmapDataObject : public wxBitmapDataObject {
299 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
300 void _setCallbackInfo(PyObject* self, PyObject* _class);
301 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
305 //----------------------------------------------------------------------
307 class wxFileDataObject : public wxDataObjectSimple
312 //const wxArrayString& GetFilenames();
314 PyObject* GetFilenames() {
315 const wxArrayString& strings = self->GetFilenames();
316 return wxArrayString2PyList_helper(strings);
320 void AddFile(const wxString &filename);
325 //----------------------------------------------------------------------
327 class wxCustomDataObject : public wxDataObjectSimple {
329 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
331 //void TakeData(size_t size, void *data);
332 //bool SetData(size_t size, const void *buf);
334 void TakeData(PyObject* data) {
335 if (PyString_Check(data)) {
336 self->SetData(PyString_Size(data), PyString_AsString(data));
339 bool SetData(PyObject* data) {
340 if (PyString_Check(data)) {
341 return self->SetData(PyString_Size(data), PyString_AsString(data));
351 PyObject* GetData() {
352 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
360 //----------------------------------------------------------------------
362 class wxURLDataObject : public wxDataObjectComposite {
367 void SetURL(const wxString& url);
370 //----------------------------------------------------------------------
375 #include <wx/metafile.h>
378 class wxMetafileDataObject : public wxDataObjectSimple
381 wxMetafileDataObject();
383 void SetMetafile(const wxMetafile& metafile);
384 wxMetafile GetMetafile() const;
389 //----------------------------------------------------------------------
390 //----------------------------------------------------------------------
391 //----------------------------------------------------------------------
393 class wxClipboard : public wxObject {
399 bool IsOpened() const;
401 bool AddData( wxDataObject *data );
402 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
403 bool SetData( wxDataObject *data );
404 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
406 bool IsSupported( const wxDataFormat& format );
407 bool GetData( wxDataObject& data );
410 void UsePrimarySelection( int primary = FALSE );
414 // See below in the init function...
415 wxClipboard* wxPyTheClipboard;
418 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
421 //----------------------------------------------------------------------
422 //----------------------------------------------------------------------
426 wxDragError, // error prevented the d&d operation from completing
427 wxDragNone, // drag target didn't accept the data
428 wxDragCopy, // the data was successfully copied
429 wxDragMove, // the data was successfully moved (MSW only)
430 wxDragLink, // operation is a drag-link
431 wxDragCancel // the operation was cancelled by user (not an error)
434 bool wxIsDragResultOk(wxDragResult res);
436 //----------------------------------------------------------------------
438 class wxPyDropSource : public wxDropSource {
441 wxPyDropSource(wxWindow *win = NULL,
442 const wxCursor &cursorCopy = wxNullCursor,
443 const wxCursor &cursorMove = wxNullCursor,
444 const wxCursor &cursorStop = wxNullCursor)
445 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
447 wxPyDropSource(wxWindow *win = NULL,
448 const wxIcon &go = wxNullIcon)
449 : wxDropSource(win, go) {}
451 ~wxPyDropSource() { }
453 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
457 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
462 %name(wxDropSource) class wxPyDropSource {
465 wxPyDropSource(wxWindow *win = NULL,
466 const wxCursor &cursorCopy = wxNullCursor,
467 const wxCursor &cursorMove = wxNullCursor,
468 const wxCursor &cursorStop = wxNullCursor);
470 wxPyDropSource(wxWindow *win = NULL,
471 const wxIcon &go = wxNullIcon);
474 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
475 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
478 void SetData(wxDataObject& data);
479 wxDataObject *GetDataObject();
480 void SetCursor(wxDragResult res, const wxCursor& cursor);
481 wxDragResult DoDragDrop(int bAllowMove = FALSE);
483 bool base_GiveFeedback(wxDragResult effect);
486 //----------------------------------------------------------------------
488 // Just a place holder for the type system. The real base class for
489 // wxPython is wxPyDropTarget
496 class wxPyDropTarget : public wxDropTarget {
498 wxPyDropTarget(wxDataObject *dataObject = NULL)
499 : wxDropTarget(dataObject) {}
501 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
502 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
504 DEC_PYCALLBACK__(OnLeave);
505 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
506 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
507 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
508 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
513 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
514 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
516 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
517 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
518 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
519 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
520 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
525 class wxPyDropTarget : public wxDropTarget {
527 wxPyDropTarget(wxDataObject *dataObject = NULL);
528 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
529 void _setCallbackInfo(PyObject* self, PyObject* _class);
530 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
534 wxDataObject *GetDataObject();
535 void SetDataObject(wxDataObject *dataObject);
536 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
538 // size_t base_GetFormatCount();
539 // wxDataFormat base_GetFormat(size_t n);
541 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
542 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
544 bool base_OnDrop(wxCoord x, wxCoord y);
545 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
547 // **** not sure about this one
553 //----------------------------------------------------------------------
556 class wxPyTextDropTarget : public wxTextDropTarget {
558 wxPyTextDropTarget() {}
560 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
562 DEC_PYCALLBACK__(OnLeave);
563 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
564 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
565 DEC_PYCALLBACK_DR_2WXCDR(OnData);
566 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
571 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
572 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
573 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
574 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
575 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
576 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
580 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
582 wxPyTextDropTarget();
583 void _setCallbackInfo(PyObject* self, PyObject* _class);
584 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
586 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
587 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
588 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
590 bool base_OnDrop(wxCoord x, wxCoord y);
591 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
594 //----------------------------------------------------------------------
596 class wxPyFileDropTarget : public wxFileDropTarget {
598 wxPyFileDropTarget() {}
600 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
602 DEC_PYCALLBACK__(OnLeave);
603 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
604 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
605 DEC_PYCALLBACK_DR_2WXCDR(OnData);
606 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
611 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
612 const wxArrayString& filenames) {
614 wxPyBeginBlockThreads();
615 PyObject* list = wxArrayString2PyList_helper(filenames);
616 if (m_myInst.findCallback("OnDropFiles"))
617 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
619 wxPyEndBlockThreads();
625 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
626 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
627 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
628 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
629 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
634 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
637 wxPyFileDropTarget();
638 void _setCallbackInfo(PyObject* self, PyObject* _class);
639 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
641 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
642 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
643 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
645 bool base_OnDrop(wxCoord x, wxCoord y);
646 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
649 //----------------------------------------------------------------------
650 //----------------------------------------------------------------------
651 //----------------------------------------------------------------------
655 wxPyTheClipboard = wxTheClipboard;
656 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
657 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
658 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
661 //----------------------------------------------------------------------