Class: Wx::DataObjectComposite

Inherits:
DataObject show all
Defined in:
lib/wx/doc/gen/data_object.rb

Overview

DataObjectComposite is the simplest DataObject derivation which may be used to support multiple formats.

It contains several DataObjectSimple 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 DataObject documentation for the reasons why you might prefer to use DataObject directly instead of DataObjectComposite 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:

class MyDropTarget < Wx::DropTarget

    def initialize
      dataobj = Wx::DataObjectComposite.new
      dataobj.add(Wx::BitmapDataObject.new, true)
      dataobj.add(Wx::FileDataObject.new)
      set_data_object(dataobj)
    end
  
    def on_data(x, y, defaultDragResult)
      return Wx::DragNone unless get_data
  
      dataobj_comp = get_data_object
  
      format = dataobj_comp.get_received_format
      dataobj = dataobj_comp.get_object(format)
      case format.get_type
      when Wx::DataFormatId::DF_BITMAP
        # dataobj is Wx::BitmapDataObject

        ... use dataobj.get_bitmap ...

      when Wx::DataFormatId::DF_FILENAME
        # dataobj is Wx::FileDataObject

         ... use dataobj->GetFilenames() ...

      else
        Wx.log_error("unexpected data object format")
      end
  
      defaultDragResult
    end

  end

Category: Clipboard and Drag & Drop

See Also:

Requires:

  • USE_CLIPBOARD

Instance Method Summary collapse

Methods inherited from DataObject

#get_all_formats, #get_data_here, #get_data_size, #get_format_count, #get_preferred_format, #is_supported, #set_data

Constructor Details

#initializeWx::DataObjectComposite

The default constructor.



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

def initialize; end

Instance Method Details

#add(dataObject, preferred = false) ⇒ void

This method returns an undefined value.

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

Parameters:



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

def add(dataObject, preferred=false) end

#get_object(format, dir = DataObject::Get) ⇒ Wx::DataObjectSimple Also known as: object

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 Wx::DataObjectComposite itself and shouldn’t be deleted by caller.

Parameters:

Returns:



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

def get_object(format, dir=DataObject::Get) end

#get_received_formatWx::DataFormat Also known as: received_format

Report the format passed to the Wx::DataObject#set_data 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.

Returns:



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

def get_received_format; end