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