Contents Up Previous Next

wxBitmapDataObject

wxBitmapDataObject is a specialization of wxDataObject for bitmap 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 a bitmap on-demand in order to minimize memory consumption when offering data in several formats, such as a bitmap and GIF.

In order to offer bitmap data on-demand GetSize and WriteData will have to be overridden.

Derived from

wxDataObject

Include files

<wx/dataobj.h>

See also

wxDataObject

Members

wxBitmapDataObject::wxBitmapDataObject
wxBitmapDataObject::GetSize
wxBitmapDataObject::GetBitmap
wxBitmapDataObject::SetBitmap
wxBitmapDataObject::WriteData
wxBitmapDataObject::WriteBitmap


wxBitmapDataObject::wxBitmapDataObject

wxBitmapDataObject()

Default constructor. Call SetBitmap later or override WriteData and GetSize for providing data on-demand.

wxBitmapDataObject(const wxBitmap& bitmap)

Constructor, passing a bitmap.


wxBitmapDataObject::GetSize

virtual size_t GetSize() const

Returns the data size. By default, returns the size of the bitmap data set in the constructor or using SetBitmap. This can be overridden to provide size data on-demand. Note that you'd have to call the inherited GetSize method as this is the only way to get to know the transfer size of the bitmap in a platform dependent way - a bitmap has different size under GTK and Windows. In practice, this would look like this:

size_t MyBitmapDataObject::GetSize()
{
  // Get bitmap from global container. This container
  // should be able to "produce" data in all formats
  // offered by the application but store it only in
  // one format to reduce memory consumption.

  wxBitmap my_bitmap = my_global_container->GetBitmap();
  
  // temporarily set bitmap
  
  SetBitmap( my_bitmap );

  size_t ret = wxBitmapDataObject::GetSize();
  
  // unset bitmap again
  
  SetBitmap( wxNullBitmap );

  retrun ret;
}
TODO: Offer a nicer way to do this. Maybe by providing a platform dependent function in this class like

size_t GetBitmapSize( const wxBitmap &bitmap )

wxBitmapDataObject::GetBitmap

virtual wxBitmap GetBitmap() const

Returns the bitmap associated with the data object. You may wish to override this method when offering data on-demand, but this is not required by wxWindows' internals. Use this method to get data in bitmap form from the wxClipboard.


wxBitmapDataObject::SetBitmap

virtual void SetBitmap(const wxBitmap& bitmap)

Sets the bitmap associated with the data object. This method is called internally when retrieving data from the wxClipboard and may be used to paste data to the clipboard directly (instead of on-demand).


wxBitmapDataObject::WriteData

virtual void WriteData(void*dest ) const

Write the data owned by this class to dest. By default, this calls WriteBitmap with the bitmap set in the constructor or using SetBitmap. This can be overridden to provide bitmap data on-demand; in this case WriteBitmap must be called from within th overriding WriteData() method.


wxBitmapDataObject::WriteBitmap

void WriteBitmap(const wxBitmap& bitmapvoid*dest ) const

Writes the the bitmap bitmap to dest. This method must be called from WriteData.