# wxTextDataObject Class Reference
[Clipboard and Drag & Drop]

`#include <wx/dataobj.h>`

Inheritance diagram for wxTextDataObject:
[legend]

## Detailed Description

wxTextDataObject is a specialization of wxDataObjectSimple for text data.

It can be used without change to paste data into the wxClipboard or a wxDropSource. A user may wish to derive a new class from this class for providing text on-demand in order to minimize memory consumption when offering data in several formats, such as plain text and RTF because by default the text is stored in a string in this class, but it might as well be generated when requested. For this, GetTextLength() and GetText() will have to be overridden.

Note that if you already have the text inside a string, you will not achieve any efficiency gain by overriding these functions because copying wxStrings is already a very efficient operation (data is not actually copied because wxStrings are reference counted).

wxPython Note: If you wish to create a derived wxTextDataObject class in wxPython you should derive the class from wxPyTextDataObject in order to get Python-aware capabilities for the various virtual methods.

##

Library: wxCore

Category: Clipboard and Drag & Drop

See also:
  Drag and Drop Overview, wxDataObject, wxDataObjectSimple, wxFileDataObject, wxBitmapDataObject

## Public Member Functions
| wxTextDataObject (const wxString &text=wxEmptyString)
| Constructor, may be used to initialise the text (otherwise SetText() should be used later).
virtual wxString | GetText () const
| Returns the text associated with the data object.
virtual size_t | GetTextLength () const
| Returns the data size.
virtual size_t | GetFormatCount (Direction dir=Get)
| Returns 2 under wxMac and wxGTK, where text data coming from the clipboard may be provided as ANSI (`wxDF_TEXT`) or as Unicode text (`wxDF_UNICODETEXT`, but only when `wxUSE_UNICODE==1`).
const wxDataFormat & | GetFormat () const
| Returns the preferred format supported by this object.
virtual void | GetAllFormats (wxDataFormat *formats, Direction dir=Get) const =0
| Returns all the formats supported by wxTextDataObject.
virtual void | SetText (const wxString &strText)
| Sets the text associated with the data object.

List of all members.

## Constructor & Destructor Documentation

wxTextDataObject::wxTextDataObject | ( | const wxString & | text = `wxEmptyString` | ) |

Constructor, may be used to initialise the text (otherwise SetText() should be used later).

## Member Function Documentation

virtual void wxTextDataObject::GetAllFormats | ( | wxDataFormat * | formats,
|  | Direction | dir = `Get` |
| ) |  |  | const`[pure virtual]`

Returns all the formats supported by wxTextDataObject.

Under wxMac and wxGTK they are `wxDF_TEXT` and `wxDF_UNICODETEXT`, under other ports returns only one of the two, depending on the build mode.

Implements wxDataObject.

const wxDataFormat& wxTextDataObject::GetFormat | ( |  | ) | const

Returns the preferred format supported by this object.

This is `wxDF_TEXT` or `wxDF_UNICODETEXT` depending on the platform and from the build mode (i.e. from `wxUSE_UNICODE`).

Reimplemented from wxDataObjectSimple.

virtual size_t wxTextDataObject::GetFormatCount | ( | Direction | dir = `Get` | ) | `[virtual]`

Returns 2 under wxMac and wxGTK, where text data coming from the clipboard may be provided as ANSI (`wxDF_TEXT`) or as Unicode text (`wxDF_UNICODETEXT`, but only when `wxUSE_UNICODE==1`).

Returns 1 under other platforms (e.g. wxMSW) or when building in ANSI mode (`wxUSE_UNICODE==0`).

virtual wxString wxTextDataObject::GetText | ( |  | ) | const`[virtual]`

Returns the text associated with the data object.

You may wish to override this method when offering data on-demand, but this is not required by wxWidgets' internals. Use this method to get data in text form from the wxClipboard.

virtual size_t wxTextDataObject::GetTextLength | ( |  | ) | const`[virtual]`

Returns the data size.

By default, returns the size of the text data set in the constructor or using SetText(). This can be overridden to provide text size data on-demand. It is recommended to return the text length plus 1 for a trailing zero, but this is not strictly required.

virtual void wxTextDataObject::SetText | ( | const wxString & | strText | ) | `[virtual]`

Sets the text associated with the data object.

This method is called when the data object receives the data and, by default, copies the text into the member variable. If you want to process the text on the fly you may wish to override this function.

|  | [ top ]