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