]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_dataobj.i
return false from IsDoubleBuffered() if the first top level parent is not double...
[wxWidgets.git] / wxPython / src / _dataobj.i
CommitLineData
d14a1e28
RD
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
0facd0e5
RD
51DocStr(wxDataFormat,
52"A wx.DataFormat is an encapsulation of a platform-specific format
d07d2bc9
RD
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
23f8f985 74Besies the standard formats, the application may also use custom
d07d2bc9
RD
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");
0facd0e5 82
d14a1e28
RD
83class wxDataFormat {
84public:
0facd0e5
RD
85 DocCtorStr(
86 wxDataFormat( wxDataFormatId type ),
d07d2bc9
RD
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)", "");
0facd0e5
RD
89
90 DocCtorStrName(
91 wxDataFormat(const wxString& format),
d07d2bc9
RD
92 "Constructs a data format object for a custom format identified by its
93name.", "",
0facd0e5 94 CustomDataFormat);
d14a1e28
RD
95
96 ~wxDataFormat();
97
0facd0e5 98
d14a1e28
RD
99 %nokwargs operator==;
100 %nokwargs operator!=;
04e27155
RD
101 bool operator==(wxDataFormatId format) const;
102 bool operator!=(wxDataFormatId format) const;
d14a1e28
RD
103 bool operator==(const wxDataFormat& format) const;
104 bool operator!=(const wxDataFormat& format) const;
105
0facd0e5
RD
106
107 DocDeclStr(
108 void , SetType(wxDataFormatId format),
d07d2bc9
RD
109 "Sets the format to the given value, which should be one of wx.DF_XXX
110constants.", "");
0facd0e5
RD
111
112 DocDeclStr(
113 wxDataFormatId , GetType() const,
d07d2bc9 114 "Returns the platform-specific number identifying the format.", "");
0facd0e5 115
d14a1e28 116
0facd0e5
RD
117 DocDeclStr(
118 wxString , GetId() const,
d07d2bc9
RD
119 "Returns the name of a custom format (this function will fail for a
120standard format).", "");
0facd0e5
RD
121
122 DocDeclStr(
123 void , SetId(const wxString& format),
d07d2bc9 124 "Sets the format to be the custom format identified by the given name.", "");
0eae5d09
RD
125
126 %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
127 %property(Type, GetType, SetType, doc="See `GetType` and `SetType`");
d14a1e28
RD
128};
129
130
131%immutable;
132const wxDataFormat wxFormatInvalid;
133%mutable;
134
d14a1e28
RD
135//---------------------------------------------------------------------------
136
137
8e0ecdd9
RD
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
d14a1e28
RD
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
8e0ecdd9
RD
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
d14a1e28 218
8e0ecdd9
RD
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
d14a1e28 224
8e0ecdd9
RD
225 DocDeclStr(
226 bool , IsSupported(const wxDataFormat& format, Direction dir = Get) const,
227 "Returns True if this format is supported.", "");
228
d14a1e28 229
8e0ecdd9
RD
230 DocDeclStr(
231 virtual size_t , GetDataSize(const wxDataFormat& format) const,
232 "Get the (total) size of data for the given format", "");
233
d14a1e28 234
d14a1e28 235
8e0ecdd9 236 %extend {
214c4fbe
RD
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.", "");
8e0ecdd9
RD
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
6e6b3557 246 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
247 PyObject* list = PyList_New(count);
248 for (size_t i=0; i<count; i++) {
249 wxDataFormat* format = new wxDataFormat(formats[i]);
a72f4631 250 PyObject* obj = wxPyConstructObject((void*)format, wxT("wxDataFormat"), true);
02b800ce 251 PyList_SET_ITEM(list, i, obj); // PyList_SET_ITEM steals a reference
8e0ecdd9
RD
252 }
253 wxPyEndBlockThreads(blocked);
254 delete [] formats;
255 return list;
256 }
257 }
258
259
d14a1e28
RD
260
261 // copy raw data (in the specified format) to the provided buffer, return
dd9f7fea 262 // True if data copied successfully, False otherwise
8e0ecdd9
RD
263 // virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
264
8e0ecdd9 265 %extend {
214c4fbe
RD
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...");
8e0ecdd9
RD
270 PyObject* GetDataHere(const wxDataFormat& format) {
271 PyObject* rval = NULL;
272 size_t size = self->GetDataSize(format);
6e6b3557 273 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
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 }
d14a1e28 288
8e0ecdd9 289
d14a1e28 290 // get data from the buffer of specified length (in the given format),
dd9f7fea 291 // return True if the data was read successfully, False otherwise
8e0ecdd9
RD
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;
6e6b3557 302 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
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.");
a72f4631 309 rval = false;
8e0ecdd9
RD
310 }
311 wxPyEndBlockThreads(blocked);
312 return rval;
313 }
314 }
315
0eae5d09
RD
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`");
8e0ecdd9 321
d14a1e28
RD
322};
323
324
325//---------------------------------------------------------------------------
326
327
8e0ecdd9
RD
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", "");
d14a1e28 336
d14a1e28
RD
337class wxDataObjectSimple : public wxDataObject {
338public:
8e0ecdd9
RD
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
d14a1e28 344
8e0ecdd9
RD
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.", "");
d14a1e28 353
8e0ecdd9
RD
354 DocDeclStr(
355 virtual size_t , GetDataSize() const,
356 "Get the size of our data.", "");
357
358
359
214c4fbe
RD
360 %extend {
361 DocAStr(GetDataHere,
362 "GetDataHere(self) -> String",
363 "Returns the data bytes from the data object as a string, returns None
8e0ecdd9
RD
364on failure. Must be implemented in the derived class if the object
365supports rendering its data.", "");
8e0ecdd9
RD
366 PyObject* GetDataHere() {
367 PyObject* rval = NULL;
368 size_t size = self->GetDataSize();
6e6b3557 369 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
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
214c4fbe
RD
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
8e0ecdd9
RD
390derived class if the object supports setting its data.
391", "");
8e0ecdd9
RD
392 bool SetData(PyObject* data) {
393 bool rval;
6e6b3557 394 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
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.");
a72f4631 401 rval = false;
8e0ecdd9
RD
402 }
403 wxPyEndBlockThreads(blocked);
404 return rval;
405 }
406 }
407
0eae5d09 408 %property(Format, GetFormat, SetFormat, doc="See `GetFormat` and `SetFormat`");
d14a1e28
RD
409};
410
411
8e0ecdd9
RD
412
413
d14a1e28
RD
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;
75216307 422 bool SetData(size_t len, const void *buf);
d14a1e28
RD
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
a72f4631 434 bool rval = false;
6e6b3557 435 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
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 }
da32eb53 446 wxPyEndBlockThreads(blocked);
d14a1e28
RD
447 return rval;
448}
449
75216307 450bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
d14a1e28
RD
451 // For this one we simply need to make a string from buf and len
452 // and send it to the Python method.
a72f4631 453 bool rval = false;
6e6b3557 454 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
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 }
da32eb53 460 wxPyEndBlockThreads(blocked);
d14a1e28
RD
461 return rval;
462}
463%}
464
465
466
467// Now define it for SWIG
8e0ecdd9
RD
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");
d14a1e28
RD
498class wxPyDataObjectSimple : public wxDataObjectSimple {
499public:
2b9048c5 500 %pythonAppend wxPyDataObjectSimple "self._setCallbackInfo(self, PyDataObjectSimple)"
d14a1e28
RD
501
502 wxPyDataObjectSimple(const wxDataFormat& format = wxFormatInvalid);
503 void _setCallbackInfo(PyObject* self, PyObject* _class);
504};
505
506
507//---------------------------------------------------------------------------
508
509
8e0ecdd9
RD
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
d14a1e28
RD
524class wxDataObjectComposite : public wxDataObject {
525public:
526 wxDataObjectComposite();
527
214c4fbe 528 %disownarg( wxDataObjectSimple *dataObject );
8e0ecdd9
RD
529
530 DocDeclStr(
a72f4631 531 void , Add(wxDataObjectSimple *dataObject, bool preferred = false),
8e0ecdd9
RD
532 "Adds the dataObject to the list of supported objects and it becomes
533the preferred object if preferred is True.", "");
534
214c4fbe 535 %cleardisown( wxDataObjectSimple *dataObject );
c072c757
RD
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
0eae5d09 544 %property(ReceivedFormat, GetReceivedFormat, doc="See `GetReceivedFormat`");
d14a1e28
RD
545};
546
547//---------------------------------------------------------------------------
548
8e0ecdd9
RD
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.", "");
d14a1e28
RD
561class wxTextDataObject : public wxDataObjectSimple {
562public:
8e0ecdd9
RD
563 DocCtorStr(
564 wxTextDataObject(const wxString& text = wxPyEmptyString),
565 "Constructor, may be used to initialise the text (otherwise `SetText`
566should be used later).", "");
d14a1e28 567
8e0ecdd9
RD
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
994453b8
RD
588 %property(Text, GetText, SetText, doc="See `GetText` and `SetText`");
589 %property(TextLength, GetTextLength, doc="See `GetTextLength`");
d14a1e28
RD
590};
591
592
593
8e0ecdd9
RD
594
595
596
d14a1e28
RD
597%{ // Create a new class for wxPython to use
598class wxPyTextDataObject : public wxTextDataObject {
599public:
600 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
601 : wxTextDataObject(text) {}
602
603 DEC_PYCALLBACK_SIZET__const(GetTextLength);
604 DEC_PYCALLBACK_STRING__const(GetText);
605 DEC_PYCALLBACK__STRING(SetText);
606 PYPRIVATE;
607};
608
609IMP_PYCALLBACK_SIZET__const(wxPyTextDataObject, wxTextDataObject, GetTextLength);
610IMP_PYCALLBACK_STRING__const(wxPyTextDataObject, wxTextDataObject, GetText);
611IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
612
613%}
614
615
616// Now define it for SWIG
8e0ecdd9
RD
617
618DocStr(wxPyTextDataObject,
619"wx.PyTextDataObject is a version of `wx.TextDataObject` that is
620Python-aware and knows how to reflect calls to its C++ virtual methods
621to methods in the Python derived class. You should derive from this
622class and overload `GetTextLength`, `GetText`, and `SetText` when you
623want to be able to provide text on demand instead of preloading it
624into the data object.", "");
625
d14a1e28
RD
626class wxPyTextDataObject : public wxTextDataObject {
627public:
2b9048c5 628 %pythonAppend wxPyTextDataObject "self._setCallbackInfo(self, PyTextDataObject)"
d14a1e28
RD
629
630 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
631 void _setCallbackInfo(PyObject* self, PyObject* _class);
632};
633
634//---------------------------------------------------------------------------
635
8e0ecdd9
RD
636DocStr(wxBitmapDataObject,
637"wx.BitmapDataObject is a specialization of wxDataObject for bitmap
638data. It can be used without change to paste data into the `wx.Clipboard`
639or a `wx.DropSource`.
640", "
641:see: `wx.PyBitmapDataObject` if you wish to override `GetBitmap` to increase efficiency.");
642
d14a1e28
RD
643class wxBitmapDataObject : public wxDataObjectSimple {
644public:
8e0ecdd9
RD
645 DocCtorStr(
646 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap),
647 "Constructor, optionally passing a bitmap (otherwise use `SetBitmap`
648later).", "");
d14a1e28 649
8e0ecdd9
RD
650 DocDeclStr(
651 wxBitmap , GetBitmap() const,
652 "Returns the bitmap associated with the data object. You may wish to
653override this method (by deriving from `wx.PyBitmapDataObject`) when
654offering data on-demand, but this is not required by wxWidgets'
655internals. Use this method to get data in bitmap form from the
656`wx.Clipboard`.", "");
657
658 DocDeclStr(
659 void , SetBitmap(const wxBitmap& bitmap),
660 "Sets the bitmap associated with the data object. This method is called
661when the data object receives data. Usually there will be no reason to
662override this function.", "");
663
0eae5d09 664 %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
d14a1e28
RD
665};
666
667
668
8e0ecdd9
RD
669
670
d14a1e28
RD
671%{ // Create a new class for wxPython to use
672class wxPyBitmapDataObject : public wxBitmapDataObject {
673public:
674 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
675 : wxBitmapDataObject(bitmap) {}
676
677 wxBitmap GetBitmap() const;
678 void SetBitmap(const wxBitmap& bitmap);
679 PYPRIVATE;
680};
681
682wxBitmap wxPyBitmapDataObject::GetBitmap() const {
683 wxBitmap* rval = &wxNullBitmap;
6e6b3557 684 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
685 if (wxPyCBH_findCallback(m_myInst, "GetBitmap")) {
686 PyObject* ro;
687 wxBitmap* ptr;
688 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
689 if (ro) {
690 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxBitmap")))
691 rval = ptr;
692 Py_DECREF(ro);
693 }
694 }
da32eb53 695 wxPyEndBlockThreads(blocked);
d14a1e28
RD
696 return *rval;
697}
8e0ecdd9 698
d14a1e28 699void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
6e6b3557 700 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 701 if (wxPyCBH_findCallback(m_myInst, "SetBitmap")) {
a72f4631 702 PyObject* bo = wxPyConstructObject((void*)&bitmap, wxT("wxBitmap"), false);
d14a1e28
RD
703 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", bo));
704 Py_DECREF(bo);
705 }
da32eb53 706 wxPyEndBlockThreads(blocked);
d14a1e28
RD
707}
708%}
709
710
711
8e0ecdd9
RD
712
713DocStr(wxPyBitmapDataObject,
714"wx.PyBitmapDataObject is a version of `wx.BitmapDataObject` that is
715Python-aware and knows how to reflect calls to its C++ virtual methods
716to methods in the Python derived class. To be able to provide bitmap
717data on demand derive from this class and overload `GetBitmap`.", "");
718
d14a1e28
RD
719class wxPyBitmapDataObject : public wxBitmapDataObject {
720public:
2b9048c5 721 %pythonAppend wxPyBitmapDataObject "self._setCallbackInfo(self, PyBitmapDataObject)"
d14a1e28
RD
722
723 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
724 void _setCallbackInfo(PyObject* self, PyObject* _class);
725};
726
727//---------------------------------------------------------------------------
728
729
8e0ecdd9
RD
730DocStr(wxFileDataObject,
731"wx.FileDataObject is a specialization of `wx.DataObjectSimple` for
732file names. The program works with it just as if it were a list of
733absolute file names, but internally it uses the same format as
734Explorer and other compatible programs under Windows or GNOME/KDE
735filemanager under Unix which makes it possible to receive files from
23f8f985 736them using this class.", "");
8e0ecdd9 737
d14a1e28
RD
738class wxFileDataObject : public wxDataObjectSimple
739{
740public:
8e0ecdd9
RD
741 DocCtorStr(
742 wxFileDataObject(),
743 "", "");
d14a1e28 744
8e0ecdd9
RD
745 DocDeclAStr(
746 const wxArrayString& , GetFilenames(),
747 "GetFilenames(self) -> [names]",
748 "Returns a list of file names.", "");
749
750 DocDeclStr(
751 void , AddFile(const wxString &filename),
752 "Adds a file to the list of files represented by this data object.", "");
753
42e2bbb9 754 %property(Filenames, GetFilenames, doc="See `GetFilenames`");
d14a1e28
RD
755};
756
d14a1e28
RD
757//---------------------------------------------------------------------------
758
8e0ecdd9
RD
759DocStr(wxCustomDataObject,
760"wx.CustomDataObject is a specialization of `wx.DataObjectSimple` for
761some application-specific data in arbitrary format. Python strings
762are used for getting and setting data, but any picklable object can
763easily be transfered via strings. A copy of the data is stored in the
764data object.", "");
765
d14a1e28
RD
766class wxCustomDataObject : public wxDataObjectSimple {
767public:
23f8f985
RD
768 %nokwargs wxCustomDataObject;
769 wxCustomDataObject(const wxDataFormat& format);
770 %extend {
771 wxCustomDataObject(const wxString& formatName) {
772 return new wxCustomDataObject(wxDataFormat(formatName));
773 }
774 }
775 wxCustomDataObject();
776
8e0ecdd9 777
d14a1e28 778 %extend {
214c4fbe
RD
779 DocAStr(SetData,
780 "SetData(self, String data) -> bool",
781 "Copy the data value to the data object.", "");
d14a1e28 782 bool SetData(PyObject* data) {
8e0ecdd9 783 bool rval;
6e6b3557 784 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 785 if (PyString_Check(data)) {
8e0ecdd9 786 rval = self->SetData(PyString_Size(data), PyString_AsString(data));
d14a1e28
RD
787 }
788 else {
789 // raise a TypeError if not a string
790 PyErr_SetString(PyExc_TypeError, "String expected.");
a72f4631 791 rval = false;
d14a1e28 792 }
8e0ecdd9
RD
793 wxPyEndBlockThreads(blocked);
794 return rval;
d14a1e28
RD
795 }
796 }
8e0ecdd9
RD
797 %pythoncode { TakeData = SetData }
798
799 DocDeclStr(
800 size_t , GetSize(),
801 "Get the size of the data.", "");
802
d14a1e28 803
d14a1e28 804 %extend {
214c4fbe
RD
805 DocAStr(GetData,
806 "GetData(self) -> String",
807 "Returns the data bytes from the data object as a string.", "");
d14a1e28 808 PyObject* GetData() {
8e0ecdd9 809 PyObject* obj;
6e6b3557 810 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9 811 obj = PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
c61fb035
RD
812 wxPyEndBlockThreads(blocked);
813 return obj;
d14a1e28
RD
814 }
815 }
0eae5d09
RD
816
817 %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
818 %property(Size, GetSize, doc="See `GetSize`");
819
d14a1e28
RD
820};
821
822
d14a1e28
RD
823//---------------------------------------------------------------------------
824
8e0ecdd9
RD
825DocStr(wxURLDataObject,
826"This data object holds a URL in a format that is compatible with some
827browsers such that it is able to be dragged to or from them.", "");
095315e2 828class wxURLDataObject : public wxDataObject/*Composite*/ {
d14a1e28 829public:
d4645514 830 wxURLDataObject(const wxString& url = wxPyEmptyString);
d14a1e28 831
8e0ecdd9
RD
832 DocDeclStr(
833 wxString , GetURL(),
834 "Returns a string containing the current URL.", "");
835
836 DocDeclStr(
837 void , SetURL(const wxString& url),
838 "Set the URL.", "");
839
dba7934c 840 %property(URL, GetURL, SetURL, doc="See `GetURL` and `SetURL`");
d14a1e28
RD
841};
842
843//---------------------------------------------------------------------------
844
c1201401 845#if defined(__WXMSW__) || defined(__WXMAC__)
d14a1e28
RD
846
847%{
848#include <wx/metafile.h>
849%}
850
851class wxMetafileDataObject : public wxDataObjectSimple
852{
853public:
854 wxMetafileDataObject();
855
856 void SetMetafile(const wxMetafile& metafile);
857 wxMetafile GetMetafile() const;
858};
859
860
861#else
862%{
863class wxMetafileDataObject : public wxDataObjectSimple
864{
865public:
81cfe5e1 866 wxMetafileDataObject() { wxPyRaiseNotImplemented(); }
d14a1e28
RD
867};
868%}
869
870class wxMetafileDataObject : public wxDataObjectSimple
871{
872public:
873 wxMetafileDataObject();
874};
875
876#endif
877
878//---------------------------------------------------------------------------
879//---------------------------------------------------------------------------
880