2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dataobj.h
|
|
|
|
// Purpose: documentation for wxCustomDataObject class
|
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxCustomDataObject
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
wxCustomDataObject is a specialization of
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataObjectSimple for some
|
|
|
|
application-specific data in arbitrary (either custom or one of the standard
|
|
|
|
ones). The only restriction is that it is supposed that this data can be
|
|
|
|
copied bitwise (i.e. with @c memcpy()), so it would be a bad idea to make
|
|
|
|
it contain a C++ object (though C struct is fine).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
By default, wxCustomDataObject stores the data inside in a buffer. To put the
|
2008-03-08 09:43:31 -05:00
|
|
|
data into the buffer you may use either
|
|
|
|
wxCustomDataObject::SetData or
|
2008-03-08 08:52:38 -05:00
|
|
|
wxCustomDataObject::TakeData depending on whether you want
|
|
|
|
the object to make a copy of data or not.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
If you already store the data in another place, it may be more convenient and
|
|
|
|
efficient to provide the data on-demand which is possible too if you override
|
|
|
|
the virtual functions mentioned below.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
wxDataObject
|
|
|
|
*/
|
|
|
|
class wxCustomDataObject : public wxDataObjectSimple
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
The constructor accepts a @a format argument which specifies the (single)
|
2008-03-08 09:43:31 -05:00
|
|
|
format supported by this object. If it isn't set here,
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataObjectSimple::SetFormat should be used.
|
|
|
|
*/
|
|
|
|
wxCustomDataObject(const wxDataFormat& format = wxFormatInvalid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
The destructor will free the data hold by the object. Notice that although it
|
|
|
|
calls a virtual Free() function, the base
|
|
|
|
class version will always be called (C++ doesn't allow calling virtual
|
|
|
|
functions from constructors or destructors), so if you override @c Free(), you
|
|
|
|
should override the destructor in your class as well (which would probably
|
|
|
|
just call the derived class' version of @c Free()).
|
|
|
|
*/
|
|
|
|
~wxCustomDataObject();
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
This function is called to allocate @a size bytes of memory from SetData().
|
2008-03-08 08:52:38 -05:00
|
|
|
The default version just uses the operator new.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
virtual void* Alloc(size_t size);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
This function is called when the data is freed, you may override it to anything
|
|
|
|
you want (or may be nothing at all). The default version calls operator
|
|
|
|
delete[] on the data.
|
|
|
|
*/
|
|
|
|
virtual void Free();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to the data.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual void* GetData() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the data size in bytes.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual size_t GetSize() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the data. The data object will make an internal copy.
|
|
|
|
*/
|
|
|
|
virtual void SetData(size_t size, const void data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Like SetData(), but doesn't copy the data -
|
|
|
|
instead the object takes ownership of the pointer.
|
|
|
|
@b wxPython note: This method expects a string in wxPython. You can pass
|
|
|
|
nearly any object by pickling it first.
|
|
|
|
*/
|
|
|
|
virtual void TakeData(size_t size, const void data);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDataObjectComposite
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
wxDataObjectComposite is the simplest
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataObject derivation which may be used to support
|
2008-03-08 09:43:31 -05:00
|
|
|
multiple formats. It contains several
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataObjectSimple objects and supports any
|
|
|
|
format supported by at least one of them. Only one of these data objects is
|
|
|
|
@e preferred (the first one if not explicitly changed by using the second
|
|
|
|
parameter of wxDataObjectComposite::Add) and its format determines
|
|
|
|
the preferred format of the composite data object as well.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
See wxDataObject documentation for the reasons why you
|
|
|
|
might prefer to use wxDataObject directly instead of wxDataObjectComposite for
|
|
|
|
efficiency reasons.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{FIXME}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview",
|
|
|
|
wxDataObject, wxDataObjectSimple, wxFileDataObject, wxTextDataObject, wxBitmapDataObject
|
|
|
|
*/
|
|
|
|
class wxDataObjectComposite : public wxDataObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
The default constructor.
|
|
|
|
*/
|
|
|
|
wxDataObjectComposite();
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Adds the @a dataObject to the list of supported objects and it becomes the
|
|
|
|
preferred object if @a preferred is @true.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void Add(wxDataObjectSimple dataObject, bool preferred = false);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Report the format passed to the SetData method. This should be the
|
|
|
|
format of the data object within the composite that recieved data from
|
|
|
|
the clipboard or the DnD operation. You can use this method to find
|
|
|
|
out what kind of data object was recieved.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxDataFormat GetReceivedFormat() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDataObjectSimple
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
This is the simplest possible implementation of the
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataObject class. The data object of (a class derived
|
|
|
|
from) this class only supports one format, so the number of virtual functions
|
|
|
|
to be implemented is reduced.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Notice that this is still an abstract base class and cannot be used but should
|
|
|
|
be derived from.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b wxPython note: If you wish to create a derived wxDataObjectSimple class in
|
|
|
|
wxPython you should derive the class from wxPyDataObjectSimple
|
|
|
|
in order to get Python-aware capabilities for the various virtual
|
|
|
|
methods.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b wxPerl note: In wxPerl, you need to derive your data object class
|
|
|
|
from Wx::PlDataObjectSimple.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{FIXME}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref
|
|
|
|
overview_samplednd "DnD sample", wxFileDataObject, wxTextDataObject, wxBitmapDataObject
|
|
|
|
*/
|
|
|
|
class wxDataObjectSimple : public wxDataObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor accepts the supported format (none by default) which may also be
|
|
|
|
set later with SetFormat().
|
|
|
|
*/
|
|
|
|
wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Copy the data to the buffer, return @true on success. Must be implemented in the
|
|
|
|
derived class if the object supports rendering its data.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual bool GetDataHere(void buf) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the size of our data. Must be implemented in the derived class if the
|
|
|
|
object supports rendering its data.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual size_t GetDataSize() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the (one and only one) format supported by this object. It is supposed
|
|
|
|
that the format is supported in both directions.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
const wxDataFormat GetFormat() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Copy the data from the buffer, return @true on success. Must be implemented in
|
|
|
|
the derived class if the object supports setting its data.
|
|
|
|
@b wxPython note: When implementing this method in wxPython, the data comes
|
|
|
|
as a single string parameter rather than the two shown here.
|
|
|
|
*/
|
|
|
|
virtual bool SetData(size_t len, const void buf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the supported format.
|
|
|
|
*/
|
|
|
|
void SetFormat(const wxDataFormat& format);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxBitmapDataObject
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxBitmapDataObject is a specialization of wxDataObject for bitmap data. It can
|
2008-03-08 09:43:31 -05:00
|
|
|
be used without change to paste data into the
|
2008-03-08 08:52:38 -05:00
|
|
|
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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b wxPython note: If you wish to create a derived wxBitmapDataObject class in
|
|
|
|
wxPython you should derive the class from wxPyBitmapDataObject
|
|
|
|
in order to get Python-aware capabilities for the various virtual
|
|
|
|
methods.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview",
|
|
|
|
wxDataObject, wxDataObjectSimple, wxFileDataObject, wxTextDataObject, wxDataObject
|
|
|
|
*/
|
|
|
|
class wxBitmapDataObject : public wxDataObjectSimple
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Constructor, optionally passing a bitmap (otherwise use
|
2008-03-08 08:52:38 -05:00
|
|
|
SetBitmap() later).
|
|
|
|
*/
|
|
|
|
wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
wxWidgets' internals. Use this method to get data in bitmap form from
|
|
|
|
the wxClipboard.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual wxBitmap GetBitmap() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the bitmap associated with the data object. This method is called when the
|
|
|
|
data object receives data. Usually there will be no reason to override this
|
|
|
|
function.
|
|
|
|
*/
|
|
|
|
virtual void SetBitmap(const wxBitmap& bitmap);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDataFormat
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A wxDataFormat is an encapsulation of a platform-specific format handle which
|
|
|
|
is used by the system for the clipboard and drag and drop operations. The
|
|
|
|
applications are usually only interested in, for example, pasting data from the
|
|
|
|
clipboard only if the data is in a format the program understands and a data
|
|
|
|
format is something which uniquely identifies this format.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
On the system level, a data format is usually just a number (@c CLIPFORMAT
|
|
|
|
under Windows or @c Atom under X11, for example) and the standard formats
|
|
|
|
are, indeed, just numbers which can be implicitly converted to wxDataFormat.
|
|
|
|
The standard formats are:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDF_INVALID
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
An invalid format - used as default argument for
|
|
|
|
functions taking a wxDataFormat argument sometimes
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDF_TEXT
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Text format (wxString)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDF_BITMAP
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A bitmap (wxBitmap)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDF_METAFILE
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A metafile (wxMetafile, Windows only)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDF_FILENAME
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A list of filenames
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDF_HTML
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
An HTML string. This is only valid when passed to wxSetClipboardData
|
|
|
|
when compiled with Visual C++ in non-Unicode mode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
As mentioned above, these standard formats may be passed to any function taking
|
|
|
|
wxDataFormat argument because wxDataFormat has an implicit conversion from
|
|
|
|
them (or, to be precise from the type @c wxDataFormat::NativeFormat which is
|
|
|
|
the type used by the underlying platform for data formats).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Aside the standard formats, the application may also use custom formats which
|
|
|
|
are identified by their names (strings) and not numeric identifiers. Although
|
|
|
|
internally custom format must be created (or @e registered) first, you
|
|
|
|
shouldn't care about it because it is done automatically the first time the
|
|
|
|
wxDataFormat object corresponding to a given format name is created. The only
|
|
|
|
implication of this is that you should avoid having global wxDataFormat objects
|
|
|
|
with non-default constructor because their constructors are executed before the
|
|
|
|
program has time to perform all necessary initialisations and so an attempt to
|
|
|
|
do clipboard format registration at this time will usually lead to a crash!
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref
|
|
|
|
overview_samplednd "DnD sample", wxDataObject
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxDataFormat
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Constructs a data format object for a custom format identified by its name
|
2008-03-08 08:52:38 -05:00
|
|
|
@e format.
|
|
|
|
*/
|
|
|
|
wxDataFormat(const wxChar format);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the name of a custom format (this function will fail for a standard
|
|
|
|
format).
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetId() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the platform-specific number identifying the format.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
NativeFormat GetType() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the format to be the custom format identified by the given name.
|
|
|
|
*/
|
|
|
|
void SetId(const wxChar format);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the format to the given value, which should be one of wxDF_XXX constants.
|
|
|
|
*/
|
|
|
|
void SetType(NativeFormat format);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the formats are different.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool operator !=(const wxDataFormat& format) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the formats are equal.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool operator ==(const wxDataFormat& format) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxURLDataObject
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxURLDataObject is a wxDataObject containing an URL
|
|
|
|
and can be used e.g. when you need to put an URL on or retrieve it from the
|
|
|
|
clipboard:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
wxTheClipboard-SetData(new wxURLDataObject(url));
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview", wxDataObject
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxURLDataObject
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Constructor, may be used to initialize the URL. If @a url is empty,
|
2008-03-08 08:52:38 -05:00
|
|
|
SetURL() can be used later.
|
|
|
|
*/
|
|
|
|
wxURLDataObject(const wxString& url = wxEmptyString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the URL stored by this object, as a string.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetURL() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the URL stored by this object.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void SetURL(const wxString& url);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDataObject
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A wxDataObject represents data that can be copied to or from the clipboard, or
|
|
|
|
dragged and dropped. The important thing about wxDataObject 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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
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. wxDataObject defines an
|
|
|
|
enumeration type
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
enum Direction
|
|
|
|
{
|
|
|
|
Get = 0x01, // format is supported by GetDataHere()
|
|
|
|
Set = 0x02 // format is supported by SetData()
|
|
|
|
};
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
which distinguishes between them. See
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataFormat documentation for more about formats.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
To provide a solution for both cases, wxWidgets has two predefined classes
|
2008-03-08 09:43:31 -05:00
|
|
|
which derive from wxDataObject: wxDataObjectSimple and
|
|
|
|
wxDataObjectComposite.
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDataObjectSimple is
|
|
|
|
the simplest wxDataObject possible and only holds data in a single format (such
|
|
|
|
as HTML or text) and wxDataObjectComposite is
|
|
|
|
the simplest way to implement a wxDataObject that does support multiple formats
|
|
|
|
because it achieves this by simply holding several wxDataObjectSimple objects.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
So, you have several solutions when you need a wxDataObject class (and you need
|
|
|
|
one as soon as you want to transfer data via the clipboard or drag and drop):
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b 1. Use one of the built-in classes
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
You may use wxTextDataObject,
|
|
|
|
wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need
|
|
|
|
to support one format and your data is either text, bitmap or list of files.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b 2. Use wxDataObjectSimple
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Deriving from wxDataObjectSimple 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 copies of it).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b 3. Use wxDataObjectComposite
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
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).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b 4. Use wxDataObject directly
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This is the solution for
|
|
|
|
maximal flexibility and efficiency, but it is also the most difficult to
|
|
|
|
implement.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Please note that the easiest way to use drag and drop and the clipboard with
|
|
|
|
multiple formats is by using wxDataObjectComposite, but it is not the most
|
|
|
|
efficient one as each wxDataObjectSimple 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 wxDataObject directly and make it enumerate its
|
|
|
|
formats and provide the data in the requested format on demand.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that neither the GTK+ data transfer mechanisms for clipboard and
|
|
|
|
drag and drop, nor OLE data transfer, copy 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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
There are several predefined data object classes derived from
|
2008-03-08 09:43:31 -05:00
|
|
|
wxDataObjectSimple: wxFileDataObject,
|
2008-03-08 08:52:38 -05:00
|
|
|
wxTextDataObject,
|
|
|
|
wxBitmapDataObject and
|
|
|
|
wxURLDataObject
|
|
|
|
which can be used without change.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
You may also derive your own data object classes from
|
2008-03-08 08:52:38 -05:00
|
|
|
wxCustomDataObject 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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b wxPython note: At this time this class is not directly usable from wxPython.
|
2008-03-08 09:43:31 -05:00
|
|
|
Derive a class from wxPyDataObjectSimple
|
2008-03-08 08:52:38 -05:00
|
|
|
instead.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b wxPerl note: This class is not currently usable from wxPerl; you may
|
|
|
|
use Wx::PlDataObjectSimple instead.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref
|
|
|
|
overview_samplednd "DnD sample", wxFileDataObject, wxTextDataObject, wxBitmapDataObject, wxCustomDataObject, wxDropTarget, wxDropSource, wxTextDropTarget, wxFileDropTarget
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxDataObject
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxDataObject();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxDataObject();
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Copy all supported formats in the given direction to the array pointed to by
|
2008-03-08 08:52:38 -05:00
|
|
|
@e formats. There is enough space for GetFormatCount(dir) formats in it.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
virtual void GetAllFormats(wxDataFormat* formats,
|
2008-03-09 12:24:26 -04:00
|
|
|
Direction dir = Get) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
The method will write the data of the format @a format in the buffer @a buf and
|
2008-03-08 08:52:38 -05:00
|
|
|
return @true on success, @false on failure.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual bool GetDataHere(const wxDataFormat& format, void buf) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the data size of the given format @e format.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual size_t GetDataSize(const wxDataFormat& format) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of available formats for rendering or setting the data.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual size_t GetFormatCount(Direction dir = Get) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Returns the preferred format for either rendering the data (if @a dir is @c Get,
|
2008-03-08 08:52:38 -05:00
|
|
|
its default value) or for setting it. Usually this will be the
|
|
|
|
native format of the wxDataObject.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual wxDataFormat GetPreferredFormat(Direction dir = Get) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Set the data in the format @a format of the length @a len provided in the
|
2008-03-08 08:52:38 -05:00
|
|
|
buffer @e buf.
|
|
|
|
Returns @true on success, @false on failure.
|
|
|
|
*/
|
|
|
|
virtual bool SetData(const wxDataFormat& format, size_t len,
|
|
|
|
const void buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxTextDataObject
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxTextDataObject is a specialization of wxDataObject for text data. It can be
|
2008-03-08 09:43:31 -05:00
|
|
|
used without change to paste data into the wxClipboard
|
2008-03-08 08:52:38 -05:00
|
|
|
or a wxDropSource. A user may wish to derive a new
|
|
|
|
class from this class for providing text on-demand in order to minimize memory
|
|
|
|
consumption when offering data in several formats, such as plain text and RTF
|
|
|
|
because by default the text is stored in a string in this class, but it might
|
2008-03-08 09:43:31 -05:00
|
|
|
as well be generated when requested. For this,
|
|
|
|
wxTextDataObject::GetTextLength and
|
2008-03-08 08:52:38 -05:00
|
|
|
wxTextDataObject::GetText will have to be overridden.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that if you already have the text inside a string, you will not achieve
|
|
|
|
any efficiency gain by overriding these functions because copying wxStrings is
|
|
|
|
already a very efficient operation (data is not actually copied because
|
|
|
|
wxStrings are reference counted).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b wxPython note: If you wish to create a derived wxTextDataObject class in
|
|
|
|
wxPython you should derive the class from wxPyTextDataObject
|
|
|
|
in order to get Python-aware capabilities for the various virtual
|
|
|
|
methods.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
@ref overview_wxdndoverview "Clipboard and drag and drop overview",
|
|
|
|
wxDataObject, wxDataObjectSimple, wxFileDataObject, wxBitmapDataObject
|
|
|
|
*/
|
|
|
|
class wxTextDataObject : public wxDataObjectSimple
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Constructor, may be used to initialise the text (otherwise
|
2008-03-08 08:52:38 -05:00
|
|
|
SetText() should be used later).
|
|
|
|
*/
|
|
|
|
wxTextDataObject(const wxString& text = wxEmptyString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the text associated with the data object. You may wish to override
|
|
|
|
this method when offering data on-demand, but this is not required by
|
|
|
|
wxWidgets' internals. Use this method to get data in text form from
|
|
|
|
the wxClipboard.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual wxString GetText() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the data size. By default, returns the size of the text data
|
|
|
|
set in the constructor or using SetText().
|
|
|
|
This can be overridden to provide text size data on-demand. It is recommended
|
|
|
|
to return the text length plus 1 for a trailing zero, but this is not
|
|
|
|
strictly required.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual size_t GetTextLength() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the text associated with the data object. This method is called
|
|
|
|
when the data object receives the data and, by default, copies the text into
|
|
|
|
the member variable. If you want to process the text on the fly you may wish to
|
|
|
|
override this function.
|
|
|
|
*/
|
|
|
|
virtual void SetText(const wxString& strText);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxFileDataObject
|
|
|
|
@wxheader{dataobj.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
wxFileDataObject is a specialization of wxDataObject
|
2008-03-08 08:52:38 -05:00
|
|
|
for file names. The program works with it just as if it were a list of absolute
|
|
|
|
file
|
|
|
|
names, but internally it uses the same format as
|
|
|
|
Explorer and other compatible programs under Windows or GNOME/KDE filemanager
|
|
|
|
under Unix which makes it possible to receive files from them using this
|
|
|
|
class.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@b Warning: Under all non-Windows platforms this class is currently
|
|
|
|
"input-only", i.e. you can receive the files from another application, but
|
|
|
|
copying (or dragging) file(s) from a wxWidgets application is not currently
|
|
|
|
supported. PS: GTK2 should work as well.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dnd}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@seealso
|
|
|
|
wxDataObject, wxDataObjectSimple, wxTextDataObject, wxBitmapDataObject,
|
|
|
|
wxDataObject
|
|
|
|
*/
|
|
|
|
class wxFileDataObject : public wxDataObjectSimple
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxFileDataObject();
|
|
|
|
|
|
|
|
/**
|
|
|
|
@b MSW only: adds a file to the file list represented by this data object.
|
|
|
|
*/
|
|
|
|
virtual void AddFile(const wxString& file);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the array of file names.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
const wxArrayString GetFilenames() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|