Table Of Contents

Previous topic

TextCtrlHitTestResult

Next topic

TextDropTarget

This Page

phoenix_title TextDataObject

TextDataObject is a specialization of DataObjectSimple for text data.

It can be used without change to paste data into the Clipboard or a DropSource. 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 string is already a very efficient operation (data is not actually copied because string are reference counted).


class_hierarchy Inheritance Diagram

Inheritance diagram for class TextDataObject

Inheritance diagram of TextDataObject


sub_classes Known Subclasses

URLDataObject


method_summary Methods Summary

__init__ Constructor, may be used to initialise the text (otherwise SetText should be used later).
GetFormat Returns the preferred format supported by this object.
GetFormatCount Returns 2 under Mac and wxGTK, where text data coming from the clipboard may be provided as ANSI ( DF_TEXT ) or as Unicode text ( DF_UNICODETEXT , but only when USE_UNICODE==1 ).
GetText Returns the text associated with the data object.
GetTextLength Returns the data size.
SetText Sets the text associated with the data object.

property_summary Properties Summary

AllFormats See GetAllFormats
Format See GetFormat
FormatCount See GetFormatCount
Text See GetText and SetText
TextLength See GetTextLength

api Class API



class TextDataObject(DataObjectSimple)

TextDataObject is a specialization of DataObjectSimple for text data.

Possible constructors:

TextDataObject(text='')

Methods



__init__(self, text='')

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

Parameters:text (string) –


GetFormat(self)

Returns the preferred format supported by this object.

This is DF_TEXT or DF_UNICODETEXT depending on the platform and from the build mode (i.e. from USE_UNICODE ).

Return type: DataFormat


GetFormatCount(self, dir=DataObject.Get)

Returns 2 under Mac and wxGTK, where text data coming from the clipboard may be provided as ANSI ( DF_TEXT ) or as Unicode text ( DF_UNICODETEXT , but only when USE_UNICODE==1 ).

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

Parameters:dir (DataObject.Direction) –
Return type:int


GetText(self)

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 Clipboard.

Return type:string


GetTextLength(self)

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.

Return type:int


SetText(self, strText)

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.

Parameters:strText (string) –

Properties



AllFormats

See GetAllFormats



Format

See GetFormat



FormatCount

See GetFormatCount



Text

See GetText and SetText



TextLength

See GetTextLength