]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/clip_dnd.i
Added missing CreateManifest() to initialisation
[wxWidgets.git] / wxPython / src / clip_dnd.i
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: clip_dnd.i
3// Purpose: SWIG definitions for the Clipboard and Drag-n-drop classes
4//
5// Author: Robin Dunn
6//
7// Created: 31-October-1999
8// RCS-ID: $Id$
9// Copyright: (c) 1999 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13
14%module clip_dnd
15
16#ifndef __WXMAC__
17
18%{
19#include "helpers.h"
20#include <wx/dataobj.h>
21#include <wx/clipbrd.h>
22#include <wx/dnd.h>
23%}
24
25//----------------------------------------------------------------------
26
27%include typemaps.i
28%include my_typemaps.i
29
30// Import some definitions of other classes, etc.
31%import _defs.i
32%import misc.i
33%import gdi.i
34
35
36%pragma(python) code = "import wx"
37
38//---------------------------------------------------------------------------
39%{
40 // Put some wx default wxChar* values into wxStrings.
41 static const wxString wxPyEmptyString(wxT(""));
42%}
43//----------------------------------------------------------------------
44
45
46enum wxDataFormatId
47{
48 wxDF_INVALID = 0,
49 wxDF_TEXT = 1, /* CF_TEXT */
50 wxDF_BITMAP = 2, /* CF_BITMAP */
51 wxDF_METAFILE = 3, /* CF_METAFILEPICT */
52 wxDF_SYLK = 4,
53 wxDF_DIF = 5,
54 wxDF_TIFF = 6,
55 wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
56 wxDF_DIB = 8, /* CF_DIB */
57 wxDF_PALETTE = 9,
58 wxDF_PENDATA = 10,
59 wxDF_RIFF = 11,
60 wxDF_WAVE = 12,
61 wxDF_UNICODETEXT = 13,
62 wxDF_ENHMETAFILE = 14,
63 wxDF_FILENAME = 15, /* CF_HDROP */
64 wxDF_LOCALE = 16,
65 wxDF_PRIVATE = 20,
66 wxDF_MAX
67};
68
69//----------------------------------------------------------------------
70
71class wxDataFormat {
72public:
73 wxDataFormat( wxDataFormatId type );
74 ~wxDataFormat();
75
76 void SetType(wxDataFormatId format);
77 wxDataFormatId GetType() const;
78
79 wxString GetId() const;
80 void SetId(const wxString& format);
81};
82
83%new wxDataFormat* wxCustomDataFormat(const wxString &id);
84%{ // An alternate constructor...
85 wxDataFormat* wxCustomDataFormat(const wxString &id) {
86 return new wxDataFormat(id);
87 }
88%}
89
90
91%{
92wxDataFormat wxPyFormatInvalid;
93%}
94%readonly
95%name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
96%readwrite
97
98
99//----------------------------------------------------------------------
100
101
102
103class wxDataObject { // An abstract base class
104public:
105 enum Direction {
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)
109 };
110
111 ~wxDataObject();
112
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);
122};
123
124//----------------------------------------------------------------------
125
126class wxDataObjectSimple : public wxDataObject {
127public:
128 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
129
130 const wxDataFormat& GetFormat();
131 void SetFormat(const wxDataFormat& format);
132
133};
134
135
136%{ // Create a new class for wxPython to use
137class wxPyDataObjectSimple : public wxDataObjectSimple {
138public:
139 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
140 : wxDataObjectSimple(format) {}
141
142 DEC_PYCALLBACK_SIZET_(GetDataSize);
143 bool GetDataHere(void *buf);
144 bool SetData(size_t len, const void *buf);
145 PYPRIVATE;
146};
147
148IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
149
150bool 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
154 // C++ version.
155
156 bool rval = FALSE;
157 wxPyBeginBlockThreads();
158 if (m_myInst.findCallback("GetDataHere")) {
159 PyObject* ro;
160 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
161 if (ro) {
162 rval = (ro != Py_None && PyString_Check(ro));
163 if (rval)
164 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
165 Py_DECREF(ro);
166 }
167 }
168 wxPyEndBlockThreads();
169 return rval;
170}
171
172bool 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.
175 bool rval = FALSE;
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));
180 Py_DECREF(data);
181 }
182 wxPyEndBlockThreads();
183 return rval;
184}
185%}
186
187
188
189// Now define it for SWIG
190class wxPyDataObjectSimple : public wxDataObjectSimple {
191public:
192 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
193 void _setCallbackInfo(PyObject* self, PyObject* _class);
194 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
195};
196
197//----------------------------------------------------------------------
198
199class wxDataObjectComposite : public wxDataObject {
200public:
201 wxDataObjectComposite();
202
203 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
204 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
205
206};
207
208
209//----------------------------------------------------------------------
210
211class wxTextDataObject : public wxDataObjectSimple {
212public:
213 wxTextDataObject(const wxString& text = wxPyEmptyString);
214
215 size_t GetTextLength();
216 wxString GetText();
217 void SetText(const wxString& text);
218};
219
220
221
222%{ // Create a new class for wxPython to use
223class wxPyTextDataObject : public wxTextDataObject {
224public:
225 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
226 : wxTextDataObject(text) {}
227
228 DEC_PYCALLBACK_SIZET_(GetTextLength);
229 DEC_PYCALLBACK_STRING_(GetText);
230 DEC_PYCALLBACK__STRING(SetText);
231 PYPRIVATE;
232};
233
234IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
235IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
236IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
237
238%}
239
240
241// Now define it for SWIG
242class wxPyTextDataObject : public wxTextDataObject {
243public:
244 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
245 void _setCallbackInfo(PyObject* self, PyObject* _class);
246 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
247};
248
249//----------------------------------------------------------------------
250
251class wxBitmapDataObject : public wxDataObjectSimple {
252public:
253 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
254
255 wxBitmap GetBitmap();
256 void SetBitmap(const wxBitmap& bitmap);
257};
258
259
260
261%{ // Create a new class for wxPython to use
262class wxPyBitmapDataObject : public wxBitmapDataObject {
263public:
264 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
265 : wxBitmapDataObject(bitmap) {}
266
267 wxBitmap GetBitmap();
268 void SetBitmap(const wxBitmap& bitmap);
269 PYPRIVATE;
270};
271
272wxBitmap wxPyBitmapDataObject::GetBitmap() {
273 wxBitmap* rval = &wxNullBitmap;
274 wxPyBeginBlockThreads();
275 if (m_myInst.findCallback("GetBitmap")) {
276 PyObject* ro;
277 wxBitmap* ptr;
278 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
279 if (ro) {
280 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
281 rval = ptr;
282 Py_DECREF(ro);
283 }
284 }
285 wxPyEndBlockThreads();
286 return *rval;
287}
288
289void 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")));
294 }
295 wxPyEndBlockThreads();
296}
297%}
298
299
300
301// Now define it for SWIG
302class wxPyBitmapDataObject : public wxBitmapDataObject {
303public:
304 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
305 void _setCallbackInfo(PyObject* self, PyObject* _class);
306 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
307};
308
309
310//----------------------------------------------------------------------
311
312class wxFileDataObject : public wxDataObjectSimple
313{
314public:
315 wxFileDataObject();
316
317 //const wxArrayString& GetFilenames();
318 %addmethods {
319 PyObject* GetFilenames() {
320 const wxArrayString& strings = self->GetFilenames();
321 return wxArrayString2PyList_helper(strings);
322 }
323 }
324#ifdef __WXMSW__
325 void AddFile(const wxString &filename);
326#endif
327};
328
329
330//----------------------------------------------------------------------
331
332class wxCustomDataObject : public wxDataObjectSimple {
333public:
334 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
335
336 //void TakeData(size_t size, void *data);
337 //bool SetData(size_t size, const void *buf);
338 %addmethods {
339 void TakeData(PyObject* data) {
340 if (PyString_Check(data)) {
341 self->SetData(PyString_Size(data), PyString_AsString(data));
342 }
343 }
344 bool SetData(PyObject* data) {
345 if (PyString_Check(data)) {
346 return self->SetData(PyString_Size(data), PyString_AsString(data));
347 }
348 return FALSE;
349 }
350 }
351
352 size_t GetSize();
353
354 //void *GetData();
355 %addmethods {
356 PyObject* GetData() {
357 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
358 }
359 }
360
361
362};
363
364
365//----------------------------------------------------------------------
366
367class wxURLDataObject : public wxDataObjectComposite {
368public:
369 wxURLDataObject();
370
371 wxString GetURL();
372 void SetURL(const wxString& url);
373};
374
375//----------------------------------------------------------------------
376
377#ifndef __WXGTK__
378
379%{
380#include <wx/metafile.h>
381%}
382
383class wxMetafileDataObject : public wxDataObjectSimple
384{
385public:
386 wxMetafileDataObject();
387
388 void SetMetafile(const wxMetafile& metafile);
389 wxMetafile GetMetafile() const;
390};
391
392#endif
393
394//----------------------------------------------------------------------
395//----------------------------------------------------------------------
396//----------------------------------------------------------------------
397
398class wxClipboard : public wxObject {
399public:
400 wxClipboard();
401
402 bool Open();
403 void Close();
404 bool IsOpened() const;
405
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"
410
411 bool IsSupported( const wxDataFormat& format );
412 bool GetData( wxDataObject& data );
413 void Clear();
414 bool Flush();
415 void UsePrimarySelection( int primary = FALSE );
416};
417
418%{
419 // See below in the init function...
420 wxClipboard* wxPyTheClipboard;
421%}
422%readonly
423%name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
424%readwrite
425
426//----------------------------------------------------------------------
427//----------------------------------------------------------------------
428
429enum wxDragResult
430{
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)
437};
438
439bool wxIsDragResultOk(wxDragResult res);
440
441//----------------------------------------------------------------------
442%{
443class wxPyDropSource : public wxDropSource {
444public:
445#ifdef __WXMSW__
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) {}
451#else
452 wxPyDropSource(wxWindow *win = NULL,
453 const wxIcon &go = wxNullIcon)
454 : wxDropSource(win, go) {}
455#endif
456 ~wxPyDropSource() { }
457
458 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
459 PYPRIVATE;
460};
461
462IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
463
464%}
465
466
467%name(wxDropSource) class wxPyDropSource {
468public:
469#ifdef __WXMSW__
470 wxPyDropSource(wxWindow *win = NULL,
471 const wxCursor &cursorCopy = wxNullCursor,
472 const wxCursor &cursorMove = wxNullCursor,
473 const wxCursor &cursorStop = wxNullCursor);
474#else
475 wxPyDropSource(wxWindow *win = NULL,
476 const wxIcon &go = wxNullIcon);
477#endif
478
479 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
480 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
481 ~wxPyDropSource();
482
483 void SetData(wxDataObject& data);
484 wxDataObject *GetDataObject();
485 void SetCursor(wxDragResult res, const wxCursor& cursor);
486 wxDragResult DoDragDrop(int bAllowMove = FALSE);
487
488 bool base_GiveFeedback(wxDragResult effect);
489};
490
491//----------------------------------------------------------------------
492
493// Just a place holder for the type system. The real base class for
494// wxPython is wxPyDropTarget
495class wxDropTarget {
496public:
497};
498
499
500%{
501class wxPyDropTarget : public wxDropTarget {
502public:
503 wxPyDropTarget(wxDataObject *dataObject = NULL)
504 : wxDropTarget(dataObject) {}
505
506// DEC_PYCALLBACK_SIZET_(GetFormatCount);
507// DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
508
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);
514
515 PYPRIVATE;
516};
517
518// IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
519// IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
520
521IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
522IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
523IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
524IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
525IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
526
527%}
528
529
530class wxPyDropTarget : public wxDropTarget {
531public:
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)"
536
537 ~wxPyDropTarget();
538
539 wxDataObject *GetDataObject();
540 void SetDataObject(wxDataObject *dataObject);
541 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
542
543// size_t base_GetFormatCount();
544// wxDataFormat base_GetFormat(size_t n);
545
546 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
547 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
548 void base_OnLeave();
549 bool base_OnDrop(wxCoord x, wxCoord y);
550 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
551
552 // **** not sure about this one
553 bool GetData();
554
555};
556
557
558//----------------------------------------------------------------------
559
560%{
561class wxPyTextDropTarget : public wxTextDropTarget {
562public:
563 wxPyTextDropTarget() {}
564
565 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
566
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);
572
573 PYPRIVATE;
574};
575
576IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
577IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
578IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
579IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
580IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
581IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
582
583%}
584
585%name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
586public:
587 wxPyTextDropTarget();
588 void _setCallbackInfo(PyObject* self, PyObject* _class);
589 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
590
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);
594 void base_OnLeave();
595 bool base_OnDrop(wxCoord x, wxCoord y);
596 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
597};
598
599//----------------------------------------------------------------------
600%{
601class wxPyFileDropTarget : public wxFileDropTarget {
602public:
603 wxPyFileDropTarget() {}
604
605 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
606
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);
612
613 PYPRIVATE;
614};
615
616bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
617 const wxArrayString& filenames) {
618 bool rval = FALSE;
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));
623 Py_DECREF(list);
624 wxPyEndBlockThreads();
625 return rval;
626}
627
628
629
630IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
631IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
632IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
633IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
634IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
635
636%}
637
638
639%name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
640{
641public:
642 wxPyFileDropTarget();
643 void _setCallbackInfo(PyObject* self, PyObject* _class);
644 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
645
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);
649 void base_OnLeave();
650 bool base_OnDrop(wxCoord x, wxCoord y);
651 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
652};
653
654//----------------------------------------------------------------------
655//----------------------------------------------------------------------
656//----------------------------------------------------------------------
657
658%init %{
659
660 wxPyTheClipboard = wxTheClipboard;
661 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
662 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
663 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
664%}
665
666//----------------------------------------------------------------------
667#endif
668