]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_dataobj.i
Don't steal VK_RETURN for wxEVT_COMMAND_LIST_ITEM_ACTIVATED if any of
[wxWidgets.git] / wxPython / src / _dataobj.i
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
26 enum 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
51 DocStr(wxDataFormat,
52 "A wx.DataFormat is an encapsulation of a platform-specific format
53 handle which is used by the system for the clipboard and drag and drop
54 operations. The applications are usually only interested in, for
55 example, pasting data from the clipboard only if the data is in a
56 format the program understands. A data format is is used to uniquely
57 identify this format.",
58 "
59 On the system level, a data format is usually just a number, (which
60 may be the CLIPFORMAT under Windows or Atom under X11, for example.)
61
62 The 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
74 Besies the standard formats, the application may also use custom
75 formats which are identified by their names (strings) and not numeric
76 identifiers. Although internally custom format must be created (or
77 registered) first, you shouldn\'t care about it because it is done
78 automatically the first time the wxDataFormat object corresponding to
79 a given format name is created.
80
81 ");
82
83 class wxDataFormat {
84 public:
85 DocCtorStr(
86 wxDataFormat( wxDataFormatId type ),
87 "Constructs a data format object for one of the standard data formats
88 or 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
93 name.", "",
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
110 constants.", "");
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
120 standard 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;
132 const wxDataFormat wxFormatInvalid;
133 %mutable;
134
135 //---------------------------------------------------------------------------
136
137
138 DocStr(wxDataObject,
139 "A wx.DataObject represents data that can be copied to or from the
140 clipboard, or dragged and dropped. The important thing about
141 wx.DataObject is that this is a 'smart' piece of data unlike usual
142 'dumb' data containers such as memory buffers or files. Being 'smart'
143 here means that the data object itself should know what data formats
144 it 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
147 directly from Python. If you need a custom type of data object then
148 you should instead derive from `wx.PyDataObjectSimple` or use
149 `wx.CustomDataObject`.
150 ", "
151 Not surprisingly, being 'smart' comes at a price of added
152 complexity. This is reasonable for the situations when you really need
153 to support multiple formats, but may be annoying if you only want to
154 do something simple like cut and paste text.
155
156 To provide a solution for both cases, wxWidgets has two predefined
157 classes which derive from wx.DataObject: `wx.DataObjectSimple` and
158 `wx.DataObjectComposite`. `wx.DataObjectSimple` is the simplest
159 wx.DataObject possible and only holds data in a single format (such as
160 text or bitmap) and `wx.DataObjectComposite` is the simplest way to
161 implement a wx.DataObject which supports multiple simultaneous formats
162 because it achievs this by simply holding several
163 `wx.DataObjectSimple` objects.
164
165 Please note that the easiest way to use drag and drop and the
166 clipboard with multiple formats is by using `wx.DataObjectComposite`,
167 but it is not the most efficient one as each `wx.DataObjectSimple`
168 would contain the whole data in its respective formats. Now imagine
169 that you want to paste 200 pages of text in your proprietary format,
170 as well as Word, RTF, HTML, Unicode and plain text to the clipboard
171 and even today's computers are in trouble. For this case, you will
172 have to derive from wx.DataObject directly and make it enumerate its
173 formats and provide the data in the requested format on
174 demand. (**TODO**: This is currently not possible from Python. Make
175 it so.)
176
177 Note that the platform transfer mechanisms for the clipboard and drag
178 and drop, do not copy any data out of the source application until
179 another application actually requests the data. This is in contrast to
180 the 'feel' offered to the user of a program who would normally think
181 that the data resides in the clipboard after having pressed 'Copy' -
182 in 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
201 class wxDataObject {
202 public:
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
215 Get, its default value) or for setting it. Usually this will be the
216 native 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
222 data.", "");
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
240 in 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
328 DocStr(wxDataObjectSimple,
329 "wx.DataObjectSimple is a `wx.DataObject` which only supports one
330 format. This is the simplest possible `wx.DataObject` implementation.
331
332 This is still an \"abstract base class\" meaning that you can't use it
333 directly. You either need to use one of the predefined base classes,
334 or derive your own class from `wx.PyDataObjectSimple`.
335 ", "");
336
337 class wxDataObjectSimple : public wxDataObject {
338 public:
339 DocCtorStr(
340 wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid),
341 "Constructor accepts the supported format (none by default) which may
342 also 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
348 assumed 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
364 on failure. Must be implemented in the derived class if the object
365 supports 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
390 derived 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
415 class wxPyDataObjectSimple : public wxDataObjectSimple {
416 public:
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
426 IMP_PYCALLBACK_SIZET__const(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
427
428 bool 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
450 bool 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
468 DocStr(wxPyDataObjectSimple,
469 "wx.PyDataObjectSimple is a version of `wx.DataObjectSimple` that is
470 Python-aware and knows how to reflect calls to its C++ virtual methods
471 to methods in the Python derived class. You should derive from this
472 class and overload `GetDataSize`, `GetDataHere` and `SetData` when you
473 need to create your own simple single-format type of `wx.DataObject`.
474 ", "
475 Here 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
491 Note that there is already a `wx.CustomDataObject` class that behaves
492 very similarly to this example. The value of creating your own
493 derived class like this is to be able to do additional things when the
494 data is requested or given via the clipboard or drag and drop
495 operation, such as generate the data value or decode it into needed
496 data structures.
497 ");
498 class wxPyDataObjectSimple : public wxDataObjectSimple {
499 public:
500 %pythonAppend wxPyDataObjectSimple setCallbackInfo(PyDataObjectSimple)
501
502 wxPyDataObjectSimple(const wxDataFormat& format = wxFormatInvalid);
503 void _setCallbackInfo(PyObject* self, PyObject* _class);
504 };
505
506
507 //---------------------------------------------------------------------------
508
509
510 DocStr(wxDataObjectComposite,
511 "wx.DataObjectComposite is the simplest `wx.DataObject` derivation
512 which may be sued to support multiple formats. It contains several
513 'wx.DataObjectSimple` objects and supports any format supported by at
514 least one of them. Only one of these data objects is *preferred* (the
515 first one if not explicitly changed by using the second parameter of
516 `Add`) and its format determines the preferred format of the composite
517 data object as well.
518
519 See `wx.DataObject` documentation for the reasons why you might prefer
520 to use wx.DataObject directly instead of wx.DataObjectComposite for
521 efficiency reasons.
522 ", "");
523
524 class wxDataObjectComposite : public wxDataObject {
525 public:
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
533 the 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
540 format of the data object within the composite that recieved data from
541 the clipboard or the DnD operation. You can use this method to find
542 out what kind of data object was recieved.", "");
543
544 %property(ReceivedFormat, GetReceivedFormat, doc="See `GetReceivedFormat`");
545 };
546
547 //---------------------------------------------------------------------------
548
549 DocStr(wxTextDataObject,
550 "wx.TextDataObject is a specialization of `wx.DataObject` for text
551 data. It can be used without change to paste data into the `wx.Clipboard`
552 or a `wx.DropSource`.
553
554 Alternativly, you may wish to derive a new class from the
555 `wx.PyTextDataObject` class for providing text on-demand in order to
556 minimize memory consumption when offering data in several formats,
557 such as plain text and RTF, because by default the text is stored in a
558 string in this class, but it might as well be generated on demand when
559 requested. For this, `GetTextLength` and `GetText` will have to be
560 overridden.", "");
561 class wxTextDataObject : public wxDataObjectSimple {
562 public:
563 DocCtorStr(
564 wxTextDataObject(const wxString& text = wxPyEmptyString),
565 "Constructor, may be used to initialise the text (otherwise `SetText`
566 should be used later).", "");
567
568 DocDeclStr(
569 size_t , GetTextLength(),
570 "Returns the data size. By default, returns the size of the text data
571 set in the constructor or using `SetText`. This can be overridden (via
572 `wx.PyTextDataObject`) to provide text size data on-demand. It is
573 recommended to return the text length plus 1 for a trailing zero, but
574 this 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
583 when the data object receives the data and, by default, copies the
584 text into the member variable. If you want to process the text on the
585 fly you may wish to override this function (via
586 `wx.PyTextDataObject`.)", "");
587
588 %property(Text, GetText, SetText, doc="See `GetText` and `SetText`");
589 %property(TextLength, GetTextLength, doc="See `GetTextLength`");
590 };
591
592
593
594
595
596
597 %{ // Create a new class for wxPython to use
598 class wxPyTextDataObject : public wxTextDataObject {
599 public:
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
609 IMP_PYCALLBACK_SIZET__const(wxPyTextDataObject, wxTextDataObject, GetTextLength);
610 IMP_PYCALLBACK_STRING__const(wxPyTextDataObject, wxTextDataObject, GetText);
611 IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
612
613 %}
614
615
616 // Now define it for SWIG
617
618 DocStr(wxPyTextDataObject,
619 "wx.PyTextDataObject is a version of `wx.TextDataObject` that is
620 Python-aware and knows how to reflect calls to its C++ virtual methods
621 to methods in the Python derived class. You should derive from this
622 class and overload `GetTextLength`, `GetText`, and `SetText` when you
623 want to be able to provide text on demand instead of preloading it
624 into the data object.", "");
625
626 class wxPyTextDataObject : public wxTextDataObject {
627 public:
628 %pythonAppend wxPyTextDataObject setCallbackInfo(PyTextDataObject)
629
630 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
631 void _setCallbackInfo(PyObject* self, PyObject* _class);
632 };
633
634 //---------------------------------------------------------------------------
635
636 DocStr(wxBitmapDataObject,
637 "wx.BitmapDataObject is a specialization of wxDataObject for bitmap
638 data. It can be used without change to paste data into the `wx.Clipboard`
639 or a `wx.DropSource`.
640 ", "
641 :see: `wx.PyBitmapDataObject` if you wish to override `GetBitmap` to increase efficiency.");
642
643 class wxBitmapDataObject : public wxDataObjectSimple {
644 public:
645 DocCtorStr(
646 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap),
647 "Constructor, optionally passing a bitmap (otherwise use `SetBitmap`
648 later).", "");
649
650 DocDeclStr(
651 wxBitmap , GetBitmap() const,
652 "Returns the bitmap associated with the data object. You may wish to
653 override this method (by deriving from `wx.PyBitmapDataObject`) when
654 offering data on-demand, but this is not required by wxWidgets'
655 internals. 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
661 when the data object receives data. Usually there will be no reason to
662 override this function.", "");
663
664 %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
665 };
666
667
668
669
670
671 %{ // Create a new class for wxPython to use
672 class wxPyBitmapDataObject : public wxBitmapDataObject {
673 public:
674 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
675 : wxBitmapDataObject(bitmap) {}
676
677 wxBitmap GetBitmap() const;
678 void SetBitmap(const wxBitmap& bitmap);
679 PYPRIVATE;
680 };
681
682 wxBitmap wxPyBitmapDataObject::GetBitmap() const {
683 wxBitmap* rval = &wxNullBitmap;
684 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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 }
695 wxPyEndBlockThreads(blocked);
696 return *rval;
697 }
698
699 void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
700 wxPyBlock_t blocked = wxPyBeginBlockThreads();
701 if (wxPyCBH_findCallback(m_myInst, "SetBitmap")) {
702 PyObject* bo = wxPyConstructObject((void*)&bitmap, wxT("wxBitmap"), false);
703 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", bo));
704 Py_DECREF(bo);
705 }
706 wxPyEndBlockThreads(blocked);
707 }
708 %}
709
710
711
712
713 DocStr(wxPyBitmapDataObject,
714 "wx.PyBitmapDataObject is a version of `wx.BitmapDataObject` that is
715 Python-aware and knows how to reflect calls to its C++ virtual methods
716 to methods in the Python derived class. To be able to provide bitmap
717 data on demand derive from this class and overload `GetBitmap`.", "");
718
719 class wxPyBitmapDataObject : public wxBitmapDataObject {
720 public:
721 %pythonAppend wxPyBitmapDataObject setCallbackInfo(PyBitmapDataObject)
722
723 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
724 void _setCallbackInfo(PyObject* self, PyObject* _class);
725 };
726
727 //---------------------------------------------------------------------------
728
729
730 DocStr(wxFileDataObject,
731 "wx.FileDataObject is a specialization of `wx.DataObjectSimple` for
732 file names. The program works with it just as if it were a list of
733 absolute file names, but internally it uses the same format as
734 Explorer and other compatible programs under Windows or GNOME/KDE
735 filemanager under Unix which makes it possible to receive files from
736 them using this class.", "");
737
738 class wxFileDataObject : public wxDataObjectSimple
739 {
740 public:
741 DocCtorStr(
742 wxFileDataObject(),
743 "", "");
744
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
754 %property(Filenames, GetFilenames, doc="See `GetFilenames`");
755 };
756
757 //---------------------------------------------------------------------------
758
759 DocStr(wxCustomDataObject,
760 "wx.CustomDataObject is a specialization of `wx.DataObjectSimple` for
761 some application-specific data in arbitrary format. Python strings
762 are used for getting and setting data, but any picklable object can
763 easily be transfered via strings. A copy of the data is stored in the
764 data object.", "");
765
766 class wxCustomDataObject : public wxDataObjectSimple {
767 public:
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
777
778 %extend {
779 DocAStr(SetData,
780 "SetData(self, String data) -> bool",
781 "Copy the data value to the data object.", "");
782 bool SetData(PyObject* data) {
783 bool rval;
784 wxPyBlock_t blocked = wxPyBeginBlockThreads();
785 if (PyString_Check(data)) {
786 rval = self->SetData(PyString_Size(data), PyString_AsString(data));
787 }
788 else {
789 // raise a TypeError if not a string
790 PyErr_SetString(PyExc_TypeError, "String expected.");
791 rval = false;
792 }
793 wxPyEndBlockThreads(blocked);
794 return rval;
795 }
796 }
797 %pythoncode { TakeData = SetData }
798
799 DocDeclStr(
800 size_t , GetSize(),
801 "Get the size of the data.", "");
802
803
804 %extend {
805 DocAStr(GetData,
806 "GetData(self) -> String",
807 "Returns the data bytes from the data object as a string.", "");
808 PyObject* GetData() {
809 PyObject* obj;
810 wxPyBlock_t blocked = wxPyBeginBlockThreads();
811 obj = PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
812 wxPyEndBlockThreads(blocked);
813 return obj;
814 }
815 }
816
817 %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
818 %property(Size, GetSize, doc="See `GetSize`");
819
820 };
821
822
823 //---------------------------------------------------------------------------
824
825 DocStr(wxURLDataObject,
826 "This data object holds a URL in a format that is compatible with some
827 browsers such that it is able to be dragged to or from them.", "");
828 class wxURLDataObject : public wxDataObject/*Composite*/ {
829 public:
830 wxURLDataObject(const wxString& url = wxPyEmptyString);
831
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
840 %property(URL, GetURL, SetURL, doc="See `GetURL` and `SetURL`");
841 };
842
843 //---------------------------------------------------------------------------
844
845 #if defined(__WXMSW__) || defined(__WXMAC__)
846
847 %{
848 #include <wx/metafile.h>
849 %}
850
851 class wxMetafileDataObject : public wxDataObjectSimple
852 {
853 public:
854 wxMetafileDataObject();
855
856 void SetMetafile(const wxMetafile& metafile);
857 wxMetafile GetMetafile() const;
858 };
859
860
861 #else
862 %{
863 class wxMetafileDataObject : public wxDataObjectSimple
864 {
865 public:
866 wxMetafileDataObject() { wxPyRaiseNotImplemented(); }
867 };
868 %}
869
870 class wxMetafileDataObject : public wxDataObjectSimple
871 {
872 public:
873 wxMetafileDataObject();
874 };
875
876 #endif
877
878 //---------------------------------------------------------------------------
879 //---------------------------------------------------------------------------
880