]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/_dataobj.i
implemented DrawPoint in terms of DrawLine (for now)
[wxWidgets.git] / wxPython / src / _dataobj.i
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: _dataobj.i
3// Purpose: SWIG definitions for the Data Object classes
4//
5// Author: Robin Dunn
6//
7// Created: 31-October-1999
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17
18%{
19#include <wx/dataobj.h>
20%}
21
22//---------------------------------------------------------------------------
23%newgroup
24
25
26enum wxDataFormatId
27{
28 wxDF_INVALID,
29 wxDF_TEXT,
30 wxDF_BITMAP,
31 wxDF_METAFILE,
32 wxDF_SYLK,
33 wxDF_DIF,
34 wxDF_TIFF,
35 wxDF_OEMTEXT,
36 wxDF_DIB,
37 wxDF_PALETTE,
38 wxDF_PENDATA,
39 wxDF_RIFF,
40 wxDF_WAVE,
41 wxDF_UNICODETEXT,
42 wxDF_ENHMETAFILE,
43 wxDF_FILENAME,
44 wxDF_LOCALE,
45 wxDF_PRIVATE,
46 wxDF_HTML,
47 wxDF_MAX,
48};
49
50
51DocStr(wxDataFormat,
52"A wx.DataFormat is an encapsulation of a platform-specific format
53handle which is used by the system for the clipboard and drag and drop
54operations. The applications are usually only interested in, for
55example, pasting data from the clipboard only if the data is in a
56format the program understands. A data format is is used to uniquely
57identify this format.",
58"
59On the system level, a data format is usually just a number, (which
60may be the CLIPFORMAT under Windows or Atom under X11, for example.)
61
62The standard format IDs are:
63
64 ================ =====================================
65 wx.DF_INVALID An invalid format
66 wx.DF_TEXT Text format
67 wx.DF_BITMAP A bitmap (wx.Bitmap)
68 wx.DF_METAFILE A metafile (wx.Metafile, Windows only)
69 wx.DF_FILENAME A list of filenames
70 wx.DF_HTML An HTML string. This is only valid on
71 Windows and non-unicode builds
72 ================ =====================================
73
74Besies the standard formats, the application may also use custom
75formats which are identified by their names (strings) and not numeric
76identifiers. Although internally custom format must be created (or
77registered) first, you shouldn\'t care about it because it is done
78automatically the first time the wxDataFormat object corresponding to
79a given format name is created.
80
81");
82
83class wxDataFormat {
84public:
85 DocCtorStr(
86 wxDataFormat( wxDataFormatId type ),
87 "Constructs a data format object for one of the standard data formats
88or an empty data object (use SetType or SetId later in this case)", "");
89
90 DocCtorStrName(
91 wxDataFormat(const wxString& format),
92 "Constructs a data format object for a custom format identified by its
93name.", "",
94 CustomDataFormat);
95
96 ~wxDataFormat();
97
98
99 %nokwargs operator==;
100 %nokwargs operator!=;
101 bool operator==(wxDataFormatId format) const;
102 bool operator!=(wxDataFormatId format) const;
103 bool operator==(const wxDataFormat& format) const;
104 bool operator!=(const wxDataFormat& format) const;
105
106
107 DocDeclStr(
108 void , SetType(wxDataFormatId format),
109 "Sets the format to the given value, which should be one of wx.DF_XXX
110constants.", "");
111
112 DocDeclStr(
113 wxDataFormatId , GetType() const,
114 "Returns the platform-specific number identifying the format.", "");
115
116
117 DocDeclStr(
118 wxString , GetId() const,
119 "Returns the name of a custom format (this function will fail for a
120standard format).", "");
121
122 DocDeclStr(
123 void , SetId(const wxString& format),
124 "Sets the format to be the custom format identified by the given name.", "");
125
126 %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
127 %property(Type, GetType, SetType, doc="See `GetType` and `SetType`");
128};
129
130
131%immutable;
132const wxDataFormat wxFormatInvalid;
133%mutable;
134
135//---------------------------------------------------------------------------
136
137
138DocStr(wxDataObject,
139"A wx.DataObject represents data that can be copied to or from the
140clipboard, or dragged and dropped. The important thing about
141wx.DataObject is that this is a 'smart' piece of data unlike usual
142'dumb' data containers such as memory buffers or files. Being 'smart'
143here means that the data object itself should know what data formats
144it supports and how to render itself in each of supported formats.
145
146**NOTE**: This class is an abstract base class and can not be used
147directly from Python. If you need a custom type of data object then
148you should instead derive from `wx.PyDataObjectSimple` or use
149`wx.CustomDataObject`.
150", "
151Not surprisingly, being 'smart' comes at a price of added
152complexity. This is reasonable for the situations when you really need
153to support multiple formats, but may be annoying if you only want to
154do something simple like cut and paste text.
155
156To provide a solution for both cases, wxWidgets has two predefined
157classes which derive from wx.DataObject: `wx.DataObjectSimple` and
158`wx.DataObjectComposite`. `wx.DataObjectSimple` is the simplest
159wx.DataObject possible and only holds data in a single format (such as
160text or bitmap) and `wx.DataObjectComposite` is the simplest way to
161implement a wx.DataObject which supports multiple simultaneous formats
162because it achievs this by simply holding several
163`wx.DataObjectSimple` objects.
164
165Please note that the easiest way to use drag and drop and the
166clipboard with multiple formats is by using `wx.DataObjectComposite`,
167but it is not the most efficient one as each `wx.DataObjectSimple`
168would contain the whole data in its respective formats. Now imagine
169that you want to paste 200 pages of text in your proprietary format,
170as well as Word, RTF, HTML, Unicode and plain text to the clipboard
171and even today's computers are in trouble. For this case, you will
172have to derive from wx.DataObject directly and make it enumerate its
173formats and provide the data in the requested format on
174demand. (**TODO**: This is currently not possible from Python. Make
175it so.)
176
177Note that the platform transfer mechanisms for the clipboard and drag
178and drop, do not copy any data out of the source application until
179another application actually requests the data. This is in contrast to
180the 'feel' offered to the user of a program who would normally think
181that the data resides in the clipboard after having pressed 'Copy' -
182in reality it is only declared to be available.
183");
184
185// [other docs...]
186// There are several predefined data object classes derived from
187// wxDataObjectSimple: wxFileDataObject, wxTextDataObject and
188// wxBitmapDataObject which can be used without change.
189
190// You may also derive your own data object classes from
191// wxCustomDataObject for user-defined types. The format of user-defined
192// data is given as mime-type string literal, such as 'application/word'
193// or 'image/png'. These strings are used as they are under Unix (so far
194// only GTK) to identify a format and are translated into their Windows
195// equivalent under Win32 (using the OLE IDataObject for data exchange to
196// and from the clipboard and for drag and drop). Note that the format
197// string translation under Windows is not yet finished.
198
199
200
201class wxDataObject {
202public:
203 enum Direction {
204 Get = 0x01, // format is supported by GetDataHere()
205 Set = 0x02, // format is supported by SetData()
206 Both = 0x03 // format is supported by both (unused currently)
207 };
208
209 // wxDataObject(); // *** It's an ABC.
210 ~wxDataObject();
211
212 DocDeclStr(
213 virtual wxDataFormat , GetPreferredFormat(Direction dir = Get) const,
214 "Returns the preferred format for either rendering the data (if dir is
215Get, its default value) or for setting it. Usually this will be the
216native format of the wx.DataObject.", "");
217
218
219 DocDeclStr(
220 virtual size_t , GetFormatCount(Direction dir = Get) const,
221 "Returns the number of available formats for rendering or setting the
222data.", "");
223
224
225 DocDeclStr(
226 bool , IsSupported(const wxDataFormat& format, Direction dir = Get) const,
227 "Returns True if this format is supported.", "");
228
229
230 DocDeclStr(
231 virtual size_t , GetDataSize(const wxDataFormat& format) const,
232 "Get the (total) size of data for the given format", "");
233
234
235
236 %extend {
237 DocAStr(GetAllFormats,
238 "GetAllFormats(self, int dir=Get) -> [formats]",
239 "Returns a list of all the wx.DataFormats that this dataobject supports
240in the given direction.", "");
241 PyObject* GetAllFormats(Direction dir = Get) {
242 size_t count = self->GetFormatCount(dir);
243 wxDataFormat* formats = new wxDataFormat[count];
244 self->GetAllFormats(formats, dir);
245
246 wxPyBlock_t blocked = wxPyBeginBlockThreads();
247 PyObject* list = PyList_New(count);
248 for (size_t i=0; i<count; i++) {
249 wxDataFormat* format = new wxDataFormat(formats[i]);
250 PyObject* obj = wxPyConstructObject((void*)format, wxT("wxDataFormat"), true);
251 PyList_SET_ITEM(list, i, obj); // PyList_SET_ITEM steals a reference
252 }
253 wxPyEndBlockThreads(blocked);
254 delete [] formats;
255 return list;
256 }
257 }
258
259
260
261 // copy raw data (in the specified format) to the provided buffer, return
262 // True if data copied successfully, False otherwise
263 // virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
264
265 %extend {
266 DocAStr(GetDataHere,
267 "GetDataHere(self, DataFormat format) -> String",
268 "Get the data bytes in the specified format, returns None on failure.", "
269:todo: This should use the python buffer interface isntead...");
270 PyObject* GetDataHere(const wxDataFormat& format) {
271 PyObject* rval = NULL;
272 size_t size = self->GetDataSize(format);
273 wxPyBlock_t blocked = wxPyBeginBlockThreads();
274 if (size) {
275 char* buf = new char[size];
276 if (self->GetDataHere(format, buf))
277 rval = PyString_FromStringAndSize(buf, size);
278 delete [] buf;
279 }
280 if (! rval) {
281 rval = Py_None;
282 Py_INCREF(rval);
283 }
284 wxPyEndBlockThreads(blocked);
285 return rval;
286 }
287 }
288
289
290 // get data from the buffer of specified length (in the given format),
291 // return True if the data was read successfully, False otherwise
292 //virtual bool SetData(const wxDataFormat& format,
293 // size_t len, const void * buf);
294 DocAStr(SetData,
295 "SetData(self, DataFormat format, String data) -> bool",
296 "Set the data in the specified format from the bytes in the the data string.
297", "
298:todo: This should use the python buffer interface isntead...");
299 %extend {
300 bool SetData(const wxDataFormat& format, PyObject* data) {
301 bool rval;
302 wxPyBlock_t blocked = wxPyBeginBlockThreads();
303 if (PyString_Check(data)) {
304 rval = self->SetData(format, PyString_Size(data), PyString_AsString(data));
305 }
306 else {
307 // raise a TypeError if not a string
308 PyErr_SetString(PyExc_TypeError, "String expected.");
309 rval = false;
310 }
311 wxPyEndBlockThreads(blocked);
312 return rval;
313 }
314 }
315
316 %property(AllFormats, GetAllFormats, doc="See `GetAllFormats`");
317 %property(DataHere, GetDataHere, doc="See `GetDataHere`");
318 %property(DataSize, GetDataSize, doc="See `GetDataSize`");
319 %property(FormatCount, GetFormatCount, doc="See `GetFormatCount`");
320 %property(PreferredFormat, GetPreferredFormat, doc="See `GetPreferredFormat`");
321
322};
323
324
325//---------------------------------------------------------------------------
326
327
328DocStr(wxDataObjectSimple,
329"wx.DataObjectSimple is a `wx.DataObject` which only supports one
330format. This is the simplest possible `wx.DataObject` implementation.
331
332This is still an \"abstract base class\" meaning that you can't use it
333directly. You either need to use one of the predefined base classes,
334or derive your own class from `wx.PyDataObjectSimple`.
335", "");
336
337class wxDataObjectSimple : public wxDataObject {
338public:
339 DocCtorStr(
340 wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid),
341 "Constructor accepts the supported format (none by default) which may
342also be set later with `SetFormat`.","");
343
344
345 DocDeclStr(
346 const wxDataFormat& , GetFormat(),
347 "Returns the (one and only one) format supported by this object. It is
348assumed that the format is supported in both directions.", "");
349
350 DocDeclStr(
351 void , SetFormat(const wxDataFormat& format),
352 "Sets the supported format.", "");
353
354 DocDeclStr(
355 virtual size_t , GetDataSize() const,
356 "Get the size of our data.", "");
357
358
359
360 %extend {
361 DocAStr(GetDataHere,
362 "GetDataHere(self) -> String",
363 "Returns the data bytes from the data object as a string, returns None
364on failure. Must be implemented in the derived class if the object
365supports rendering its data.", "");
366 PyObject* GetDataHere() {
367 PyObject* rval = NULL;
368 size_t size = self->GetDataSize();
369 wxPyBlock_t blocked = wxPyBeginBlockThreads();
370 if (size) {
371 char* buf = new char[size];
372 if (self->GetDataHere(buf))
373 rval = PyString_FromStringAndSize(buf, size);
374 delete [] buf;
375 }
376 if (! rval) {
377 rval = Py_None;
378 Py_INCREF(rval);
379 }
380 wxPyEndBlockThreads(blocked);
381 return rval;
382 }
383 }
384
385
386 %extend {
387 DocAStr(SetData,
388 "SetData(self, String data) -> bool",
389 "Copy the data value to the data object. Must be implemented in the
390derived class if the object supports setting its data.
391", "");
392 bool SetData(PyObject* data) {
393 bool rval;
394 wxPyBlock_t blocked = wxPyBeginBlockThreads();
395 if (PyString_Check(data)) {
396 rval = self->SetData(PyString_Size(data), PyString_AsString(data));
397 }
398 else {
399 // raise a TypeError if not a string
400 PyErr_SetString(PyExc_TypeError, "String expected.");
401 rval = false;
402 }
403 wxPyEndBlockThreads(blocked);
404 return rval;
405 }
406 }
407
408 %property(Format, GetFormat, SetFormat, doc="See `GetFormat` and `SetFormat`");
409};
410
411
412
413
414%{ // Create a new class for wxPython to use
415class wxPyDataObjectSimple : public wxDataObjectSimple {
416public:
417 wxPyDataObjectSimple(const wxDataFormat& format = wxFormatInvalid)
418 : wxDataObjectSimple(format) {}
419
420 DEC_PYCALLBACK_SIZET__const(GetDataSize);
421 bool GetDataHere(void *buf) const;
422 bool SetData(size_t len, const void *buf);
423 PYPRIVATE;
424};
425
426IMP_PYCALLBACK_SIZET__const(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
427
428bool wxPyDataObjectSimple::GetDataHere(void *buf) const {
429 // We need to get the data for this object and write it to buf. I think
430 // the best way to do this for wxPython is to have the Python method
431 // return either a string or None and then act appropriately with the
432 // C++ version.
433
434 bool rval = false;
435 wxPyBlock_t blocked = wxPyBeginBlockThreads();
436 if (wxPyCBH_findCallback(m_myInst, "GetDataHere")) {
437 PyObject* ro;
438 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
439 if (ro) {
440 rval = (ro != Py_None && PyString_Check(ro));
441 if (rval)
442 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
443 Py_DECREF(ro);
444 }
445 }
446 wxPyEndBlockThreads(blocked);
447 return rval;
448}
449
450bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
451 // For this one we simply need to make a string from buf and len
452 // and send it to the Python method.
453 bool rval = false;
454 wxPyBlock_t blocked = wxPyBeginBlockThreads();
455 if (wxPyCBH_findCallback(m_myInst, "SetData")) {
456 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
457 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", data));
458 Py_DECREF(data);
459 }
460 wxPyEndBlockThreads(blocked);
461 return rval;
462}
463%}
464
465
466
467// Now define it for SWIG
468DocStr(wxPyDataObjectSimple,
469"wx.PyDataObjectSimple is a version of `wx.DataObjectSimple` that is
470Python-aware and knows how to reflect calls to its C++ virtual methods
471to methods in the Python derived class. You should derive from this
472class and overload `GetDataSize`, `GetDataHere` and `SetData` when you
473need to create your own simple single-format type of `wx.DataObject`.
474", "
475Here is a simple example::
476
477 class MyDataObject(wx.PyDataObjectSimple):
478 def __init__(self):
479 wx.PyDataObjectSimple.__init__(
480 self, wx.CustomDataFormat('MyDOFormat'))
481 self.data = ''
482
483 def GetDataSize(self):
484 return len(self.data)
485 def GetDataHere(self):
486 return self.data # returns a string
487 def SetData(self, data):
488 self.data = data
489 return True
490
491Note that there is already a `wx.CustomDataObject` class that behaves
492very similarly to this example. The value of creating your own
493derived class like this is to be able to do additional things when the
494data is requested or given via the clipboard or drag and drop
495operation, such as generate the data value or decode it into needed
496data structures.
497");
498class wxPyDataObjectSimple : public wxDataObjectSimple {
499public:
500 %pythonAppend wxPyDataObjectSimple "self._setCallbackInfo(self, PyDataObjectSimple)"
501
502 wxPyDataObjectSimple(const wxDataFormat& format = wxFormatInvalid);
503 void _setCallbackInfo(PyObject* self, PyObject* _class);
504};
505
506
507//---------------------------------------------------------------------------
508
509
510DocStr(wxDataObjectComposite,
511"wx.DataObjectComposite is the simplest `wx.DataObject` derivation
512which may be sued to support multiple formats. It contains several
513'wx.DataObjectSimple` objects and supports any format supported by at
514least one of them. Only one of these data objects is *preferred* (the
515first one if not explicitly changed by using the second parameter of
516`Add`) and its format determines the preferred format of the composite
517data object as well.
518
519See `wx.DataObject` documentation for the reasons why you might prefer
520to use wx.DataObject directly instead of wx.DataObjectComposite for
521efficiency reasons.
522", "");
523
524class wxDataObjectComposite : public wxDataObject {
525public:
526 wxDataObjectComposite();
527
528 %disownarg( wxDataObjectSimple *dataObject );
529
530 DocDeclStr(
531 void , Add(wxDataObjectSimple *dataObject, bool preferred = false),
532 "Adds the dataObject to the list of supported objects and it becomes
533the preferred object if preferred is True.", "");
534
535 %cleardisown( wxDataObjectSimple *dataObject );
536
537 DocDeclStr(
538 wxDataFormat , GetReceivedFormat() const,
539 "Report the format passed to the `SetData` method. This should be the
540format of the data object within the composite that recieved data from
541the clipboard or the DnD operation. You can use this method to find
542out what kind of data object was recieved.", "");
543
544 %property(ReceivedFormat, GetReceivedFormat, doc="See `GetReceivedFormat`");
545};
546
547//---------------------------------------------------------------------------
548
549DocStr(wxTextDataObject,
550"wx.TextDataObject is a specialization of `wx.DataObject` for text
551data. It can be used without change to paste data into the `wx.Clipboard`
552or a `wx.DropSource`.
553
554Alternativly, you may wish to derive a new class from the
555`wx.PyTextDataObject` class for providing text on-demand in order to
556minimize memory consumption when offering data in several formats,
557such as plain text and RTF, because by default the text is stored in a
558string in this class, but it might as well be generated on demand when
559requested. For this, `GetTextLength` and `GetText` will have to be
560overridden.", "");
561class wxTextDataObject : public wxDataObjectSimple {
562public:
563 DocCtorStr(
564 wxTextDataObject(const wxString& text = wxPyEmptyString),
565 "Constructor, may be used to initialise the text (otherwise `SetText`
566should be used later).", "");
567
568 DocDeclStr(
569 size_t , GetTextLength(),
570 "Returns the data size. By default, returns the size of the text data
571set in the constructor or using `SetText`. This can be overridden (via
572`wx.PyTextDataObject`) to provide text size data on-demand. It is
573recommended to return the text length plus 1 for a trailing zero, but
574this is not strictly required.", "");
575
576 DocDeclStr(
577 wxString , GetText(),
578 "Returns the text associated with the data object.", "");
579
580 DocDeclStr(
581 void , SetText(const wxString& text),
582 "Sets the text associated with the data object. This method is called
583when the data object receives the data and, by default, copies the
584text into the member variable. If you want to process the text on the
585fly you may wish to override this function (via
586`wx.PyTextDataObject`.)", "");
587
588};
589
590
591
592
593
594
595%{ // Create a new class for wxPython to use
596class wxPyTextDataObject : public wxTextDataObject {
597public:
598 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
599 : wxTextDataObject(text) {}
600
601 DEC_PYCALLBACK_SIZET__const(GetTextLength);
602 DEC_PYCALLBACK_STRING__const(GetText);
603 DEC_PYCALLBACK__STRING(SetText);
604 PYPRIVATE;
605};
606
607IMP_PYCALLBACK_SIZET__const(wxPyTextDataObject, wxTextDataObject, GetTextLength);
608IMP_PYCALLBACK_STRING__const(wxPyTextDataObject, wxTextDataObject, GetText);
609IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
610
611%}
612
613
614// Now define it for SWIG
615
616DocStr(wxPyTextDataObject,
617"wx.PyTextDataObject is a version of `wx.TextDataObject` that is
618Python-aware and knows how to reflect calls to its C++ virtual methods
619to methods in the Python derived class. You should derive from this
620class and overload `GetTextLength`, `GetText`, and `SetText` when you
621want to be able to provide text on demand instead of preloading it
622into the data object.", "");
623
624class wxPyTextDataObject : public wxTextDataObject {
625public:
626 %pythonAppend wxPyTextDataObject "self._setCallbackInfo(self, PyTextDataObject)"
627
628 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
629 void _setCallbackInfo(PyObject* self, PyObject* _class);
630};
631
632//---------------------------------------------------------------------------
633
634DocStr(wxBitmapDataObject,
635"wx.BitmapDataObject is a specialization of wxDataObject for bitmap
636data. It can be used without change to paste data into the `wx.Clipboard`
637or a `wx.DropSource`.
638", "
639:see: `wx.PyBitmapDataObject` if you wish to override `GetBitmap` to increase efficiency.");
640
641class wxBitmapDataObject : public wxDataObjectSimple {
642public:
643 DocCtorStr(
644 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap),
645 "Constructor, optionally passing a bitmap (otherwise use `SetBitmap`
646later).", "");
647
648 DocDeclStr(
649 wxBitmap , GetBitmap() const,
650 "Returns the bitmap associated with the data object. You may wish to
651override this method (by deriving from `wx.PyBitmapDataObject`) when
652offering data on-demand, but this is not required by wxWidgets'
653internals. Use this method to get data in bitmap form from the
654`wx.Clipboard`.", "");
655
656 DocDeclStr(
657 void , SetBitmap(const wxBitmap& bitmap),
658 "Sets the bitmap associated with the data object. This method is called
659when the data object receives data. Usually there will be no reason to
660override this function.", "");
661
662 %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
663};
664
665
666
667
668
669%{ // Create a new class for wxPython to use
670class wxPyBitmapDataObject : public wxBitmapDataObject {
671public:
672 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
673 : wxBitmapDataObject(bitmap) {}
674
675 wxBitmap GetBitmap() const;
676 void SetBitmap(const wxBitmap& bitmap);
677 PYPRIVATE;
678};
679
680wxBitmap wxPyBitmapDataObject::GetBitmap() const {
681 wxBitmap* rval = &wxNullBitmap;
682 wxPyBlock_t blocked = wxPyBeginBlockThreads();
683 if (wxPyCBH_findCallback(m_myInst, "GetBitmap")) {
684 PyObject* ro;
685 wxBitmap* ptr;
686 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
687 if (ro) {
688 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxBitmap")))
689 rval = ptr;
690 Py_DECREF(ro);
691 }
692 }
693 wxPyEndBlockThreads(blocked);
694 return *rval;
695}
696
697void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
698 wxPyBlock_t blocked = wxPyBeginBlockThreads();
699 if (wxPyCBH_findCallback(m_myInst, "SetBitmap")) {
700 PyObject* bo = wxPyConstructObject((void*)&bitmap, wxT("wxBitmap"), false);
701 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", bo));
702 Py_DECREF(bo);
703 }
704 wxPyEndBlockThreads(blocked);
705}
706%}
707
708
709
710
711DocStr(wxPyBitmapDataObject,
712"wx.PyBitmapDataObject is a version of `wx.BitmapDataObject` that is
713Python-aware and knows how to reflect calls to its C++ virtual methods
714to methods in the Python derived class. To be able to provide bitmap
715data on demand derive from this class and overload `GetBitmap`.", "");
716
717class wxPyBitmapDataObject : public wxBitmapDataObject {
718public:
719 %pythonAppend wxPyBitmapDataObject "self._setCallbackInfo(self, PyBitmapDataObject)"
720
721 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
722 void _setCallbackInfo(PyObject* self, PyObject* _class);
723};
724
725//---------------------------------------------------------------------------
726
727
728DocStr(wxFileDataObject,
729"wx.FileDataObject is a specialization of `wx.DataObjectSimple` for
730file names. The program works with it just as if it were a list of
731absolute file names, but internally it uses the same format as
732Explorer and other compatible programs under Windows or GNOME/KDE
733filemanager under Unix which makes it possible to receive files from
734them using this class.", "");
735
736class wxFileDataObject : public wxDataObjectSimple
737{
738public:
739 DocCtorStr(
740 wxFileDataObject(),
741 "", "");
742
743 DocDeclAStr(
744 const wxArrayString& , GetFilenames(),
745 "GetFilenames(self) -> [names]",
746 "Returns a list of file names.", "");
747
748 DocDeclStr(
749 void , AddFile(const wxString &filename),
750 "Adds a file to the list of files represented by this data object.", "");
751
752 %property(Filenames, GetFilenames, doc="See `GetFilenames`");
753};
754
755//---------------------------------------------------------------------------
756
757DocStr(wxCustomDataObject,
758"wx.CustomDataObject is a specialization of `wx.DataObjectSimple` for
759some application-specific data in arbitrary format. Python strings
760are used for getting and setting data, but any picklable object can
761easily be transfered via strings. A copy of the data is stored in the
762data object.", "");
763
764class wxCustomDataObject : public wxDataObjectSimple {
765public:
766 %nokwargs wxCustomDataObject;
767 wxCustomDataObject(const wxDataFormat& format);
768 %extend {
769 wxCustomDataObject(const wxString& formatName) {
770 return new wxCustomDataObject(wxDataFormat(formatName));
771 }
772 }
773 wxCustomDataObject();
774
775
776 %extend {
777 DocAStr(SetData,
778 "SetData(self, String data) -> bool",
779 "Copy the data value to the data object.", "");
780 bool SetData(PyObject* data) {
781 bool rval;
782 wxPyBlock_t blocked = wxPyBeginBlockThreads();
783 if (PyString_Check(data)) {
784 rval = self->SetData(PyString_Size(data), PyString_AsString(data));
785 }
786 else {
787 // raise a TypeError if not a string
788 PyErr_SetString(PyExc_TypeError, "String expected.");
789 rval = false;
790 }
791 wxPyEndBlockThreads(blocked);
792 return rval;
793 }
794 }
795 %pythoncode { TakeData = SetData }
796
797 DocDeclStr(
798 size_t , GetSize(),
799 "Get the size of the data.", "");
800
801
802 %extend {
803 DocAStr(GetData,
804 "GetData(self) -> String",
805 "Returns the data bytes from the data object as a string.", "");
806 PyObject* GetData() {
807 PyObject* obj;
808 wxPyBlock_t blocked = wxPyBeginBlockThreads();
809 obj = PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
810 wxPyEndBlockThreads(blocked);
811 return obj;
812 }
813 }
814
815 %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
816 %property(Size, GetSize, doc="See `GetSize`");
817
818};
819
820
821//---------------------------------------------------------------------------
822
823DocStr(wxURLDataObject,
824"This data object holds a URL in a format that is compatible with some
825browsers such that it is able to be dragged to or from them.", "");
826class wxURLDataObject : public wxDataObject/*Composite*/ {
827public:
828 wxURLDataObject(const wxString& url = wxPyEmptyString);
829
830 DocDeclStr(
831 wxString , GetURL(),
832 "Returns a string containing the current URL.", "");
833
834 DocDeclStr(
835 void , SetURL(const wxString& url),
836 "Set the URL.", "");
837
838};
839
840//---------------------------------------------------------------------------
841
842#if defined(__WXMSW__) || defined(__WXMAC__)
843
844%{
845#include <wx/metafile.h>
846%}
847
848class wxMetafileDataObject : public wxDataObjectSimple
849{
850public:
851 wxMetafileDataObject();
852
853 void SetMetafile(const wxMetafile& metafile);
854 wxMetafile GetMetafile() const;
855};
856
857
858#else
859%{
860class wxMetafileDataObject : public wxDataObjectSimple
861{
862public:
863 wxMetafileDataObject() { wxPyRaiseNotImplemented(); }
864};
865%}
866
867class wxMetafileDataObject : public wxDataObjectSimple
868{
869public:
870 wxMetafileDataObject();
871};
872
873#endif
874
875//---------------------------------------------------------------------------
876//---------------------------------------------------------------------------
877