]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/clip_dnd.i
merged wxRegConf rename fix from 2.2
[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%{
17#include "helpers.h"
18#include <wx/dataobj.h>
19#include <wx/clipbrd.h>
20#include <wx/dnd.h>
21%}
22
23//----------------------------------------------------------------------
24
25%include typemaps.i
26%include my_typemaps.i
27
28// Import some definitions of other classes, etc.
29%import _defs.i
30%import misc.i
31%import gdi.i
32
33
34%pragma(python) code = "import wx"
35
36//----------------------------------------------------------------------
37
38
39enum wxDataFormatId
40{
41 wxDF_INVALID = 0,
42 wxDF_TEXT = 1, /* CF_TEXT */
43 wxDF_BITMAP = 2, /* CF_BITMAP */
44 wxDF_METAFILE = 3, /* CF_METAFILEPICT */
45 wxDF_SYLK = 4,
46 wxDF_DIF = 5,
47 wxDF_TIFF = 6,
48 wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
49 wxDF_DIB = 8, /* CF_DIB */
50 wxDF_PALETTE = 9,
51 wxDF_PENDATA = 10,
52 wxDF_RIFF = 11,
53 wxDF_WAVE = 12,
54 wxDF_UNICODETEXT = 13,
55 wxDF_ENHMETAFILE = 14,
56 wxDF_FILENAME = 15, /* CF_HDROP */
57 wxDF_LOCALE = 16,
58 wxDF_PRIVATE = 20,
59 wxDF_MAX
60};
61
62//----------------------------------------------------------------------
63
64class wxDataFormat {
65public:
66 wxDataFormat( wxDataFormatId type );
67 ~wxDataFormat();
68
69 void SetType(wxDataFormatId format);
70 wxDataFormatId GetType() const;
71
72 wxString GetId() const;
73 void SetId(const char *format);
74};
75
76%new wxDataFormat* wxCustomDataFormat(const wxString &id);
77%{ // An alternate constructor...
78 wxDataFormat* wxCustomDataFormat(const wxString &id) {
79 return new wxDataFormat(id);
80 }
81%}
82
83
84%{
85wxDataFormat wxPyFormatInvalid;
86%}
87%readonly
88%name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
89%readwrite
90
91
92//----------------------------------------------------------------------
93
94
95
96class wxDataObject { // An abstract base class
97public:
98 enum Direction {
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)
102 };
103
104 ~wxDataObject();
105
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);
115};
116
117//----------------------------------------------------------------------
118
119class wxDataObjectSimple : public wxDataObject {
120public:
121 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
122
123 const wxDataFormat& GetFormat();
124 void SetFormat(const wxDataFormat& format);
125
126};
127
128
129%{ // Create a new class for wxPython to use
130class wxPyDataObjectSimple : public wxDataObjectSimple {
131public:
132 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
133 : wxDataObjectSimple(format) {}
134
135 DEC_PYCALLBACK_SIZET_(GetDataSize);
136 bool GetDataHere(void *buf);
137 bool SetData(size_t len, const void *buf);
138 PYPRIVATE;
139};
140
141IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
142
143bool 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
147 // C++ version.
148
149 bool rval = FALSE;
150 bool doSave = wxPyRestoreThread();
151 if (m_myInst.findCallback("GetDataHere")) {
152 PyObject* ro;
153 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
154 if (ro) {
155 rval = (ro != Py_None && PyString_Check(ro));
156 if (rval)
157 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
158 Py_DECREF(ro);
159 }
160 }
161 wxPySaveThread(doSave);
162 return rval;
163}
164
165bool 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.
168 bool rval = FALSE;
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));
173 Py_DECREF(data);
174 }
175 wxPySaveThread(doSave);
176 return rval;
177}
178%}
179
180
181
182// Now define it for SWIG
183class wxPyDataObjectSimple : public wxDataObjectSimple {
184public:
185 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
186 void _setSelf(PyObject* self, PyObject* _class);
187 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyDataObjectSimple)"
188};
189
190//----------------------------------------------------------------------
191
192class wxDataObjectComposite : public wxDataObject {
193public:
194 wxDataObjectComposite();
195
196 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
197 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
198
199};
200
201
202//----------------------------------------------------------------------
203
204class wxTextDataObject : public wxDataObjectSimple {
205public:
206 wxTextDataObject(const wxString& text = wxEmptyString);
207
208 size_t GetTextLength();
209 wxString GetText();
210 void SetText(const wxString& text);
211};
212
213
214
215%{ // Create a new class for wxPython to use
216class wxPyTextDataObject : public wxTextDataObject {
217public:
218 wxPyTextDataObject(const wxString& text = wxEmptyString)
219 : wxTextDataObject(text) {}
220
221 DEC_PYCALLBACK_SIZET_(GetTextLength);
222 DEC_PYCALLBACK_STRING_(GetText);
223 DEC_PYCALLBACK__STRING(SetText);
224 PYPRIVATE;
225};
226
227IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
228IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
229IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
230
231%}
232
233
234// Now define it for SWIG
235class wxPyTextDataObject : public wxTextDataObject {
236public:
237 wxPyTextDataObject(const wxString& text = wxEmptyString);
238 void _setSelf(PyObject* self, PyObject* _class);
239 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyTextDataObject)"
240};
241
242//----------------------------------------------------------------------
243
244class wxBitmapDataObject : public wxDataObjectSimple {
245public:
246 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
247
248 wxBitmap GetBitmap();
249 void SetBitmap(const wxBitmap& bitmap);
250};
251
252
253
254%{ // Create a new class for wxPython to use
255class wxPyBitmapDataObject : public wxBitmapDataObject {
256public:
257 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
258 : wxBitmapDataObject(bitmap) {}
259
260 wxBitmap GetBitmap();
261 void SetBitmap(const wxBitmap& bitmap);
262 PYPRIVATE;
263};
264
265wxBitmap wxPyBitmapDataObject::GetBitmap() {
266 wxBitmap* rval = &wxNullBitmap;
267 bool doSave = wxPyRestoreThread();
268 if (m_myInst.findCallback("GetBitmap")) {
269 PyObject* ro;
270 wxBitmap* ptr;
271 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
272 if (ro) {
273 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
274 rval = ptr;
275 Py_DECREF(ro);
276 }
277 }
278 wxPySaveThread(doSave);
279 return *rval;
280}
281
282void 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")));
287 }
288 wxPySaveThread(doSave);
289}
290%}
291
292
293
294// Now define it for SWIG
295class wxPyBitmapDataObject : public wxBitmapDataObject {
296public:
297 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
298 void _setSelf(PyObject* self, PyObject* _class);
299 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyBitmapDataObject)"
300};
301
302
303//----------------------------------------------------------------------
304
305class wxFileDataObject : public wxDataObjectSimple
306{
307public:
308 wxFileDataObject();
309
310 //const wxArrayString& GetFilenames();
311 %addmethods {
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]));
317 return list;
318 }
319 }
320#ifdef __WXMSW__
321 void AddFile(const wxString &filename);
322#endif
323};
324
325
326//----------------------------------------------------------------------
327
328class wxCustomDataObject : public wxDataObjectSimple {
329public:
330 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
331
332 //void TakeData(size_t size, void *data);
333 //bool SetData(size_t size, const void *buf);
334 %addmethods {
335 void TakeData(PyObject* data) {
336 if (PyString_Check(data)) {
337 self->SetData(PyString_Size(data), PyString_AsString(data));
338 }
339 }
340 bool SetData(PyObject* data) {
341 if (PyString_Check(data)) {
342 return self->SetData(PyString_Size(data), PyString_AsString(data));
343 }
344 return FALSE;
345 }
346 }
347
348 size_t GetSize();
349
350 //void *GetData();
351 %addmethods {
352 PyObject* GetData() {
353 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
354 }
355 }
356
357
358};
359
360
361
362//----------------------------------------------------------------------
363//----------------------------------------------------------------------
364//----------------------------------------------------------------------
365
366class wxClipboard : public wxObject {
367public:
368 wxClipboard();
369
370 bool Open();
371 void Close();
372 bool IsOpened() const;
373
374 bool AddData( wxDataObject *data );
375 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
376 bool SetData( wxDataObject *data );
377 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
378
379 bool IsSupported( const wxDataFormat& format );
380 bool GetData( wxDataObject& data );
381 void Clear();
382 bool Flush();
383 void UsePrimarySelection( int primary = FALSE );
384};
385
386%{
387 // See below in the init function...
388 wxClipboard* wxPyTheClipboard;
389%}
390%readonly
391%name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
392%readwrite
393
394//----------------------------------------------------------------------
395//----------------------------------------------------------------------
396
397enum wxDragResult
398{
399 wxDragError, // error prevented the d&d operation from completing
400 wxDragNone, // drag target didn't accept the data
401 wxDragCopy, // the data was successfully copied
402 wxDragMove, // the data was successfully moved (MSW only)
403 wxDragCancel // the operation was cancelled by user (not an error)
404};
405
406bool wxIsDragResultOk(wxDragResult res);
407
408//----------------------------------------------------------------------
409%{
410class wxPyDropSource : public wxDropSource {
411public:
412#ifdef __WXMSW__
413 wxPyDropSource(wxWindow *win = NULL,
414 const wxCursor &cursorCopy = wxNullCursor,
415 const wxCursor &cursorMove = wxNullCursor,
416 const wxCursor &cursorStop = wxNullCursor)
417 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
418#else
419 wxPyDropSource(wxWindow *win = NULL,
420 const wxIcon &go = wxNullIcon)
421 : wxDropSource(win, go) {}
422#endif
423 ~wxPyDropSource() { }
424
425 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
426 PYPRIVATE;
427};
428
429IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
430
431%}
432
433
434%name(wxDropSource) class wxPyDropSource {
435public:
436#ifdef __WXMSW__
437 wxPyDropSource(wxWindow *win = NULL,
438 const wxCursor &cursorCopy = wxNullCursor,
439 const wxCursor &cursorMove = wxNullCursor,
440 const wxCursor &cursorStop = wxNullCursor);
441#else
442 wxPyDropSource(wxWindow *win = NULL,
443 const wxIcon &go = wxNullIcon);
444#endif
445
446 void _setSelf(PyObject* self, PyObject* _class, int incref);
447 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxDropSource, 0)"
448 ~wxPyDropSource();
449
450 void SetData(wxDataObject& data);
451 wxDataObject *GetDataObject();
452 void SetCursor(wxDragResult res, const wxCursor& cursor);
453 wxDragResult DoDragDrop(int bAllowMove = FALSE);
454
455 bool base_GiveFeedback(wxDragResult effect);
456};
457
458//----------------------------------------------------------------------
459
460// Just a place holder for the type system. The real base class for
461// wxPython is wxPyDropTarget
462class wxDropTarget {
463public:
464};
465
466
467%{
468class wxPyDropTarget : public wxDropTarget {
469public:
470 wxPyDropTarget(wxDataObject *dataObject = NULL)
471 : wxDropTarget(dataObject) {}
472
473// DEC_PYCALLBACK_SIZET_(GetFormatCount);
474// DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
475
476 DEC_PYCALLBACK__(OnLeave);
477 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
478 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
479 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
480 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
481
482 PYPRIVATE;
483};
484
485// IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
486// IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
487
488IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
489IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
490IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
491IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
492IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
493
494%}
495
496
497class wxPyDropTarget : public wxDropTarget {
498public:
499 wxPyDropTarget(wxDataObject *dataObject = NULL);
500 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
501 void _setSelf(PyObject* self, PyObject* _class);
502 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyDropTarget)"
503
504 ~wxPyDropTarget();
505
506 wxDataObject *GetDataObject();
507 void SetDataObject(wxDataObject *dataObject);
508 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
509
510// size_t base_GetFormatCount();
511// wxDataFormat base_GetFormat(size_t n);
512
513 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
514 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
515 void base_OnLeave();
516 bool base_OnDrop(wxCoord x, wxCoord y);
517 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
518
519 // **** not sure about this one
520 bool GetData();
521
522};
523
524
525//----------------------------------------------------------------------
526
527%{
528class wxPyTextDropTarget : public wxTextDropTarget {
529public:
530 wxPyTextDropTarget() {}
531
532 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
533
534 DEC_PYCALLBACK__(OnLeave);
535 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
536 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
537 DEC_PYCALLBACK_DR_2WXCDR(OnData);
538 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
539
540 PYPRIVATE;
541};
542
543IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
544IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
545IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
546IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
547IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
548IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
549
550%}
551
552%name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
553public:
554 wxPyTextDropTarget();
555 void _setSelf(PyObject* self, PyObject* _class);
556 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTextDropTarget)"
557
558 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
559 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
560 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
561 void base_OnLeave();
562 bool base_OnDrop(wxCoord x, wxCoord y);
563 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
564};
565
566//----------------------------------------------------------------------
567%{
568class wxPyFileDropTarget : public wxFileDropTarget {
569public:
570 wxPyFileDropTarget() {}
571
572 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
573
574 DEC_PYCALLBACK__(OnLeave);
575 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
576 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
577 DEC_PYCALLBACK_DR_2WXCDR(OnData);
578 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
579
580 PYPRIVATE;
581};
582
583bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
584 const wxArrayString& filenames) {
585 bool rval = FALSE;
586 bool doSave = wxPyRestoreThread();
587 PyObject* list = PyList_New(0);
588 for (size_t i=0; i<filenames.GetCount(); i++) {
589 PyObject* str = PyString_FromString(filenames[i].c_str());
590 PyList_Append(list, str);
591 }
592 if (m_myInst.findCallback("OnDropFiles"))
593 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
594 Py_DECREF(list);
595 wxPySaveThread(doSave);
596 return rval;
597}
598
599
600
601IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
602IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
603IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
604IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
605IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
606
607%}
608
609
610%name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
611{
612public:
613 wxPyFileDropTarget();
614 void _setSelf(PyObject* self, PyObject* _class);
615 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxFileDropTarget)"
616
617// bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
618 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
619 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
620 void base_OnLeave();
621 bool base_OnDrop(wxCoord x, wxCoord y);
622 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
623};
624
625//----------------------------------------------------------------------
626//----------------------------------------------------------------------
627//----------------------------------------------------------------------
628
629%init %{
630
631 wxPyTheClipboard = wxTheClipboard;
632 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
633 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
634 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
635%}
636
637//----------------------------------------------------------------------
638