]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/clip_dnd.i
use specific linker flags under Mac OS X when linking executables against the
[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,
49 wxDF_TEXT,
50 wxDF_BITMAP,
51 wxDF_METAFILE,
52 wxDF_SYLK,
53 wxDF_DIF,
54 wxDF_TIFF,
55 wxDF_OEMTEXT,
56 wxDF_DIB,
57 wxDF_PALETTE,
58 wxDF_PENDATA,
59 wxDF_RIFF,
60 wxDF_WAVE,
61 wxDF_UNICODETEXT,
62 wxDF_ENHMETAFILE,
63 wxDF_FILENAME,
64 wxDF_LOCALE,
65 wxDF_PRIVATE,
66 wxDF_HTML,
67 wxDF_MAX,
68};
69
70//----------------------------------------------------------------------
71
72class wxDataFormat {
73public:
74 wxDataFormat( wxDataFormatId type );
75 ~wxDataFormat();
76
77 void SetType(wxDataFormatId format);
78 wxDataFormatId GetType() const;
79
80 wxString GetId() const;
81 void SetId(const wxString& format);
82};
83
84%new wxDataFormat* wxCustomDataFormat(const wxString &id);
85%{ // An alternate constructor...
86 wxDataFormat* wxCustomDataFormat(const wxString &id) {
87 return new wxDataFormat(id);
88 }
89%}
90
91
92%{
93wxDataFormat wxPyFormatInvalid;
94%}
95%readonly
96%name(wxFormatInvalid) wxDataFormat wxPyFormatInvalid;
97%readwrite
98
99
100//----------------------------------------------------------------------
101
102
103
104class wxDataObject { // An abstract base class
105public:
106 enum Direction {
107 Get = 0x01, // format is supported by GetDataHere()
108 Set = 0x02, // format is supported by SetData()
109 Both = 0x03 // format is supported by both (unused currently)
110 };
111
112 ~wxDataObject();
113
114 wxDataFormat GetPreferredFormat(Direction dir = wxDataObject::Get);
115 size_t GetFormatCount(Direction dir = wxDataObject::Get);
116 void GetAllFormats(wxDataFormat *formats,
117 Direction dir = wxDataObject::Get);
118 size_t GetDataSize(const wxDataFormat& format);
119 bool GetDataHere(const wxDataFormat& format, void *buf);
120 bool SetData(const wxDataFormat& format,
121 size_t len, const void * buf);
122 bool IsSupportedFormat(const wxDataFormat& format);
123};
124
125//----------------------------------------------------------------------
126
127class wxDataObjectSimple : public wxDataObject {
128public:
129 wxDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
130
131 const wxDataFormat& GetFormat();
132 void SetFormat(const wxDataFormat& format);
133
134};
135
136
137%{ // Create a new class for wxPython to use
138class wxPyDataObjectSimple : public wxDataObjectSimple {
139public:
140 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid)
141 : wxDataObjectSimple(format) {}
142
143 DEC_PYCALLBACK_SIZET_(GetDataSize);
144 bool GetDataHere(void *buf);
145 bool SetData(size_t len, const void *buf);
146 PYPRIVATE;
147};
148
149IMP_PYCALLBACK_SIZET_(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
150
151bool wxPyDataObjectSimple::GetDataHere(void *buf) {
152 // We need to get the data for this object and write it to buf. I think
153 // the best way to do this for wxPython is to have the Python method
154 // return either a string or None and then act appropriately with the
155 // C++ version.
156
157 bool rval = FALSE;
158 wxPyBeginBlockThreads();
159 if (m_myInst.findCallback("GetDataHere")) {
160 PyObject* ro;
161 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
162 if (ro) {
163 rval = (ro != Py_None && PyString_Check(ro));
164 if (rval)
165 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
166 Py_DECREF(ro);
167 }
168 }
169 wxPyEndBlockThreads();
170 return rval;
171}
172
173bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
174 // For this one we simply need to make a string from buf and len
175 // and send it to the Python method.
176 bool rval = FALSE;
177 wxPyBeginBlockThreads();
178 if (m_myInst.findCallback("SetData")) {
179 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
180 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
181 Py_DECREF(data);
182 }
183 wxPyEndBlockThreads();
184 return rval;
185}
186%}
187
188
189
190// Now define it for SWIG
191class wxPyDataObjectSimple : public wxDataObjectSimple {
192public:
193 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
194 void _setCallbackInfo(PyObject* self, PyObject* _class);
195 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDataObjectSimple)"
196};
197
198//----------------------------------------------------------------------
199
200class wxDataObjectComposite : public wxDataObject {
201public:
202 wxDataObjectComposite();
203
204 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
205 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
206
207};
208
209
210//----------------------------------------------------------------------
211
212class wxTextDataObject : public wxDataObjectSimple {
213public:
214 wxTextDataObject(const wxString& text = wxPyEmptyString);
215
216 size_t GetTextLength();
217 wxString GetText();
218 void SetText(const wxString& text);
219};
220
221
222
223%{ // Create a new class for wxPython to use
224class wxPyTextDataObject : public wxTextDataObject {
225public:
226 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
227 : wxTextDataObject(text) {}
228
229 DEC_PYCALLBACK_SIZET_(GetTextLength);
230 DEC_PYCALLBACK_STRING_(GetText);
231 DEC_PYCALLBACK__STRING(SetText);
232 PYPRIVATE;
233};
234
235IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
236IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
237IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
238
239%}
240
241
242// Now define it for SWIG
243class wxPyTextDataObject : public wxTextDataObject {
244public:
245 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
246 void _setCallbackInfo(PyObject* self, PyObject* _class);
247 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyTextDataObject)"
248};
249
250//----------------------------------------------------------------------
251
252class wxBitmapDataObject : public wxDataObjectSimple {
253public:
254 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
255
256 wxBitmap GetBitmap();
257 void SetBitmap(const wxBitmap& bitmap);
258};
259
260
261
262%{ // Create a new class for wxPython to use
263class wxPyBitmapDataObject : public wxBitmapDataObject {
264public:
265 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
266 : wxBitmapDataObject(bitmap) {}
267
268 wxBitmap GetBitmap();
269 void SetBitmap(const wxBitmap& bitmap);
270 PYPRIVATE;
271};
272
273wxBitmap wxPyBitmapDataObject::GetBitmap() {
274 wxBitmap* rval = &wxNullBitmap;
275 wxPyBeginBlockThreads();
276 if (m_myInst.findCallback("GetBitmap")) {
277 PyObject* ro;
278 wxBitmap* ptr;
279 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
280 if (ro) {
281 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
282 rval = ptr;
283 Py_DECREF(ro);
284 }
285 }
286 wxPyEndBlockThreads();
287 return *rval;
288}
289
290void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
291 wxPyBeginBlockThreads();
292 if (m_myInst.findCallback("SetBitmap")) {
293 m_myInst.callCallback(Py_BuildValue("(O)",
294 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
295 }
296 wxPyEndBlockThreads();
297}
298%}
299
300
301
302// Now define it for SWIG
303class wxPyBitmapDataObject : public wxBitmapDataObject {
304public:
305 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
306 void _setCallbackInfo(PyObject* self, PyObject* _class);
307 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyBitmapDataObject)"
308};
309
310
311//----------------------------------------------------------------------
312
313class wxFileDataObject : public wxDataObjectSimple
314{
315public:
316 wxFileDataObject();
317
318 //const wxArrayString& GetFilenames();
319 %addmethods {
320 PyObject* GetFilenames() {
321 const wxArrayString& strings = self->GetFilenames();
322 return wxArrayString2PyList_helper(strings);
323 }
324 }
325#ifdef __WXMSW__
326 void AddFile(const wxString &filename);
327#endif
328};
329
330
331//----------------------------------------------------------------------
332
333class wxCustomDataObject : public wxDataObjectSimple {
334public:
335 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
336
337 //void TakeData(size_t size, void *data);
338 //bool SetData(size_t size, const void *buf);
339 %addmethods {
340 void TakeData(PyObject* data) {
341 if (PyString_Check(data)) {
342 self->SetData(PyString_Size(data), PyString_AsString(data));
343 }
344 }
345 bool SetData(PyObject* data) {
346 if (PyString_Check(data)) {
347 return self->SetData(PyString_Size(data), PyString_AsString(data));
348 }
349 return FALSE;
350 }
351 }
352
353 size_t GetSize();
354
355 //void *GetData();
356 %addmethods {
357 PyObject* GetData() {
358 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
359 }
360 }
361
362
363};
364
365
366//----------------------------------------------------------------------
367
368class wxURLDataObject : public wxDataObjectComposite {
369public:
370 wxURLDataObject();
371
372 wxString GetURL();
373 void SetURL(const wxString& url);
374};
375
376//----------------------------------------------------------------------
377
378#ifndef __WXGTK__
379
380%{
381#include <wx/metafile.h>
382%}
383
384class wxMetafileDataObject : public wxDataObjectSimple
385{
386public:
387 wxMetafileDataObject();
388
389 void SetMetafile(const wxMetafile& metafile);
390 wxMetafile GetMetafile() const;
391};
392
393#endif
394
395//----------------------------------------------------------------------
396//----------------------------------------------------------------------
397//----------------------------------------------------------------------
398
399class wxClipboard : public wxObject {
400public:
401 wxClipboard();
402
403 bool Open();
404 void Close();
405 bool IsOpened() const;
406
407 bool AddData( wxDataObject *data );
408 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
409 bool SetData( wxDataObject *data );
410 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
411
412 bool IsSupported( const wxDataFormat& format );
413 bool GetData( wxDataObject& data );
414 void Clear();
415 bool Flush();
416 void UsePrimarySelection( int primary = FALSE );
417};
418
419%{
420 // See below in the init function...
421 wxClipboard* wxPyTheClipboard;
422%}
423%readonly
424%name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
425%readwrite
426
427//----------------------------------------------------------------------
428//----------------------------------------------------------------------
429
430enum wxDragResult
431{
432 wxDragError, // error prevented the d&d operation from completing
433 wxDragNone, // drag target didn't accept the data
434 wxDragCopy, // the data was successfully copied
435 wxDragMove, // the data was successfully moved (MSW only)
436 wxDragLink, // operation is a drag-link
437 wxDragCancel // the operation was cancelled by user (not an error)
438};
439
440bool wxIsDragResultOk(wxDragResult res);
441
442//----------------------------------------------------------------------
443%{
444class wxPyDropSource : public wxDropSource {
445public:
446#ifdef __WXMSW__
447 wxPyDropSource(wxWindow *win = NULL,
448 const wxCursor &cursorCopy = wxNullCursor,
449 const wxCursor &cursorMove = wxNullCursor,
450 const wxCursor &cursorStop = wxNullCursor)
451 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
452#else
453 wxPyDropSource(wxWindow *win = NULL,
454 const wxIcon &go = wxNullIcon)
455 : wxDropSource(win, go) {}
456#endif
457 ~wxPyDropSource() { }
458
459 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
460 PYPRIVATE;
461};
462
463IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
464
465%}
466
467
468%name(wxDropSource) class wxPyDropSource {
469public:
470#ifdef __WXMSW__
471 wxPyDropSource(wxWindow *win = NULL,
472 const wxCursor &cursorCopy = wxNullCursor,
473 const wxCursor &cursorMove = wxNullCursor,
474 const wxCursor &cursorStop = wxNullCursor);
475#else
476 wxPyDropSource(wxWindow *win = NULL,
477 const wxIcon &go = wxNullIcon);
478#endif
479
480 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
481 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
482 ~wxPyDropSource();
483
484 void SetData(wxDataObject& data);
485 wxDataObject *GetDataObject();
486 void SetCursor(wxDragResult res, const wxCursor& cursor);
487 wxDragResult DoDragDrop(int bAllowMove = FALSE);
488
489 bool base_GiveFeedback(wxDragResult effect);
490};
491
492//----------------------------------------------------------------------
493
494// Just a place holder for the type system. The real base class for
495// wxPython is wxPyDropTarget
496class wxDropTarget {
497public:
498};
499
500
501%{
502class wxPyDropTarget : public wxDropTarget {
503public:
504 wxPyDropTarget(wxDataObject *dataObject = NULL)
505 : wxDropTarget(dataObject) {}
506
507// DEC_PYCALLBACK_SIZET_(GetFormatCount);
508// DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
509
510 DEC_PYCALLBACK__(OnLeave);
511 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
512 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
513 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
514 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
515
516 PYPRIVATE;
517};
518
519// IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
520// IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
521
522IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
523IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
524IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
525IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
526IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
527
528%}
529
530
531class wxPyDropTarget : public wxDropTarget {
532public:
533 wxPyDropTarget(wxDataObject *dataObject = NULL);
534 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
535 void _setCallbackInfo(PyObject* self, PyObject* _class);
536 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyDropTarget)"
537
538 ~wxPyDropTarget();
539
540 wxDataObject *GetDataObject();
541 void SetDataObject(wxDataObject *dataObject);
542 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
543
544// size_t base_GetFormatCount();
545// wxDataFormat base_GetFormat(size_t n);
546
547 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
548 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
549 void base_OnLeave();
550 bool base_OnDrop(wxCoord x, wxCoord y);
551 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
552
553 // **** not sure about this one
554 bool GetData();
555
556};
557
558
559//----------------------------------------------------------------------
560
561%{
562class wxPyTextDropTarget : public wxTextDropTarget {
563public:
564 wxPyTextDropTarget() {}
565
566 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
567
568 DEC_PYCALLBACK__(OnLeave);
569 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
570 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
571 DEC_PYCALLBACK_DR_2WXCDR(OnData);
572 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
573
574 PYPRIVATE;
575};
576
577IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
578IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
579IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
580IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
581IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
582IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
583
584%}
585
586%name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
587public:
588 wxPyTextDropTarget();
589 void _setCallbackInfo(PyObject* self, PyObject* _class);
590 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTextDropTarget)"
591
592 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
593 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
594 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
595 void base_OnLeave();
596 bool base_OnDrop(wxCoord x, wxCoord y);
597 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
598};
599
600//----------------------------------------------------------------------
601%{
602class wxPyFileDropTarget : public wxFileDropTarget {
603public:
604 wxPyFileDropTarget() {}
605
606 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
607
608 DEC_PYCALLBACK__(OnLeave);
609 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
610 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
611 DEC_PYCALLBACK_DR_2WXCDR(OnData);
612 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
613
614 PYPRIVATE;
615};
616
617bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
618 const wxArrayString& filenames) {
619 bool rval = FALSE;
620 wxPyBeginBlockThreads();
621 PyObject* list = wxArrayString2PyList_helper(filenames);
622 if (m_myInst.findCallback("OnDropFiles"))
623 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
624 Py_DECREF(list);
625 wxPyEndBlockThreads();
626 return rval;
627}
628
629
630
631IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
632IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
633IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
634IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
635IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
636
637%}
638
639
640%name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
641{
642public:
643 wxPyFileDropTarget();
644 void _setCallbackInfo(PyObject* self, PyObject* _class);
645 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileDropTarget)"
646
647// bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
648 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
649 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
650 void base_OnLeave();
651 bool base_OnDrop(wxCoord x, wxCoord y);
652 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
653};
654
655//----------------------------------------------------------------------
656//----------------------------------------------------------------------
657//----------------------------------------------------------------------
658
659%init %{
660
661 wxPyTheClipboard = wxTheClipboard;
662 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
663 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
664 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
665%}
666
667//----------------------------------------------------------------------
668#endif
669