Class: Wx::DataObject

Inherits:
Object
  • Object
show all
Defined in:
lib/wx/doc/gen/data_object.rb,
lib/wx/doc/data_object.rb

Overview

A DataObject represents data that can be copied to or from the clipboard, or dragged and dropped.

The important thing about DataObject is that this is a ‘smart’ piece of data unlike ‘dumb’ data containers such as memory buffers or files. Being ‘smart’ here means that the data object itself should know what data formats it supports and how to render itself in each of its supported formats. A supported format, incidentally, is exactly the format in which the data can be requested from a data object or from which the data object may be set. In the general case, an object may support different formats on ‘input’ and ‘output’, i.e. it may be able to render itself in a given format but not be created from data on this format or vice versa. DataObject defines the Direction enumeration type which distinguishes between them. See DataFormat documentation for more about formats. Not surprisingly, being ‘smart’ comes at a price of added complexity. This is reasonable for the situations when you really need to support multiple formats, but may be annoying if you only want to do something simple like cut and paste text. To provide a solution for both cases, wxWidgets has two predefined classes which derive from DataObject: DataObjectSimple and DataObjectComposite. DataObjectSimple is the simplest DataObject possible and only holds data in a single format (such as HTML or text) and DataObjectComposite is the simplest way to implement a DataObject that does support multiple formats because it achieves this by simply holding several DataObjectSimple objects. So, you have several solutions when you need a DataObject class (and you need one as soon as you want to transfer data via the clipboard or drag and drop):

  • Use one of the built-in classes.

  • You may use TextDataObject, BitmapDataObject FileDataObject, URLDataObject in the simplest cases when you only need to support one format and your data is either text, bitmap or list of files.

  • Use DataObjectSimple

  • Deriving from DataObjectSimple is the simplest solution for custom data - you will only support one format and so probably won't be able to communicate with other programs, but data transfer will work in your program (or between different instances of it).

  • Use DataObjectComposite

  • This is a simple but powerful solution which allows you to support any number of formats (either standard or custom if you combine it with the previous solution).

  • Use DataObject directly

  • This is the solution for maximum flexibility and efficiency, but it is also the most difficult to implement.

Please note that the easiest way to use drag and drop and the clipboard with multiple formats is by using DataObjectComposite, but it is not the most efficient one as each DataObjectSimple would contain the whole data in its respective formats. Now imagine that you want to paste 200 pages of text in your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to the clipboard and even today’s computers are in trouble. For this case, you will have to derive from DataObject directly and make it enumerate its formats and provide the data in the requested format on demand. Note that neither the GTK+ data transfer mechanisms for clipboard and drag and drop, nor OLE data transfer, copies any data until another application actually requests the data. This is in contrast to the ‘feel’ offered to the user of a program who would normally think that the data resides in the clipboard after having pressed ‘Copy’ - in reality it is only declared to be available. You may also derive your own data object classes from CustomDataObject for user-defined types. The format of user-defined data is given as a mime-type string literal, such as “application/word” or “image/png”. These strings are used as they are under Unix (so far only GTK+) to identify a format and are translated into their Windows equivalent under Win32 (using the OLE IDataObject for data exchange to and from the clipboard and for drag and drop). Note that the format string translation under Windows is not yet finished. Each class derived directly from DataObject must override and implement all of its functions which are pure virtual in the base class. The data objects which only render their data or only set it (i.e. work in only one direction), should return 0 from #get_format_count.

Category: Clipboard and Drag & Drop

See Also:

Requires:

  • USE_CLIPBOARD

Defined Under Namespace

Classes: Direction

Instance Method Summary collapse

Constructor Details

#initializeWx::DataObject

Constructor.



79
# File 'lib/wx/doc/gen/data_object.rb', line 79

def initialize; end

Instance Method Details

#get_all_formats(dir = Wx::DataObjectSimpleBase::Direction::Get) ⇒ Array<Wx::DataFormat> Also known as: all_formats

Copies all formats supported in the given direction dir to the array pointed to by formats.

There must be enough space for GetFormatCount(dir) formats in it.

Parameters:

Returns:



86
# File 'lib/wx/doc/gen/data_object.rb', line 86

def get_all_formats(dir=Wx::DataObjectSimpleBase::Direction::Get) end

#get_data_here(format) ⇒ String Also known as: data_here

The method will write the data of the format format to the buffer buf.

In other words, copy the data from this object in the given format to the supplied buffer. Returns true on success, false on failure.

Parameters:

Returns:

  • (String)


94
# File 'lib/wx/doc/gen/data_object.rb', line 94

def get_data_here(format) end

#get_data_size(format) ⇒ Integer Also known as: data_size

Note:

IMPORTANT Please note that it is necessary to return the size in bytes of the data string

Returns the data size of the given format. Should be overridden in derived classes. returned by #get_data_here (not the size in characters).

Parameters:

Returns:

  • (Integer)


18
# File 'lib/wx/doc/data_object.rb', line 18

def get_data_size(format) end

#get_format_count(dir = Wx::DataObjectSimpleBase::Direction::Get) ⇒ Integer Also known as: format_count

Returns the number of available formats for rendering or setting the data.

Parameters:

Returns:

  • (Integer)


100
# File 'lib/wx/doc/gen/data_object.rb', line 100

def get_format_count(dir=Wx::DataObjectSimpleBase::Direction::Get) end

#get_preferred_format(dir = Wx::DataObjectSimpleBase::Direction::Get) ⇒ Wx::DataFormat Also known as: preferred_format

Returns the preferred format for either rendering the data (if dir is Get, its default value) or for setting it.

Usually this will be the native format of the Wx::DataObject.

Parameters:

Returns:



108
# File 'lib/wx/doc/gen/data_object.rb', line 108

def get_preferred_format(dir=Wx::DataObjectSimpleBase::Direction::Get) end

#is_supported(format, dir = Wx::DataObjectSimpleBase::Direction::Get) ⇒ Boolean Also known as: supported?

Returns true if this format is supported.

Parameters:

Returns:

  • (Boolean)


125
# File 'lib/wx/doc/gen/data_object.rb', line 125

def is_supported(format, dir=Wx::DataObjectSimpleBase::Direction::Get) end

#set_data(format, buf) ⇒ Boolean

Set the data in the format format of the length len provided in the buffer buf.

In other words, copy length bytes of data from the buffer to this data object.

true on success, false on failure.

Parameters:

  • format (Wx::DataFormat)

    The format for which to set the data.

  • buf (String)

    Non-NULL pointer to the data.

Returns:

  • (Boolean)


119
# File 'lib/wx/doc/gen/data_object.rb', line 119

def set_data(format, buf) end