]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/src/clip_dnd.i
New toolbar wrappers
[wxWidgets.git] / utils / wxPython / src / clip_dnd.i
CommitLineData
b1462dfa
RD
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 rval = (ro != Py_None && PyString_Check(ro));
155 if (rval)
156 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
157 }
158 wxPySaveThread(doSave);
159 return rval;
160}
161
162bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
163 // For this one we simply need to make a string from buf and len
164 // and send it to the Python method.
165 bool rval = FALSE;
166 bool doSave = wxPyRestoreThread();
167 if (m_myInst.findCallback("SetData")) {
168 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
169 rval = m_myInst.callCallback(Py_BuildValue("(O)", data));
170 Py_DECREF(data);
171 }
172 wxPySaveThread(doSave);
173 return rval;
174}
175%}
176
177
178
179// Now define it for SWIG
180class wxPyDataObjectSimple : public wxDataObjectSimple {
181public:
182 wxPyDataObjectSimple(const wxDataFormat& format = wxPyFormatInvalid);
183 void _setSelf(PyObject* self);
184 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
185};
186
187//----------------------------------------------------------------------
188
189class wxDataObjectComposite : public wxDataObject {
190public:
191 wxDataObjectComposite();
192
193 void Add(wxDataObjectSimple *dataObject, int preferred = FALSE);
194 %pragma(python) addtomethod = "Add:_args[0].thisown = 0"
195
196};
197
198
199//----------------------------------------------------------------------
200
201class wxTextDataObject : public wxDataObjectSimple {
202public:
203 wxTextDataObject(const wxString& text = wxEmptyString);
204
205 size_t GetTextLength();
206 wxString GetText();
207 void SetText(const wxString& text);
208};
209
210
211
212%{ // Create a new class for wxPython to use
213class wxPyTextDataObject : public wxTextDataObject {
214public:
215 wxPyTextDataObject(const wxString& text = wxEmptyString)
216 : wxTextDataObject(text) {}
217
218 DEC_PYCALLBACK_SIZET_(GetTextLength);
219 DEC_PYCALLBACK_STRING_(GetText);
220 DEC_PYCALLBACK__STRING(SetText);
221 PYPRIVATE;
222};
223
224IMP_PYCALLBACK_SIZET_(wxPyTextDataObject, wxTextDataObject, GetTextLength);
225IMP_PYCALLBACK_STRING_(wxPyTextDataObject, wxTextDataObject, GetText);
226IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
227
228%}
229
230
231// Now define it for SWIG
232class wxPyTextDataObject : public wxTextDataObject {
233public:
234 wxPyTextDataObject(const wxString& text = wxEmptyString);
235 void _setSelf(PyObject* self);
236 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
237};
238
239//----------------------------------------------------------------------
240
241class wxBitmapDataObject : public wxDataObjectSimple {
242public:
243 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
244
245 wxBitmap GetBitmap();
246 void SetBitmap(const wxBitmap& bitmap);
247};
248
249
250
251%{ // Create a new class for wxPython to use
252class wxPyBitmapDataObject : public wxBitmapDataObject {
253public:
254 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
255 : wxBitmapDataObject(bitmap) {}
256
257 wxBitmap GetBitmap();
258 void SetBitmap(const wxBitmap& bitmap);
259 PYPRIVATE;
260};
261
262wxBitmap wxPyBitmapDataObject::GetBitmap() {
263 wxBitmap* rval = &wxNullBitmap;
264 bool doSave = wxPyRestoreThread();
265 if (m_myInst.findCallback("GetBitmap")) {
266 PyObject* ro;
267 wxBitmap* ptr;
268 ro = m_myInst.callCallbackObj(Py_BuildValue("()"));
269 if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxBitmap_p"))
270 rval = ptr;
271 }
272 wxPySaveThread(doSave);
273 return *rval;
274}
275
276void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
277 bool doSave = wxPyRestoreThread();
278 if (m_myInst.findCallback("SetBitmap")) {
279 m_myInst.callCallback(Py_BuildValue("(O)",
280 wxPyConstructObject((void*)&bitmap, "wxBitmap")));
281 }
282 wxPySaveThread(doSave);
283}
284%}
285
286
287
288// Now define it for SWIG
289class wxPyBitmapDataObject : public wxBitmapDataObject {
290public:
291 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
292 void _setSelf(PyObject* self);
293 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
294};
295
296
297//----------------------------------------------------------------------
298
299class wxFileDataObject : public wxDataObjectSimple
300{
301public:
302 wxFileDataObject();
303
304 //const wxArrayString& GetFilenames();
305 %addmethods {
306 PyObject* GetFilenames() {
307 const wxArrayString& strings = self->GetFilenames();
308 PyObject* list = PyList_New(0);
309 for (size_t x=0; x<strings.GetCount(); x++)
310 PyList_Append(list, PyString_FromString(strings[x]));
311 return list;
312 }
313 }
314
315 //void AddFile(const wxString &filename);
316};
317
318
319//----------------------------------------------------------------------
320
321class wxCustomDataObject : public wxDataObjectSimple {
322public:
323 wxCustomDataObject(const wxDataFormat& format = wxPyFormatInvalid);
324
325 //void TakeData(size_t size, void *data);
326 //bool SetData(size_t size, const void *buf);
327 %addmethods {
328 void TakeData(PyObject* data) {
329 if (PyString_Check(data)) {
330 self->SetData(PyString_Size(data), PyString_AsString(data));
331 }
332 }
333 bool SetData(PyObject* data) {
334 if (PyString_Check(data)) {
335 return self->SetData(PyString_Size(data), PyString_AsString(data));
336 }
337 return FALSE;
338 }
339 }
340
341 size_t GetSize();
342 //void *GetData();
343 %addmethods {
344 PyObject* GetData() {
345 return PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
346 }
347 }
348
349
350};
351
352
353
354//----------------------------------------------------------------------
355//----------------------------------------------------------------------
356//----------------------------------------------------------------------
357
358class wxClipboard {
359public:
360 wxClipboard();
361
362 bool Open();
363 void Close();
364 bool IsOpened() const;
365
366 bool AddData( wxDataObject *data );
367 %pragma(python) addtomethod = "AddData:_args[0].thisown = 0"
368 bool SetData( wxDataObject *data );
369 %pragma(python) addtomethod = "SetData:_args[0].thisown = 0"
370
371 bool IsSupported( const wxDataFormat& format );
372 bool GetData( wxDataObject& data );
373 void Clear();
374 bool Flush();
375 void UsePrimarySelection( int primary = FALSE );
376};
377
378%{
6999b0d8 379 // See below in the init function...
b1462dfa
RD
380 wxClipboard* wxPyTheClipboard;
381%}
382%readonly
383%name(wxTheClipboard) wxClipboard* wxPyTheClipboard;
384%readwrite
385
386//----------------------------------------------------------------------
387//----------------------------------------------------------------------
388
389enum wxDragResult
390{
391 wxDragError, // error prevented the d&d operation from completing
392 wxDragNone, // drag target didn't accept the data
393 wxDragCopy, // the data was successfully copied
394 wxDragMove, // the data was successfully moved (MSW only)
395 wxDragCancel // the operation was cancelled by user (not an error)
396};
397
398bool wxIsDragResultOk(wxDragResult res);
399
400//----------------------------------------------------------------------
401%{
402class wxPyDropSource : public wxDropSource {
403public:
4120ef2b 404#ifdef __WXMSW__
b1462dfa
RD
405 wxPyDropSource(wxWindow *win = NULL,
406 const wxCursor &cursorCopy = wxNullCursor,
407 const wxCursor &cursorMove = wxNullCursor,
408 const wxCursor &cursorStop = wxNullCursor)
409 : wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
4120ef2b
RD
410#else
411 wxPyDropSource(wxWindow *win = NULL,
412 const wxIcon &go = wxNullIcon)
413 : wxDropSource(win, go) {}
414#endif
077def0b 415 ~wxPyDropSource() { }
dafb483b 416
b1462dfa
RD
417 DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
418 PYPRIVATE;
419};
420
421IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
422
423%}
424
425
426%name(wxDropSource) class wxPyDropSource {
427public:
4120ef2b 428#ifdef __WXMSW__
b1462dfa
RD
429 wxPyDropSource(wxWindow *win = NULL,
430 const wxCursor &cursorCopy = wxNullCursor,
431 const wxCursor &cursorMove = wxNullCursor,
432 const wxCursor &cursorStop = wxNullCursor);
4120ef2b
RD
433#else
434 wxPyDropSource(wxWindow *win = NULL,
435 const wxIcon &go = wxNullIcon);
436#endif
437
dafb483b
RD
438 void _setSelf(PyObject* self, int incref);
439 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
b1462dfa
RD
440 ~wxPyDropSource();
441
442 void SetData(wxDataObject& data);
443 wxDataObject *GetDataObject();
444 void SetCursor(wxDragResult res, const wxCursor& cursor);
445 wxDragResult DoDragDrop(int bAllowMove = FALSE);
446
447 bool base_GiveFeedback(wxDragResult effect);
448};
449
450//----------------------------------------------------------------------
451
452// Just a place holder for the type system. The real base class for
453// wxPython is wxPyDropTarget
454class wxDropTarget {
455public:
456};
457
458
459%{
460class wxPyDropTarget : public wxDropTarget {
461public:
462 wxPyDropTarget(wxDataObject *dataObject = NULL)
463 : wxDropTarget(dataObject) {}
464
465// DEC_PYCALLBACK_SIZET_(GetFormatCount);
466// DEC_PYCALLBACK_DATAFMT_SIZET(GetFormat);
467
468 DEC_PYCALLBACK__(OnLeave);
469 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
470 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
471 DEC_PYCALLBACK_DR_2WXCDR_pure(OnData);
472 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
473
474 PYPRIVATE;
475};
476
477// IMP_PYCALLBACK_SIZET_(wxPyDropTarget, wxDropTarget, GetFormatCount);
478// IMP__PYCALLBACK_DATAFMT_SIZET(wxPyDropTarget, wxDropTarget, GetFormat);
479
480IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
481IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
482IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
483IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
484IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
485
486%}
487
488
489class wxPyDropTarget : public wxDropTarget {
490public:
491 wxPyDropTarget(wxDataObject *dataObject = NULL);
492 %pragma(python) addtomethod = "__init__:if _args:_args[0].thisown = 0"
493 void _setSelf(PyObject* self);
494 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
495
496 ~wxPyDropTarget();
497
498 wxDataObject *GetDataObject();
499 void SetDataObject(wxDataObject *dataObject);
500 %pragma(python) addtomethod = "SetDataObject:if _args:_args[0].thisown = 0"
501
502// size_t base_GetFormatCount();
503// wxDataFormat base_GetFormat(size_t n);
504
505 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
506 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
507 void base_OnLeave();
508 bool base_OnDrop(wxCoord x, wxCoord y);
509 //wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
510
511 // **** not sure about this one
512 bool GetData();
513
514};
515
516
517//----------------------------------------------------------------------
518
519%{
520class wxPyTextDropTarget : public wxTextDropTarget {
521public:
522 wxPyTextDropTarget() {}
523
524 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
525
526 DEC_PYCALLBACK__(OnLeave);
527 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
528 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
529 DEC_PYCALLBACK_DR_2WXCDR(OnData);
530 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
531
532 PYPRIVATE;
533};
534
535IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
536IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
537IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
538IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
539IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
540IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
541
542%}
543
544%name(wxTextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
545public:
546 wxPyTextDropTarget();
547 void _setSelf(PyObject* self);
548 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
549
550 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
551 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
552 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
553 void base_OnLeave();
554 bool base_OnDrop(wxCoord x, wxCoord y);
555 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
556};
557
558//----------------------------------------------------------------------
559%{
560class wxPyFileDropTarget : public wxFileDropTarget {
561public:
562 wxPyFileDropTarget() {}
563
564 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
565
566 DEC_PYCALLBACK__(OnLeave);
567 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
568 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
569 DEC_PYCALLBACK_DR_2WXCDR(OnData);
570 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
571
572 PYPRIVATE;
573};
574
575bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
576 const wxArrayString& filenames) {
577 bool rval = FALSE;
578 bool doSave = wxPyRestoreThread();
579 PyObject* list = PyList_New(0);
580 for (size_t i=0; i<filenames.GetCount(); i++) {
581 PyObject* str = PyString_FromString(filenames[i].c_str());
582 PyList_Append(list, str);
583 }
584 if (m_myInst.findCallback("OnDropFiles"))
585 rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list));
586 Py_DECREF(list);
587 wxPySaveThread(doSave);
588 return rval;
589}
590
591
592
593IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
594IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
595IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
596IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
597IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
598
599%}
600
601
602%name(wxFileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
603{
604public:
605 wxPyFileDropTarget();
606 void _setSelf(PyObject* self);
607 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
608
609// bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
610 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
611 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
612 void base_OnLeave();
613 bool base_OnDrop(wxCoord x, wxCoord y);
614 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
615};
616
617//----------------------------------------------------------------------
618//----------------------------------------------------------------------
619//----------------------------------------------------------------------
620
621%init %{
622
623 wxPyTheClipboard = wxTheClipboard;
624
625%}
626
627//----------------------------------------------------------------------
628