]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_dataobj.i
Add wx.menuBar.UpdateMenus
[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 232
8e0ecdd9 233 %extend {
214c4fbe
RD
234 DocAStr(GetAllFormats,
235 "GetAllFormats(self, int dir=Get) -> [formats]",
236 "Returns a list of all the wx.DataFormats that this dataobject supports
237in the given direction.", "");
8e0ecdd9
RD
238 PyObject* GetAllFormats(Direction dir = Get) {
239 size_t count = self->GetFormatCount(dir);
240 wxDataFormat* formats = new wxDataFormat[count];
241 self->GetAllFormats(formats, dir);
242
6e6b3557 243 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
244 PyObject* list = PyList_New(count);
245 for (size_t i=0; i<count; i++) {
246 wxDataFormat* format = new wxDataFormat(formats[i]);
a72f4631 247 PyObject* obj = wxPyConstructObject((void*)format, wxT("wxDataFormat"), true);
02b800ce 248 PyList_SET_ITEM(list, i, obj); // PyList_SET_ITEM steals a reference
8e0ecdd9
RD
249 }
250 wxPyEndBlockThreads(blocked);
251 delete [] formats;
252 return list;
253 }
254 }
255
256
d14a1e28
RD
257
258 // copy raw data (in the specified format) to the provided buffer, return
dd9f7fea 259 // True if data copied successfully, False otherwise
8e0ecdd9
RD
260 // virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
261
8e0ecdd9 262 %extend {
214c4fbe
RD
263 DocAStr(GetDataHere,
264 "GetDataHere(self, DataFormat format) -> String",
265 "Get the data bytes in the specified format, returns None on failure.", "
266:todo: This should use the python buffer interface isntead...");
8e0ecdd9
RD
267 PyObject* GetDataHere(const wxDataFormat& format) {
268 PyObject* rval = NULL;
269 size_t size = self->GetDataSize(format);
6e6b3557 270 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
271 if (size) {
272 char* buf = new char[size];
273 if (self->GetDataHere(format, buf))
274 rval = PyString_FromStringAndSize(buf, size);
275 delete [] buf;
276 }
277 if (! rval) {
278 rval = Py_None;
279 Py_INCREF(rval);
280 }
281 wxPyEndBlockThreads(blocked);
282 return rval;
283 }
284 }
d14a1e28 285
8e0ecdd9 286
d14a1e28 287 // get data from the buffer of specified length (in the given format),
dd9f7fea 288 // return True if the data was read successfully, False otherwise
8e0ecdd9
RD
289 //virtual bool SetData(const wxDataFormat& format,
290 // size_t len, const void * buf);
291 DocAStr(SetData,
292 "SetData(self, DataFormat format, String data) -> bool",
293 "Set the data in the specified format from the bytes in the the data string.
294", "
295:todo: This should use the python buffer interface isntead...");
296 %extend {
297 bool SetData(const wxDataFormat& format, PyObject* data) {
298 bool rval;
6e6b3557 299 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
300 if (PyString_Check(data)) {
301 rval = self->SetData(format, PyString_Size(data), PyString_AsString(data));
302 }
303 else {
304 // raise a TypeError if not a string
305 PyErr_SetString(PyExc_TypeError, "String expected.");
a72f4631 306 rval = false;
8e0ecdd9
RD
307 }
308 wxPyEndBlockThreads(blocked);
309 return rval;
310 }
311 }
312
313
d14a1e28
RD
314};
315
316
317//---------------------------------------------------------------------------
318
319
8e0ecdd9
RD
320DocStr(wxDataObjectSimple,
321"wx.DataObjectSimple is a `wx.DataObject` which only supports one
322format. This is the simplest possible `wx.DataObject` implementation.
323
324This is still an \"abstract base class\" meaning that you can't use it
325directly. You either need to use one of the predefined base classes,
326or derive your own class from `wx.PyDataObjectSimple`.
327", "");
d14a1e28 328
d14a1e28
RD
329class wxDataObjectSimple : public wxDataObject {
330public:
8e0ecdd9
RD
331 DocCtorStr(
332 wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid),
333 "Constructor accepts the supported format (none by default) which may
334also be set later with `SetFormat`.","");
335
d14a1e28 336
8e0ecdd9
RD
337 DocDeclStr(
338 const wxDataFormat& , GetFormat(),
339 "Returns the (one and only one) format supported by this object. It is
340assumed that the format is supported in both directions.", "");
341
342 DocDeclStr(
343 void , SetFormat(const wxDataFormat& format),
344 "Sets the supported format.", "");
d14a1e28 345
8e0ecdd9
RD
346 DocDeclStr(
347 virtual size_t , GetDataSize() const,
348 "Get the size of our data.", "");
349
350
351
214c4fbe
RD
352 %extend {
353 DocAStr(GetDataHere,
354 "GetDataHere(self) -> String",
355 "Returns the data bytes from the data object as a string, returns None
8e0ecdd9
RD
356on failure. Must be implemented in the derived class if the object
357supports rendering its data.", "");
8e0ecdd9
RD
358 PyObject* GetDataHere() {
359 PyObject* rval = NULL;
360 size_t size = self->GetDataSize();
6e6b3557 361 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
362 if (size) {
363 char* buf = new char[size];
364 if (self->GetDataHere(buf))
365 rval = PyString_FromStringAndSize(buf, size);
366 delete [] buf;
367 }
368 if (! rval) {
369 rval = Py_None;
370 Py_INCREF(rval);
371 }
372 wxPyEndBlockThreads(blocked);
373 return rval;
374 }
375 }
376
377
214c4fbe
RD
378 %extend {
379 DocAStr(SetData,
380 "SetData(self, String data) -> bool",
381 "Copy the data value to the data object. Must be implemented in the
8e0ecdd9
RD
382derived class if the object supports setting its data.
383", "");
8e0ecdd9
RD
384 bool SetData(PyObject* data) {
385 bool rval;
6e6b3557 386 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9
RD
387 if (PyString_Check(data)) {
388 rval = self->SetData(PyString_Size(data), PyString_AsString(data));
389 }
390 else {
391 // raise a TypeError if not a string
392 PyErr_SetString(PyExc_TypeError, "String expected.");
a72f4631 393 rval = false;
8e0ecdd9
RD
394 }
395 wxPyEndBlockThreads(blocked);
396 return rval;
397 }
398 }
399
d14a1e28
RD
400};
401
402
8e0ecdd9
RD
403
404
d14a1e28
RD
405%{ // Create a new class for wxPython to use
406class wxPyDataObjectSimple : public wxDataObjectSimple {
407public:
408 wxPyDataObjectSimple(const wxDataFormat& format = wxFormatInvalid)
409 : wxDataObjectSimple(format) {}
410
411 DEC_PYCALLBACK_SIZET__const(GetDataSize);
412 bool GetDataHere(void *buf) const;
75216307 413 bool SetData(size_t len, const void *buf);
d14a1e28
RD
414 PYPRIVATE;
415};
416
417IMP_PYCALLBACK_SIZET__const(wxPyDataObjectSimple, wxDataObjectSimple, GetDataSize);
418
419bool wxPyDataObjectSimple::GetDataHere(void *buf) const {
420 // We need to get the data for this object and write it to buf. I think
421 // the best way to do this for wxPython is to have the Python method
422 // return either a string or None and then act appropriately with the
423 // C++ version.
424
a72f4631 425 bool rval = false;
6e6b3557 426 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
427 if (wxPyCBH_findCallback(m_myInst, "GetDataHere")) {
428 PyObject* ro;
429 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
430 if (ro) {
431 rval = (ro != Py_None && PyString_Check(ro));
432 if (rval)
433 memcpy(buf, PyString_AsString(ro), PyString_Size(ro));
434 Py_DECREF(ro);
435 }
436 }
da32eb53 437 wxPyEndBlockThreads(blocked);
d14a1e28
RD
438 return rval;
439}
440
75216307 441bool wxPyDataObjectSimple::SetData(size_t len, const void *buf) {
d14a1e28
RD
442 // For this one we simply need to make a string from buf and len
443 // and send it to the Python method.
a72f4631 444 bool rval = false;
6e6b3557 445 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
446 if (wxPyCBH_findCallback(m_myInst, "SetData")) {
447 PyObject* data = PyString_FromStringAndSize((char*)buf, len);
448 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", data));
449 Py_DECREF(data);
450 }
da32eb53 451 wxPyEndBlockThreads(blocked);
d14a1e28
RD
452 return rval;
453}
454%}
455
456
457
458// Now define it for SWIG
8e0ecdd9
RD
459DocStr(wxPyDataObjectSimple,
460"wx.PyDataObjectSimple is a version of `wx.DataObjectSimple` that is
461Python-aware and knows how to reflect calls to its C++ virtual methods
462to methods in the Python derived class. You should derive from this
463class and overload `GetDataSize`, `GetDataHere` and `SetData` when you
464need to create your own simple single-format type of `wx.DataObject`.
465", "
466Here is a simple example::
467
468 class MyDataObject(wx.PyDataObjectSimple):
469 def __init__(self):
470 wx.PyDataObjectSimple.__init__(
471 self, wx.CustomDataFormat('MyDOFormat'))
472 self.data = ''
473
474 def GetDataSize(self):
475 return len(self.data)
476 def GetDataHere(self):
477 return self.data # returns a string
478 def SetData(self, data):
479 self.data = data
480 return True
481
482Note that there is already a `wx.CustomDataObject` class that behaves
483very similarly to this example. The value of creating your own
484derived class like this is to be able to do additional things when the
485data is requested or given via the clipboard or drag and drop
486operation, such as generate the data value or decode it into needed
487data structures.
488");
d14a1e28
RD
489class wxPyDataObjectSimple : public wxDataObjectSimple {
490public:
2b9048c5 491 %pythonAppend wxPyDataObjectSimple "self._setCallbackInfo(self, PyDataObjectSimple)"
d14a1e28
RD
492
493 wxPyDataObjectSimple(const wxDataFormat& format = wxFormatInvalid);
494 void _setCallbackInfo(PyObject* self, PyObject* _class);
495};
496
497
498//---------------------------------------------------------------------------
499
500
8e0ecdd9
RD
501DocStr(wxDataObjectComposite,
502"wx.DataObjectComposite is the simplest `wx.DataObject` derivation
503which may be sued to support multiple formats. It contains several
504'wx.DataObjectSimple` objects and supports any format supported by at
505least one of them. Only one of these data objects is *preferred* (the
506first one if not explicitly changed by using the second parameter of
507`Add`) and its format determines the preferred format of the composite
508data object as well.
509
510See `wx.DataObject` documentation for the reasons why you might prefer
511to use wx.DataObject directly instead of wx.DataObjectComposite for
512efficiency reasons.
513", "");
514
d14a1e28
RD
515class wxDataObjectComposite : public wxDataObject {
516public:
517 wxDataObjectComposite();
518
214c4fbe 519 %disownarg( wxDataObjectSimple *dataObject );
8e0ecdd9
RD
520
521 DocDeclStr(
a72f4631 522 void , Add(wxDataObjectSimple *dataObject, bool preferred = false),
8e0ecdd9
RD
523 "Adds the dataObject to the list of supported objects and it becomes
524the preferred object if preferred is True.", "");
525
214c4fbe 526 %cleardisown( wxDataObjectSimple *dataObject );
c072c757
RD
527
528 DocDeclStr(
529 wxDataFormat , GetReceivedFormat() const,
530 "Report the format passed to the `SetData` method. This should be the
531format of the data object within the composite that recieved data from
532the clipboard or the DnD operation. You can use this method to find
533out what kind of data object was recieved.", "");
534
d14a1e28
RD
535};
536
537//---------------------------------------------------------------------------
538
8e0ecdd9
RD
539DocStr(wxTextDataObject,
540"wx.TextDataObject is a specialization of `wx.DataObject` for text
541data. It can be used without change to paste data into the `wx.Clipboard`
542or a `wx.DropSource`.
543
544Alternativly, you may wish to derive a new class from the
545`wx.PyTextDataObject` class for providing text on-demand in order to
546minimize memory consumption when offering data in several formats,
547such as plain text and RTF, because by default the text is stored in a
548string in this class, but it might as well be generated on demand when
549requested. For this, `GetTextLength` and `GetText` will have to be
550overridden.", "");
d14a1e28
RD
551class wxTextDataObject : public wxDataObjectSimple {
552public:
8e0ecdd9
RD
553 DocCtorStr(
554 wxTextDataObject(const wxString& text = wxPyEmptyString),
555 "Constructor, may be used to initialise the text (otherwise `SetText`
556should be used later).", "");
d14a1e28 557
8e0ecdd9
RD
558 DocDeclStr(
559 size_t , GetTextLength(),
560 "Returns the data size. By default, returns the size of the text data
561set in the constructor or using `SetText`. This can be overridden (via
562`wx.PyTextDataObject`) to provide text size data on-demand. It is
563recommended to return the text length plus 1 for a trailing zero, but
564this is not strictly required.", "");
565
566 DocDeclStr(
567 wxString , GetText(),
568 "Returns the text associated with the data object.", "");
569
570 DocDeclStr(
571 void , SetText(const wxString& text),
572 "Sets the text associated with the data object. This method is called
573when the data object receives the data and, by default, copies the
574text into the member variable. If you want to process the text on the
575fly you may wish to override this function (via
576`wx.PyTextDataObject`.)", "");
577
d14a1e28
RD
578};
579
580
581
8e0ecdd9
RD
582
583
584
d14a1e28
RD
585%{ // Create a new class for wxPython to use
586class wxPyTextDataObject : public wxTextDataObject {
587public:
588 wxPyTextDataObject(const wxString& text = wxPyEmptyString)
589 : wxTextDataObject(text) {}
590
591 DEC_PYCALLBACK_SIZET__const(GetTextLength);
592 DEC_PYCALLBACK_STRING__const(GetText);
593 DEC_PYCALLBACK__STRING(SetText);
594 PYPRIVATE;
595};
596
597IMP_PYCALLBACK_SIZET__const(wxPyTextDataObject, wxTextDataObject, GetTextLength);
598IMP_PYCALLBACK_STRING__const(wxPyTextDataObject, wxTextDataObject, GetText);
599IMP_PYCALLBACK__STRING(wxPyTextDataObject, wxTextDataObject, SetText);
600
601%}
602
603
604// Now define it for SWIG
8e0ecdd9
RD
605
606DocStr(wxPyTextDataObject,
607"wx.PyTextDataObject is a version of `wx.TextDataObject` that is
608Python-aware and knows how to reflect calls to its C++ virtual methods
609to methods in the Python derived class. You should derive from this
610class and overload `GetTextLength`, `GetText`, and `SetText` when you
611want to be able to provide text on demand instead of preloading it
612into the data object.", "");
613
d14a1e28
RD
614class wxPyTextDataObject : public wxTextDataObject {
615public:
2b9048c5 616 %pythonAppend wxPyTextDataObject "self._setCallbackInfo(self, PyTextDataObject)"
d14a1e28
RD
617
618 wxPyTextDataObject(const wxString& text = wxPyEmptyString);
619 void _setCallbackInfo(PyObject* self, PyObject* _class);
620};
621
622//---------------------------------------------------------------------------
623
8e0ecdd9
RD
624DocStr(wxBitmapDataObject,
625"wx.BitmapDataObject is a specialization of wxDataObject for bitmap
626data. It can be used without change to paste data into the `wx.Clipboard`
627or a `wx.DropSource`.
628", "
629:see: `wx.PyBitmapDataObject` if you wish to override `GetBitmap` to increase efficiency.");
630
d14a1e28
RD
631class wxBitmapDataObject : public wxDataObjectSimple {
632public:
8e0ecdd9
RD
633 DocCtorStr(
634 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap),
635 "Constructor, optionally passing a bitmap (otherwise use `SetBitmap`
636later).", "");
d14a1e28 637
8e0ecdd9
RD
638 DocDeclStr(
639 wxBitmap , GetBitmap() const,
640 "Returns the bitmap associated with the data object. You may wish to
641override this method (by deriving from `wx.PyBitmapDataObject`) when
642offering data on-demand, but this is not required by wxWidgets'
643internals. Use this method to get data in bitmap form from the
644`wx.Clipboard`.", "");
645
646 DocDeclStr(
647 void , SetBitmap(const wxBitmap& bitmap),
648 "Sets the bitmap associated with the data object. This method is called
649when the data object receives data. Usually there will be no reason to
650override this function.", "");
651
d14a1e28
RD
652};
653
654
655
8e0ecdd9
RD
656
657
d14a1e28
RD
658%{ // Create a new class for wxPython to use
659class wxPyBitmapDataObject : public wxBitmapDataObject {
660public:
661 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
662 : wxBitmapDataObject(bitmap) {}
663
664 wxBitmap GetBitmap() const;
665 void SetBitmap(const wxBitmap& bitmap);
666 PYPRIVATE;
667};
668
669wxBitmap wxPyBitmapDataObject::GetBitmap() const {
670 wxBitmap* rval = &wxNullBitmap;
6e6b3557 671 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
672 if (wxPyCBH_findCallback(m_myInst, "GetBitmap")) {
673 PyObject* ro;
674 wxBitmap* ptr;
675 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
676 if (ro) {
677 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxBitmap")))
678 rval = ptr;
679 Py_DECREF(ro);
680 }
681 }
da32eb53 682 wxPyEndBlockThreads(blocked);
d14a1e28
RD
683 return *rval;
684}
8e0ecdd9 685
d14a1e28 686void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) {
6e6b3557 687 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 688 if (wxPyCBH_findCallback(m_myInst, "SetBitmap")) {
a72f4631 689 PyObject* bo = wxPyConstructObject((void*)&bitmap, wxT("wxBitmap"), false);
d14a1e28
RD
690 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", bo));
691 Py_DECREF(bo);
692 }
da32eb53 693 wxPyEndBlockThreads(blocked);
d14a1e28
RD
694}
695%}
696
697
698
8e0ecdd9
RD
699
700DocStr(wxPyBitmapDataObject,
701"wx.PyBitmapDataObject is a version of `wx.BitmapDataObject` that is
702Python-aware and knows how to reflect calls to its C++ virtual methods
703to methods in the Python derived class. To be able to provide bitmap
704data on demand derive from this class and overload `GetBitmap`.", "");
705
d14a1e28
RD
706class wxPyBitmapDataObject : public wxBitmapDataObject {
707public:
2b9048c5 708 %pythonAppend wxPyBitmapDataObject "self._setCallbackInfo(self, PyBitmapDataObject)"
d14a1e28
RD
709
710 wxPyBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
711 void _setCallbackInfo(PyObject* self, PyObject* _class);
712};
713
714//---------------------------------------------------------------------------
715
716
8e0ecdd9
RD
717DocStr(wxFileDataObject,
718"wx.FileDataObject is a specialization of `wx.DataObjectSimple` for
719file names. The program works with it just as if it were a list of
720absolute file names, but internally it uses the same format as
721Explorer and other compatible programs under Windows or GNOME/KDE
722filemanager under Unix which makes it possible to receive files from
23f8f985 723them using this class.", "");
8e0ecdd9 724
d14a1e28
RD
725class wxFileDataObject : public wxDataObjectSimple
726{
727public:
8e0ecdd9
RD
728 DocCtorStr(
729 wxFileDataObject(),
730 "", "");
d14a1e28 731
8e0ecdd9
RD
732 DocDeclAStr(
733 const wxArrayString& , GetFilenames(),
734 "GetFilenames(self) -> [names]",
735 "Returns a list of file names.", "");
736
737 DocDeclStr(
738 void , AddFile(const wxString &filename),
739 "Adds a file to the list of files represented by this data object.", "");
740
d14a1e28
RD
741};
742
d14a1e28
RD
743//---------------------------------------------------------------------------
744
8e0ecdd9
RD
745DocStr(wxCustomDataObject,
746"wx.CustomDataObject is a specialization of `wx.DataObjectSimple` for
747some application-specific data in arbitrary format. Python strings
748are used for getting and setting data, but any picklable object can
749easily be transfered via strings. A copy of the data is stored in the
750data object.", "");
751
d14a1e28
RD
752class wxCustomDataObject : public wxDataObjectSimple {
753public:
23f8f985
RD
754 %nokwargs wxCustomDataObject;
755 wxCustomDataObject(const wxDataFormat& format);
756 %extend {
757 wxCustomDataObject(const wxString& formatName) {
758 return new wxCustomDataObject(wxDataFormat(formatName));
759 }
760 }
761 wxCustomDataObject();
762
8e0ecdd9 763
d14a1e28 764 %extend {
214c4fbe
RD
765 DocAStr(SetData,
766 "SetData(self, String data) -> bool",
767 "Copy the data value to the data object.", "");
d14a1e28 768 bool SetData(PyObject* data) {
8e0ecdd9 769 bool rval;
6e6b3557 770 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 771 if (PyString_Check(data)) {
8e0ecdd9 772 rval = self->SetData(PyString_Size(data), PyString_AsString(data));
d14a1e28
RD
773 }
774 else {
775 // raise a TypeError if not a string
776 PyErr_SetString(PyExc_TypeError, "String expected.");
a72f4631 777 rval = false;
d14a1e28 778 }
8e0ecdd9
RD
779 wxPyEndBlockThreads(blocked);
780 return rval;
d14a1e28
RD
781 }
782 }
8e0ecdd9
RD
783 %pythoncode { TakeData = SetData }
784
785 DocDeclStr(
786 size_t , GetSize(),
787 "Get the size of the data.", "");
788
d14a1e28 789
d14a1e28 790 %extend {
214c4fbe
RD
791 DocAStr(GetData,
792 "GetData(self) -> String",
793 "Returns the data bytes from the data object as a string.", "");
d14a1e28 794 PyObject* GetData() {
8e0ecdd9 795 PyObject* obj;
6e6b3557 796 wxPyBlock_t blocked = wxPyBeginBlockThreads();
8e0ecdd9 797 obj = PyString_FromStringAndSize((char*)self->GetData(), self->GetSize());
c61fb035
RD
798 wxPyEndBlockThreads(blocked);
799 return obj;
d14a1e28
RD
800 }
801 }
802};
803
804
d14a1e28
RD
805//---------------------------------------------------------------------------
806
8e0ecdd9
RD
807DocStr(wxURLDataObject,
808"This data object holds a URL in a format that is compatible with some
809browsers such that it is able to be dragged to or from them.", "");
095315e2 810class wxURLDataObject : public wxDataObject/*Composite*/ {
d14a1e28
RD
811public:
812 wxURLDataObject();
813
8e0ecdd9
RD
814 DocDeclStr(
815 wxString , GetURL(),
816 "Returns a string containing the current URL.", "");
817
818 DocDeclStr(
819 void , SetURL(const wxString& url),
820 "Set the URL.", "");
821
d14a1e28
RD
822};
823
824//---------------------------------------------------------------------------
825
c1201401 826#if defined(__WXMSW__) || defined(__WXMAC__)
d14a1e28
RD
827
828%{
829#include <wx/metafile.h>
830%}
831
832class wxMetafileDataObject : public wxDataObjectSimple
833{
834public:
835 wxMetafileDataObject();
836
837 void SetMetafile(const wxMetafile& metafile);
838 wxMetafile GetMetafile() const;
839};
840
841
842#else
843%{
844class wxMetafileDataObject : public wxDataObjectSimple
845{
846public:
81cfe5e1 847 wxMetafileDataObject() { wxPyRaiseNotImplemented(); }
d14a1e28
RD
848};
849%}
850
851class wxMetafileDataObject : public wxDataObjectSimple
852{
853public:
854 wxMetafileDataObject();
855};
856
857#endif
858
859//---------------------------------------------------------------------------
860//---------------------------------------------------------------------------
861