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("()"));
155 rval = (ro != Py_None && PyString_Check(ro));
157 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
161 wxPySaveThread(doSave);
165 bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
166 // For this one we simply need to make a string from buf and len
167 // and send it to the Python method.
169 bool doSave = wxPyRestoreThread();
170 if (m_myInst.findCallback("SetData")) {
171 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
172 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
175 wxPySaveThread(doSave);
182 // Now define it for SWIG
183 class wxPyDataObjectSimple : public wxDataObjectSimple {
185 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
186 void _setSelf(PyObject* self, PyObject* _class);
187 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyDataObjectSimple)"
190 //----------------------------------------------------------------------
192 class wxDataObjectComposite : public wxDataObject {
194 wxDataObjectComposite();
196 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
197 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
202 //----------------------------------------------------------------------
204 class wxTextDataObject : public wxDataObjectSimple {
206 wxTextDataObject(const wxString& text = wxEmptyString);
208 size_t GetTextLength();
210 void SetText(const wxString& text);
215 %{ // Create a new class for wxPython to use
216 class wxPyTextDataObject : public wxTextDataObject {
218 wxPyTextDataObject(const wxString& text = wxEmptyString)
219 : wxTextDataObject(text) {}
221 DEC_PYCALLBACK_SIZET_(GetTextLength);
222 DEC_PYCALLBACK_STRING_(GetText);
223 DEC_PYCALLBACK__STRING(SetText);
227 IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
228 IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
229 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
234 // Now define it for SWIG
235 class wxPyTextDataObject : public wxTextDataObject {
237 wxPyTextDataObject(const wxString& text = wxEmptyString);
238 void _setSelf(PyObject* self, PyObject* _class);
239 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyTextDataObject)"
242 //----------------------------------------------------------------------
244 class wxBitmapDataObject : public wxDataObjectSimple {
246 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
248 wxBitmap GetBitmap();
249 void SetBitmap(const wxBitmap& bitmap);
254 %{ // Create a new class for wxPython to use
255 class wxPyBitmapDataObject : public wxBitmapDataObject {
257 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
258 : wxBitmapDataObject(bitmap) {}
260 wxBitmap GetBitmap();
261 void SetBitmap(const wxBitmap& bitmap);
265 wxBitmap wxPyBitmapDataObject::GetBitmap() {
266 wxBitmap* rval = &wxNullBitmap;
267 bool doSave = wxPyRestoreThread();
268 if (m_myInst.findCallback("GetBitmap")) {
271 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
273 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
278 wxPySaveThread(doSave);
282 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
283 bool doSave = wxPyRestoreThread();
284 if (m_myInst.findCallback("SetBitmap")) {
285 m_myInst.callCallback(Py_BuildValue("(O)",
286 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
288 wxPySaveThread(doSave);
294 // Now define it for SWIG
295 class wxPyBitmapDataObject : public wxBitmapDataObject {
297 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
298 void _setSelf(PyObject* self, PyObject* _class);
299 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyBitmapDataObject)"
303 //----------------------------------------------------------------------
305 class wxFileDataObject : public wxDataObjectSimple
310 //const wxArrayString& GetFilenames();
312 PyObject* GetFilenames() {
313 const wxArrayString& strings = self->GetFilenames();
314 PyObject* list = PyList_New(0);
315 for (size_t x=0; x<strings.GetCount(); x++)
316 PyList_Append(list, PyString_FromString(strings[x]));
321 //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));
350 PyObject* GetData() {
351 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
360 //----------------------------------------------------------------------
361 //----------------------------------------------------------------------
362 //----------------------------------------------------------------------
370 bool IsOpened() const;
372 bool AddData( wxDataObject *data );
373 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
374 bool SetData( wxDataObject *data );
375 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
377 bool IsSupported( const wxDataFormat& format );
378 bool GetData( wxDataObject& data );
381 void UsePrimarySelection( int primary = FALSE );
385 // See below in the init function...
386 wxClipboard* wxPyTheClipboard;
389 %name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
392 //----------------------------------------------------------------------
393 //----------------------------------------------------------------------
397 wxDragError, // error prevented the d&d operation from completing
398 wxDragNone, // drag target didn't accept the data
399 wxDragCopy, // the data was successfully copied
400 wxDragMove, // the data was successfully moved (MSW only)
401 wxDragCancel // the operation was cancelled by user (not an error)
404 bool wxIsDragResultOk(wxDragResult res);
406 //----------------------------------------------------------------------
408 class wxPyDropSource : public wxDropSource {
411 wxPyDropSource(wxWindow *win = NULL,
412 const wxCursor &cursorCopy = wxNullCursor,
413 const wxCursor &cursorMove = wxNullCursor,
414 const wxCursor &cursorStop = wxNullCursor)
415 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
417 wxPyDropSource(wxWindow *win = NULL,
418 const wxIcon &go = wxNullIcon)
419 : wxDropSource(win, go) {}
421 ~wxPyDropSource() { }
423 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
427 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
432 %name(wxDropSource) class wxPyDropSource {
435 wxPyDropSource(wxWindow *win = NULL,
436 const wxCursor &cursorCopy = wxNullCursor,
437 const wxCursor &cursorMove = wxNullCursor,
438 const wxCursor &cursorStop = wxNullCursor);
440 wxPyDropSource(wxWindow *win = NULL,
441 const wxIcon &go = wxNullIcon);
444 void _setSelf(PyObject* self, PyObject* _class, int incref);
445 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxDropSource, 0)"
448 void SetData(wxDataObject& data);
449 wxDataObject *GetDataObject();
450 void SetCursor(wxDragResult res, const wxCursor& cursor);
451 wxDragResult DoDragDrop(int bAllowMove = FALSE);
453 bool base_GiveFeedback(wxDragResult effect);
456 //----------------------------------------------------------------------
458 // Just a place holder for the type system. The real base class for
459 // wxPython is wxPyDropTarget
466 class wxPyDropTarget : public wxDropTarget {
468 wxPyDropTarget(wxDataObject *dataObject = NULL)
469 : wxDropTarget(dataObject) {}
471 // DEC_PYCALLBACK_SIZET_(GetFormatCount);
472 // DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
474 DEC_PYCALLBACK__(OnLeave);
475 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
476 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
477 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
478 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
483 // IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
484 // IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
486 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
487 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
488 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
489 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
490 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
495 class wxPyDropTarget : public wxDropTarget {
497 wxPyDropTarget(wxDataObject *dataObject = NULL);
498 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
499 void _setSelf(PyObject* self, PyObject* _class);
500 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyDropTarget)"
504 wxDataObject *GetDataObject();
505 void SetDataObject(wxDataObject *dataObject);
506 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
508 // size_t base_GetFormatCount();
509 // wxDataFormat base_GetFormat(size_t n);
511 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
512 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
514 bool base_OnDrop(wxCoord x, wxCoord y);
515 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
517 // **** not sure about this one
523 //----------------------------------------------------------------------
526 class wxPyTextDropTarget : public wxTextDropTarget {
528 wxPyTextDropTarget() {}
530 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
532 DEC_PYCALLBACK__(OnLeave);
533 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
534 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
535 DEC_PYCALLBACK_DR_2WXCDR(OnData);
536 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
541 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
542 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
543 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
544 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
545 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
546 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
550 %name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
552 wxPyTextDropTarget();
553 void _setSelf(PyObject* self, PyObject* _class);
554 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTextDropTarget)"
556 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
557 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
558 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
560 bool base_OnDrop(wxCoord x, wxCoord y);
561 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
564 //----------------------------------------------------------------------
566 class wxPyFileDropTarget : public wxFileDropTarget {
568 wxPyFileDropTarget() {}
570 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
572 DEC_PYCALLBACK__(OnLeave);
573 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
574 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
575 DEC_PYCALLBACK_DR_2WXCDR(OnData);
576 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
581 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
582 const wxArrayString& filenames) {
584 bool doSave = wxPyRestoreThread();
585 PyObject* list = PyList_New(0);
586 for (size_t i=0; i<filenames.GetCount(); i++) {
587 PyObject* str = PyString_FromString(filenames[i].c_str());
588 PyList_Append(list, str);
590 if (m_myInst.findCallback("OnDropFiles"))
591 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
593 wxPySaveThread(doSave);
599 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
600 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
601 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
602 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
603 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
608 %name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
611 wxPyFileDropTarget();
612 void _setSelf(PyObject* self, PyObject* _class);
613 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxFileDropTarget)"
615 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
616 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
617 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
619 bool base_OnDrop(wxCoord x, wxCoord y);
620 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
623 //----------------------------------------------------------------------
624 //----------------------------------------------------------------------
625 //----------------------------------------------------------------------
629 wxPyTheClipboard = wxTheClipboard;
633 //----------------------------------------------------------------------