Public Member Functions

# wxDataObjectComposite Class Reference
[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)
        {
            wxDragResult dragResult = wxDropTarget::OnData(x, y, defaultDragResult);
            if ( dragResult == defaultDragResult )
            {
                wxDataObjectComposite *
                    dataobjComp = static_cast<wxDataObjectComposite *>(GetDataObject());

                wxDataFormat format = dataObjects->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 dragResult;
        }

##

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.
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.
wxDataFormat | GetReceivedFormat () const
| Report the format passed to the SetData() method.
wxDataObjectSimple * | GetObject (const wxDataFormat &format, wxDataObjectBase::Direction dir=Get) const
| Returns the pointer to the object which supports the passed format for the specified direction.

List of all members.

## Constructor & Destructor Documentation

wxDataObjectComposite::wxDataObjectComposite | ( |  | ) |

The default constructor.

## Member Function Documentation

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.

wxDataObjectSimple* wxDataObjectComposite::GetObject | ( | const wxDataFormat & | format,
|  | wxDataObjectBase::Direction | dir = `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

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.

|  | [ top ]