wxWidgets: wxDataObjectComposite Class Reference

| Version: 3.2.6

Public Member Functions | List of all members
wxDataObjectComposite Class Reference
Class List by Category » Clipboard and Drag & Drop

`#include <wx/dataobj.h>`

Inheritance diagram for wxDataObjectComposite:
[legend]

## Detailed Description

wxDataObjectComposite is the simplest wxDataObject derivation which may be used to support multiple formats.

It contains several wxDataObjectSimple objects and supports any format supported by at least one of them. Only one of these data objects is preferred (the first one if not explicitly changed by using the second parameter of Add()) and its format determines the preferred format of the composite data object as well.

See wxDataObject documentation for the reasons why you might prefer to use wxDataObject directly instead of wxDataObjectComposite for efficiency reasons.

This example shows how a composite data object capable of storing either bitmaps or file names (presumably of bitmap files) can be initialized and used:

MyDropTarget::MyDropTarget()
{
wxDataObjectComposite* dataobj = new wxDataObjectComposite();
dataobj->Add(new wxBitmapDataObject(), true);
dataobj->Add(new wxFileDataObject());
SetDataObject(dataobj);
}
wxDragResult MyDropTarget::OnData(wxCoord x, wxCoord y,
wxDragResult defaultDragResult)
{
if ( !GetData() )
return wxDragNone;
wxDataObjectComposite *
dataobjComp = static_cast<wxDataObjectComposite *>(GetDataObject());
wxDataFormat format = dataobjComp->GetReceivedFormat();
wxDataObject *dataobj = dataobjComp->GetObject(format);
switch ( format.GetType() )
{
case wxDF_BITMAP:
{
wxBitmapDataObject *
dataobjBitmap = static_cast<wxBitmapDataObject *>(dataobj);
... use dataobj->GetBitmap() ...
}
break;
case wxDF_FILENAME:
{
wxFileDataObject *
dataobjFile = static_cast<wxFileDataObject *>(dataobj);
... use dataobj->GetFilenames() ...
}
break;
default:
wxFAIL_MSG( "unexpected data object format" );
}
return defaultDragResult;
}
wxBitmapDataObject
wxBitmapDataObject is a specialization of wxDataObject for bitmap data.
Definition: dataobj.h:602
wxDataFormat
A wxDataFormat is an encapsulation of a platform-specific format handle which is used by the system f...
Definition: dataobj.h:67
wxDataFormat::GetType
wxDataFormatId GetType() const
Returns the platform-specific number identifying the format.
wxDataObjectComposite
wxDataObjectComposite is the simplest wxDataObject derivation which may be used to support multiple f...
Definition: dataobj.h:478
wxDataObjectComposite::GetObject
wxDataObjectSimple * GetObject(const wxDataFormat &format, wxDataObject::Direction dir=wxDataObject::Get) const
Returns the pointer to the object which supports the passed format for the specified direction.
wxDataObjectComposite::GetReceivedFormat
wxDataFormat GetReceivedFormat() const
Report the format passed to the SetData() method.
wxDataObjectComposite::wxDataObjectComposite
wxDataObjectComposite()
The default constructor.
wxDataObjectComposite::Add
void Add(wxDataObjectSimple *dataObject, bool preferred=false)
Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred...
wxDataObject
A wxDataObject represents data that can be copied to or from the clipboard, or dragged and dropped.
Definition: dataobj.h:234
wxFileDataObject
wxFileDataObject is a specialization of wxDataObject for file names.
Definition: dataobj.h:807
wxCoord
int wxCoord
The type for screen and DC coordinates.
Definition: defs.h:1383
wxDF_FILENAME
@ wxDF_FILENAME
Definition: defs.h:853
wxDF_BITMAP
@ wxDF_BITMAP
Definition: defs.h:840
wxFAIL_MSG
#define wxFAIL_MSG(message)
Will always generate an assert error with specified message if this code is reached (in debug mode).
Definition: debug.h:326
wxDragResult
wxDragResult
Result returned from a wxDropSource::DoDragDrop() call.
Definition: dnd.h:22
wxDragNone
@ wxDragNone
Drag target didn't accept the data.
Definition: dnd.h:24

##

Library: wxCore
Category: Clipboard and Drag & Drop

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

## Public Member Functions
| wxDataObjectComposite ()
| The default constructor. More...
void | Add (wxDataObjectSimple *dataObject, bool preferred=false)
| Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred is true. More...
wxDataFormat | GetReceivedFormat () const
| Report the format passed to the SetData() method. More...
wxDataObjectSimple * | GetObject (const wxDataFormat &format, wxDataObject::Direction dir=wxDataObject::Get) const
| Returns the pointer to the object which supports the passed format for the specified direction. More...
Public Member Functions inherited from wxDataObject
| wxDataObject ()
| Constructor. More...
virtual | ~wxDataObject ()
| Destructor. More...
virtual void | GetAllFormats (wxDataFormat *formats, Direction dir=Get) const =0
| Copies all formats supported in the given direction dir to the array pointed to by formats. More...
virtual bool | GetDataHere (const wxDataFormat &format, void *buf) const =0
| The method will write the data of the format format to the buffer buf. More...
virtual size_t | GetDataSize (const wxDataFormat &format) const =0
| Returns the data size of the given format format. More...
virtual size_t | GetFormatCount (Direction dir=Get) const =0
| Returns the number of available formats for rendering or setting the data. More...
virtual wxDataFormat | GetPreferredFormat (Direction dir=Get) const =0
| Returns the preferred format for either rendering the data (if dir is `Get`, its default value) or for setting it. More...
virtual bool | SetData (const wxDataFormat &format, size_t len, const void *buf)
| Set the data in the format format of the length len provided in the buffer buf. More...
bool | IsSupported (const wxDataFormat &format, Direction dir=Get) const
| Returns true if this format is supported. More...

## Additional Inherited Members
Public Types inherited from wxDataObject
enum | Direction { Get = 0x01 , Set = 0x02 , Both = 0x03 }

## Constructor & Destructor Documentation

## ◆ wxDataObjectComposite()

wxDataObjectComposite::wxDataObjectComposite | ( |  | ) |

The default constructor.

## Member Function Documentation

## ◆ Add()

void wxDataObjectComposite::Add | ( | wxDataObjectSimple * | dataObject,
|  | bool | preferred = `false`
| ) |  |

Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred is true.

## ◆ GetObject()

wxDataObjectSimple* wxDataObjectComposite::GetObject | ( | const wxDataFormat & | format,
|  | wxDataObject::Direction | dir = `wxDataObject::Get`
| ) |  | const

Returns the pointer to the object which supports the passed format for the specified direction.

NULL is returned if the specified format is not supported for this direction dir. The returned pointer is owned by wxDataObjectComposite itself and shouldn't be deleted by caller.

Since
  2.9.1

## ◆ GetReceivedFormat()

wxDataFormat wxDataObjectComposite::GetReceivedFormat | ( |  | ) | const

Report the format passed to the SetData() method.

This should be the format of the data object within the composite that received data from the clipboard or the DnD operation. You can use this method to find out what kind of data object was received.