Reviewed dataobj.h interface header and added wxDataViewCtrl class group.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53173 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2008-04-15 03:25:23 +00:00
parent f416695a1b
commit b321b61c10
3 changed files with 367 additions and 358 deletions

View File

@@ -0,0 +1,17 @@
/////////////////////////////////////////////////////////////////////////////
// Name: class_dvc.h
// Purpose: wxDataViewControl classes group docs
// Author: wxWidgets team
// RCS-ID: $Id: class_dc.h 52454 2008-03-12 19:08:48Z BP $
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
/**
@defgroup group_class_dvc wxDataViewCtrl Related Classes
@ingroup group_class
These are all classes used or provided for use with wxDataViewCtrl.
*/

View File

@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: dataobj.h // Name: dataobj.h
// Purpose: interface of wxCustomDataObject // Purpose: interface of wx*DataObject
// Author: wxWidgets team // Author: wxWidgets team
// RCS-ID: $Id$ // RCS-ID: $Id$
// Licence: wxWindows license // Licence: wxWindows license
@@ -10,22 +10,20 @@
@class wxCustomDataObject @class wxCustomDataObject
@wxheader{dataobj.h} @wxheader{dataobj.h}
wxCustomDataObject is a specialization of wxCustomDataObject is a specialization of wxDataObjectSimple for some
wxDataObjectSimple for some application-specific data in arbitrary (either custom or one of the
application-specific data in arbitrary (either custom or one of the standard standard ones). The only restriction is that it is supposed that this data
ones). The only restriction is that it is supposed that this data can be can be copied bitwise (i.e. with @c memcpy()), so it would be a bad idea to
copied bitwise (i.e. with @c memcpy()), so it would be a bad idea to make make it contain a C++ object (though C struct is fine).
it contain a C++ object (though C struct is fine).
By default, wxCustomDataObject stores the data inside in a buffer. To put the By default, wxCustomDataObject stores the data inside in a buffer. To put
data into the buffer you may use either the data into the buffer you may use either SetData() or TakeData()
wxCustomDataObject::SetData or depending on whether you want the object to make a copy of data or not.
wxCustomDataObject::TakeData depending on whether you want
the object to make a copy of data or not.
If you already store the data in another place, it may be more convenient and This class may be used as is, but if you don't want store the data inside
efficient to provide the data on-demand which is possible too if you override the object but provide it on demand instead, you should override GetSize(),
the virtual functions mentioned below. GetData() and SetData() (or may be only the first two or only the last one
if you only allow reading/writing the data).
@library{wxcore} @library{wxcore}
@category{dnd} @category{dnd}
@@ -36,32 +34,32 @@ class wxCustomDataObject : public wxDataObjectSimple
{ {
public: public:
/** /**
The constructor accepts a @a format argument which specifies the (single) The constructor accepts a @a format argument which specifies the
format supported by this object. If it isn't set here, (single) format supported by this object. If it isn't set here,
wxDataObjectSimple::SetFormat should be used. wxDataObjectSimple::SetFormat() should be used.
*/ */
wxCustomDataObject(const wxDataFormat& format = wxFormatInvalid); wxCustomDataObject(const wxDataFormat& format = wxFormatInvalid);
/** /**
The destructor will free the data hold by the object. Notice that although it The destructor will free the data held by the object. Notice that
calls a virtual Free() function, the base although it calls the virtual Free() function, the base class version
class version will always be called (C++ doesn't allow calling virtual will always be called (C++ doesn't allow calling virtual functions from
functions from constructors or destructors), so if you override @c Free(), you constructors or destructors), so if you override Free(), you should
should override the destructor in your class as well (which would probably override the destructor in your class as well (which would probably
just call the derived class' version of @c Free()). just call the derived class' version of Free()).
*/ */
~wxCustomDataObject(); virtual ~wxCustomDataObject();
/** /**
This function is called to allocate @a size bytes of memory from SetData(). This function is called to allocate @a size bytes of memory from
The default version just uses the operator new. SetData(). The default version just uses the operator new.
*/ */
virtual void* Alloc(size_t size); virtual void* Alloc(size_t size);
/** /**
This function is called when the data is freed, you may override it to anything This function is called when the data is freed, you may override it to
you want (or may be nothing at all). The default version calls operator anything you want (or may be nothing at all). The default version calls
delete[] on the data. operator delete[] on the data.
*/ */
virtual void Free(); virtual void Free();
@@ -77,14 +75,22 @@ public:
/** /**
Set the data. The data object will make an internal copy. Set the data. The data object will make an internal copy.
@beginWxPythonOnly
This method expects a string in wxPython. You can pass nearly any
object by pickling it first.
@endWxPythonOnly
*/ */
virtual void SetData(size_t size, const void data); virtual void SetData(size_t size, const void data);
/** /**
Like SetData(), but doesn't copy the data - Like SetData(), but doesn't copy the data - instead the object takes
instead the object takes ownership of the pointer. ownership of the pointer.
@b wxPython note: This method expects a string in wxPython. You can pass
nearly any object by pickling it first. @beginWxPythonOnly
This method expects a string in wxPython. You can pass nearly any
object by pickling it first.
@endWxPythonOnly
*/ */
virtual void TakeData(size_t size, const void data); virtual void TakeData(size_t size, const void data);
}; };
@@ -95,24 +101,22 @@ public:
@class wxDataObjectComposite @class wxDataObjectComposite
@wxheader{dataobj.h} @wxheader{dataobj.h}
wxDataObjectComposite is the simplest wxDataObjectComposite is the simplest wxDataObject derivation which may be
wxDataObject derivation which may be used to support used to support multiple formats. It contains several wxDataObjectSimple
multiple formats. It contains several objects and supports any format supported by at least one of them. Only one
wxDataObjectSimple objects and supports any of these data objects is @e preferred (the first one if not explicitly
format supported by at least one of them. Only one of these data objects is changed by using the second parameter of Add()) and its format determines
@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. the preferred format of the composite data object as well.
See wxDataObject documentation for the reasons why you See wxDataObject documentation for the reasons why you might prefer to use
might prefer to use wxDataObject directly instead of wxDataObjectComposite for wxDataObject directly instead of wxDataObjectComposite for efficiency
efficiency reasons. reasons.
@library{wxcore} @library{wxcore}
@category{FIXME} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @see @ref overview_dnd, wxDataObject, wxDataObjectSimple, wxFileDataObject,
wxDataObject, wxDataObjectSimple, wxFileDataObject, wxTextDataObject, wxBitmapDataObject wxTextDataObject, wxBitmapDataObject
*/ */
class wxDataObjectComposite : public wxDataObject class wxDataObjectComposite : public wxDataObject
{ {
@@ -123,13 +127,13 @@ public:
wxDataObjectComposite(); wxDataObjectComposite();
/** /**
Adds the @a dataObject to the list of supported objects and it becomes the Adds the @a dataObject to the list of supported objects and it becomes
preferred object if @a preferred is @true. the preferred object if @a preferred is @true.
*/ */
void Add(wxDataObjectSimple dataObject, bool preferred = false); void Add(wxDataObjectSimple dataObject, bool preferred = false);
/** /**
Report the format passed to the SetData method. This should be the Report the format passed to the SetData() method. This should be the
format of the data object within the composite that recieved data from 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 the clipboard or the DnD operation. You can use this method to find
out what kind of data object was recieved. out what kind of data object was recieved.
@@ -143,60 +147,75 @@ public:
@class wxDataObjectSimple @class wxDataObjectSimple
@wxheader{dataobj.h} @wxheader{dataobj.h}
This is the simplest possible implementation of the This is the simplest possible implementation of the wxDataObject class. The
wxDataObject class. The data object of (a class derived data object of (a class derived from) this class only supports one format,
from) this class only supports one format, so the number of virtual functions so the number of virtual functions to be implemented is reduced.
to be implemented is reduced.
Notice that this is still an abstract base class and cannot be used but should Notice that this is still an abstract base class and cannot be used
be derived from. directly, it must be derived. The objects supporting rendering the data
must override GetDataSize() and GetDataHere() while the objects which may
be set must override SetData(). Of course, the objects supporting both
operations must override all three methods.
@b wxPython note: If you wish to create a derived wxDataObjectSimple class in @beginWxPythonOnly
wxPython you should derive the class from wxPyDataObjectSimple If you wish to create a derived wxDataObjectSimple class in wxPython you
in order to get Python-aware capabilities for the various virtual should derive the class from wxPyDataObjectSimple in order to get
methods. Python-aware capabilities for the various virtual methods.
@endWxPythonOnly
@b wxPerl note: In wxPerl, you need to derive your data object class @beginWxPerlOnly
from Wx::PlDataObjectSimple. In wxPerl, you need to derive your data object class from
Wx::PlDataObjectSimple.
@endWxPerlOnly
@library{wxcore} @library{wxcore}
@category{FIXME} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref @see @ref overview_dnd, @ref page_samples_dnd, wxFileDataObject,
overview_samplednd "DnD sample", wxFileDataObject, wxTextDataObject, wxBitmapDataObject wxTextDataObject, wxBitmapDataObject
*/ */
class wxDataObjectSimple : public wxDataObject class wxDataObjectSimple : public wxDataObject
{ {
public: public:
/** /**
Constructor accepts the supported format (none by default) which may also be Constructor accepts the supported format (none by default) which may
set later with SetFormat(). also be set later with SetFormat().
*/ */
wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid); wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid);
/** /**
Copy the data to the buffer, return @true on success. Must be implemented in the Copy the data to the buffer, return @true on success. Must be
derived class if the object supports rendering its data. implemented in the derived class if the object supports rendering its
data.
@beginWxPythonOnly
When implementing this method in wxPython, no additional parameters are
required and the data should be returned from the method as a string.
@endWxPythonOnly
*/ */
virtual bool GetDataHere(void buf) const; virtual bool GetDataHere(void buf) const;
/** /**
Gets the size of our data. Must be implemented in the derived class if the Gets the size of our data. Must be implemented in the derived class if
object supports rendering its data. the object supports rendering its data.
*/ */
virtual size_t GetDataSize() const; virtual size_t GetDataSize() const;
/** /**
Returns the (one and only one) format supported by this object. It is supposed Returns the (one and only one) format supported by this object. It is
that the format is supported in both directions. assumed that the format is supported in both directions.
*/ */
const wxDataFormat GetFormat() const; const wxDataFormat GetFormat() const;
/** /**
Copy the data from the buffer, return @true on success. Must be implemented in Copy the data from the buffer, return @true on success. Must be
the derived class if the object supports setting its data. implemented in the derived class if the object supports setting its
@b wxPython note: When implementing this method in wxPython, the data comes data.
as a single string parameter rather than the two shown here.
@beginWxPythonOnly
When implementing this method in wxPython, the data comes as a single
string parameter rather than the two shown here.
@endWxPythonOnly
*/ */
virtual bool SetData(size_t len, const void buf); virtual bool SetData(size_t len, const void buf);
@@ -212,45 +231,48 @@ public:
@class wxBitmapDataObject @class wxBitmapDataObject
@wxheader{dataobj.h} @wxheader{dataobj.h}
wxBitmapDataObject is a specialization of wxDataObject for bitmap data. It can wxBitmapDataObject is a specialization of wxDataObject for bitmap data. It
be used without change to paste data into the can be used without change to paste data into the wxClipboard or a
wxClipboard or a wxDropSource. A wxDropSource. A user may wish to derive a new class from this class for
user may wish to derive a new class from this class for providing a bitmap providing a bitmap on-demand in order to minimize memory consumption when
on-demand in order to minimize memory consumption when offering data in several offering data in several formats, such as a bitmap and GIF.
formats, such as a bitmap and GIF.
@b wxPython note: If you wish to create a derived wxBitmapDataObject class in This class may be used as is, but GetBitmap() may be overridden to increase
wxPython you should derive the class from wxPyBitmapDataObject efficiency.
in order to get Python-aware capabilities for the various virtual
methods. @beginWxPythonOnly
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.
@endWxPythonOnly
@library{wxcore} @library{wxcore}
@category{dnd} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @see @ref overview_dnd, wxDataObject, wxDataObjectSimple, wxFileDataObject,
wxDataObject, wxDataObjectSimple, wxFileDataObject, wxTextDataObject, wxDataObject wxTextDataObject, wxDataObject
*/ */
class wxBitmapDataObject : public wxDataObjectSimple class wxBitmapDataObject : public wxDataObjectSimple
{ {
public: public:
/** /**
Constructor, optionally passing a bitmap (otherwise use Constructor, optionally passing a bitmap (otherwise use SetBitmap()
SetBitmap() later). later).
*/ */
wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap); wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap);
/** /**
Returns the bitmap associated with the data object. You may wish to override Returns the bitmap associated with the data object. You may wish to
this method when offering data on-demand, but this is not required by override this method when offering data on-demand, but this is not
wxWidgets' internals. Use this method to get data in bitmap form from required by wxWidgets' internals. Use this method to get data in bitmap
the wxClipboard. form from the wxClipboard.
*/ */
virtual wxBitmap GetBitmap() const; virtual wxBitmap GetBitmap() const;
/** /**
Sets the bitmap associated with the data object. This method is called when the Sets the bitmap associated with the data object. This method is called
data object receives data. Usually there will be no reason to override this when the data object receives data. Usually there will be no reason to
function. override this function.
*/ */
virtual void SetBitmap(const wxBitmap& bitmap); virtual void SetBitmap(const wxBitmap& bitmap);
}; };
@@ -261,91 +283,74 @@ public:
@class wxDataFormat @class wxDataFormat
@wxheader{dataobj.h} @wxheader{dataobj.h}
A wxDataFormat is an encapsulation of a platform-specific format handle which A wxDataFormat is an encapsulation of a platform-specific format handle
is used by the system for the clipboard and drag and drop operations. The which is used by the system for the clipboard and drag and drop operations.
applications are usually only interested in, for example, pasting data from the The applications are usually only interested in, for example, pasting data
clipboard only if the data is in a format the program understands and a data from the clipboard only if the data is in a format the program understands
format is something which uniquely identifies this format. and a data format is something which uniquely identifies this format.
On the system level, a data format is usually just a number (@c CLIPFORMAT 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 under Windows or @c Atom under X11, for example) and the standard formats
are, indeed, just numbers which can be implicitly converted to wxDataFormat. are, indeed, just numbers which can be implicitly converted to wxDataFormat.
The standard formats are: The standard formats are:
@beginDefList
@itemdef{wxDF_INVALID,
An invalid format - used as default argument for functions taking
a wxDataFormat argument sometimes.}
@itemdef{wxDF_TEXT,
Text format (wxString).}
@itemdef{wxDF_BITMAP,
A bitmap (wxBitmap).}
@itemdef{wxDF_METAFILE,
A metafile (wxMetafile, Windows only).}
@itemdef{wxDF_FILENAME,
A list of filenames.}
@itemdef{wxDF_HTML,
An HTML string. This is only valid when passed to
wxSetClipboardData when compiled with Visual C++ in non-Unicode
mode.}
@endDefList
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).
wxDF_INVALID 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,
An invalid format - used as default argument for you shouldn't care about it because it is done automatically the first time
functions taking a wxDataFormat argument sometimes 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
wxDF_TEXT 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!
Text format (wxString)
wxDF_BITMAP
A bitmap (wxBitmap)
wxDF_METAFILE
A metafile (wxMetafile, Windows only)
wxDF_FILENAME
A list of filenames
wxDF_HTML
An HTML string. This is only valid when passed to wxSetClipboardData
when compiled with Visual C++ in non-Unicode mode
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).
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!
@library{wxbase} @library{wxbase}
@category{dnd} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref @see @ref overview_dnd, @ref page_samples_dnd, wxDataObject
overview_samplednd "DnD sample", wxDataObject
*/ */
class wxDataFormat class wxDataFormat
{ {
public: public:
/** /**
Constructs a data format object for a custom format identified by its name Constructs a data format object for one of the standard data formats or
@e format. an empty data object (use SetType() or SetId() later in this case).
*/
wxDataFormat(NativeFormat format = wxDF_INVALID);
/**
Constructs a data format object for a custom format identified by its
name @a format.
*/ */
wxDataFormat(const wxChar format); wxDataFormat(const wxChar format);
/** /**
Returns the name of a custom format (this function will fail for a standard Returns the name of a custom format (this function will fail for a
format). standard format).
*/ */
wxString GetId() const; wxString GetId() const;
@@ -360,7 +365,8 @@ public:
void SetId(const wxChar format); void SetId(const wxChar format);
/** /**
Sets the format to the given value, which should be one of wxDF_XXX constants. Sets the format to the given value, which should be one of wxDF_XXX
constants.
*/ */
void SetType(NativeFormat format); void SetType(NativeFormat format);
@@ -381,21 +387,22 @@ public:
@class wxURLDataObject @class wxURLDataObject
@wxheader{dataobj.h} @wxheader{dataobj.h}
wxURLDataObject is a wxDataObject containing an URL wxURLDataObject is a wxDataObject containing an URL and can be used e.g.
and can be used e.g. when you need to put an URL on or retrieve it from the when you need to put an URL on or retrieve it from the clipboard:
clipboard:
@code @code
wxTheClipboard-SetData(new wxURLDataObject(url)); wxTheClipboard->SetData(new wxURLDataObject(url));
@endcode @endcode
@note This class is derived from wxDataObjectComposite on Windows rather
than wxTextDataObject on all other platforms.
@library{wxcore} @library{wxcore}
@category{dnd} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @see @ref overview_dnd, wxDataObject
wxDataObject
*/ */
class wxURLDataObject class wxURLDataObject: public wxTextDataObject
{ {
public: public:
/** /**
@@ -421,19 +428,19 @@ public:
@class wxDataObject @class wxDataObject
@wxheader{dataobj.h} @wxheader{dataobj.h}
A wxDataObject represents data that can be copied to or from the clipboard, or A wxDataObject represents data that can be copied to or from the clipboard,
dragged and dropped. The important thing about wxDataObject is that this is a or dragged and dropped. The important thing about wxDataObject is that this
'smart' piece of data unlike 'dumb' data containers such as memory 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 buffers or files. Being 'smart' here means that the data object itself
know what data formats it supports and how to render itself in each of should know what data formats it supports and how to render itself in each
its supported formats. of its supported formats.
A supported format, incidentally, is exactly the format in which the data can A supported format, incidentally, is exactly the format in which the data
be requested from a data object or from which the data object may be set. In can be requested from a data object or from which the data object may be
the general case, an object may support different formats on 'input' and set. In the general case, an object may support different formats on
'output', i.e. it may be able to render itself in a given format but not be 'input' and 'output', i.e. it may be able to render itself in a given
created from data on this format or vice versa. wxDataObject defines an format but not be created from data on this format or vice versa.
enumeration type wxDataObject defines an enumeration type which distinguishes between them:
@code @code
enum Direction enum Direction
@@ -443,106 +450,93 @@ public:
}; };
@endcode @endcode
which distinguishes between them. See See wxDataFormat documentation for more about formats.
wxDataFormat documentation for more about formats.
Not surprisingly, being 'smart' comes at a price of added complexity. This is Not surprisingly, being 'smart' comes at a price of added complexity. This
reasonable for the situations when you really need to support multiple formats, is reasonable for the situations when you really need to support multiple
but may be annoying if you only want to do something simple like cut and paste formats, but may be annoying if you only want to do something simple like
text. cut and paste text.
To provide a solution for both cases, wxWidgets has two predefined classes To provide a solution for both cases, wxWidgets has two predefined classes
which derive from wxDataObject: wxDataObjectSimple and which derive from wxDataObject: wxDataObjectSimple and
wxDataObjectComposite. wxDataObjectComposite. wxDataObjectSimple is the simplest wxDataObject
wxDataObjectSimple is possible and only holds data in a single format (such as HTML or text) and
the simplest wxDataObject possible and only holds data in a single format (such wxDataObjectComposite is the simplest way to implement a wxDataObject that
as HTML or text) and wxDataObjectComposite is does support multiple formats because it achieves this by simply holding
the simplest way to implement a wxDataObject that does support multiple formats several wxDataObjectSimple objects.
because it achieves this by simply holding several wxDataObjectSimple objects.
So, you have several solutions when you need a wxDataObject class (and you need So, you have several solutions when you need a wxDataObject class (and you
one as soon as you want to transfer data via the clipboard or drag and drop): need one as soon as you want to transfer data via the clipboard or drag and
drop):
-# Use one of the built-in classes.
- 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.
-# Use wxDataObjectSimple
- 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).
-# Use wxDataObjectComposite
- 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).
-# Use wxDataObject Directly
- This is the solution for maximal flexibility and efficiency, but it
is also the most difficult to implement.
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.
@b 1. Use one of the built-in classes 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
You may use wxTextDataObject, the user of a program who would normally think that the data resides in the
wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need clipboard after having pressed 'Copy' - in reality it is only declared to
to support one format and your data is either text, bitmap or list of files. be available.
@b 2. Use wxDataObjectSimple
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).
@b 3. Use wxDataObjectComposite
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).
@b 4. Use wxDataObject directly
This is the solution for
maximal flexibility and efficiency, but it is also the most difficult to
implement.
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.
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.
There are several predefined data object classes derived from There are several predefined data object classes derived from
wxDataObjectSimple: wxFileDataObject, wxDataObjectSimple: wxFileDataObject, wxTextDataObject, wxBitmapDataObject
wxTextDataObject, and wxURLDataObject which can be used without change.
wxBitmapDataObject and
wxURLDataObject
which can be used without change.
You may also derive your own data object classes from You may also derive your own data object classes from wxCustomDataObject
wxCustomDataObject for user-defined types. The for user-defined types. The format of user-defined data is given as a
format of user-defined data is given as a mime-type string literal, such as mime-type string literal, such as "application/word" or "image/png". These
"application/word" or "image/png". These strings are used as they are under strings are used as they are under Unix (so far only GTK+) to identify a
Unix (so far only GTK+) to identify a format and are translated into their format and are translated into their Windows equivalent under Win32 (using
Windows equivalent under Win32 (using the OLE IDataObject for data exchange to the OLE IDataObject for data exchange to and from the clipboard and for
and from the clipboard and for drag and drop). Note that the format string drag and drop). Note that the format string translation under Windows is
translation under Windows is not yet finished. not yet finished.
@b wxPython note: At this time this class is not directly usable from wxPython. Each class derived directly from wxDataObject must override and implement
Derive a class from wxPyDataObjectSimple() all of its functions which are pure virtual in the base class. The data
instead. objects which only render their data or only set it (i.e. work in only one
direction), should return 0 from GetFormatCount().
@b wxPerl note: This class is not currently usable from wxPerl; you may @beginWxPythonOnly
use Wx::PlDataObjectSimple instead. At this time this class is not directly usable from wxPython. Derive a
class from wxPyDataObjectSimple() instead.
@endWxPythonOnly
@beginWxPerlOnly
This class is not currently usable from wxPerl; you may use
Wx::PlDataObjectSimple instead.
@endWxPerlOnly
@library{wxcore} @library{wxcore}
@category{dnd} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @ref @see @ref overview_dnd, @ref page_samples_dnd, wxFileDataObject,
overview_samplednd "DnD sample", wxFileDataObject, wxTextDataObject, wxBitmapDataObject, wxCustomDataObject, wxDropTarget, wxDropSource, wxTextDropTarget, wxFileDropTarget wxTextDataObject, wxBitmapDataObject, wxCustomDataObject,
wxDropTarget, wxDropSource, wxTextDropTarget, wxFileDropTarget
*/ */
class wxDataObject class wxDataObject
{ {
@@ -558,42 +552,45 @@ public:
~wxDataObject(); ~wxDataObject();
/** /**
Copy all supported formats in the given direction to the array pointed to by Copy all supported formats in the given direction to the array pointed
@e formats. There is enough space for GetFormatCount(dir) formats in it. to by @a formats. There is enough space for GetFormatCount(dir) formats
in it.
*/ */
virtual void GetAllFormats(wxDataFormat* formats, virtual void GetAllFormats(wxDataFormat* formats,
Direction dir = Get) const; Direction dir = Get) const;
/** /**
The method will write the data of the format @a format in the buffer @a buf and The method will write the data of the format @a format in the buffer
return @true on success, @false on failure. @a buf and return @true on success, @false on failure.
*/ */
virtual bool GetDataHere(const wxDataFormat& format, void buf) const; virtual bool GetDataHere(const wxDataFormat& format, void buf) const;
/** /**
Returns the data size of the given format @e format. Returns the data size of the given format @a format.
*/ */
virtual size_t GetDataSize(const wxDataFormat& format) const; virtual size_t GetDataSize(const wxDataFormat& format) const;
/** /**
Returns the number of available formats for rendering or setting the data. Returns the number of available formats for rendering or setting the
data.
*/ */
virtual size_t GetFormatCount(Direction dir = Get) const; virtual size_t GetFormatCount(Direction dir = Get) const;
/** /**
Returns the preferred format for either rendering the data (if @a dir is @c Get, Returns the preferred format for either rendering the data (if @a dir
its default value) or for setting it. Usually this will be the is @c Get, its default value) or for setting it. Usually this will be
native format of the wxDataObject. the native format of the wxDataObject.
*/ */
virtual wxDataFormat GetPreferredFormat(Direction dir = Get) const; virtual wxDataFormat GetPreferredFormat(Direction dir = Get) const;
/** /**
Set the data in the format @a format of the length @a len provided in the Set the data in the format @a format of the length @a len provided in
buffer @e buf. the buffer @a buf.
Returns @true on success, @false on failure.
@returns @true on success, @false on failure.
*/ */
virtual bool SetData(const wxDataFormat& format, size_t len, virtual bool SetData(const wxDataFormat& format, size_t len,
const void buf); const void buf);
}; };
@@ -602,63 +599,62 @@ public:
@class wxTextDataObject @class wxTextDataObject
@wxheader{dataobj.h} @wxheader{dataobj.h}
wxTextDataObject is a specialization of wxDataObject for text data. It can be wxTextDataObject is a specialization of wxDataObject for text data. It can
used without change to paste data into the wxClipboard be used without change to paste data into the wxClipboard or a
or a wxDropSource. A user may wish to derive a new wxDropSource. A user may wish to derive a new class from this class for
class from this class for providing text on-demand in order to minimize memory providing text on-demand in order to minimize memory consumption when
consumption when offering data in several formats, such as plain text and RTF offering data in several formats, such as plain text and RTF because by
because by default the text is stored in a string in this class, but it might default the text is stored in a string in this class, but it might as well
as well be generated when requested. For this, be generated when requested. For this, GetTextLength() and GetText() will
wxTextDataObject::GetTextLength and have to be overridden.
wxTextDataObject::GetText will have to be overridden.
Note that if you already have the text inside a string, you will not achieve Note that if you already have the text inside a string, you will not
any efficiency gain by overriding these functions because copying wxStrings is achieve any efficiency gain by overriding these functions because copying
already a very efficient operation (data is not actually copied because wxStrings is already a very efficient operation (data is not actually
wxStrings are reference counted). copied because wxStrings are reference counted).
@b wxPython note: If you wish to create a derived wxTextDataObject class in @beginWxPythonOnly
wxPython you should derive the class from wxPyTextDataObject If you wish to create a derived wxTextDataObject class in wxPython you
in order to get Python-aware capabilities for the various virtual should derive the class from wxPyTextDataObject in order to get
methods. Python-aware capabilities for the various virtual methods.
@endWxPythonOnly
@library{wxcore} @library{wxcore}
@category{dnd} @category{dnd}
@see @ref overview_wxdndoverview "Clipboard and drag and drop overview", @see @ref overview_dnd, wxDataObject, wxDataObjectSimple, wxFileDataObject,
wxDataObject, wxDataObjectSimple, wxFileDataObject, wxBitmapDataObject wxBitmapDataObject
*/ */
class wxTextDataObject : public wxDataObjectSimple class wxTextDataObject : public wxDataObjectSimple
{ {
public: public:
/** /**
Constructor, may be used to initialise the text (otherwise Constructor, may be used to initialise the text (otherwise SetText()
SetText() should be used later). should be used later).
*/ */
wxTextDataObject(const wxString& text = wxEmptyString); wxTextDataObject(const wxString& text = wxEmptyString);
/** /**
Returns the text associated with the data object. You may wish to override Returns the text associated with the data object. You may wish to
this method when offering data on-demand, but this is not required by override this method when offering data on-demand, but this is not
wxWidgets' internals. Use this method to get data in text form from required by wxWidgets' internals. Use this method to get data in text
the wxClipboard. form from the wxClipboard.
*/ */
virtual wxString GetText() const; virtual wxString GetText() const;
/** /**
Returns the data size. By default, returns the size of the text data Returns the data size. By default, returns the size of the text data
set in the constructor or using SetText(). set in the constructor or using SetText(). This can be overridden to
This can be overridden to provide text size data on-demand. It is recommended provide text size data on-demand. It is recommended to return the text
to return the text length plus 1 for a trailing zero, but this is not length plus 1 for a trailing zero, but this is not strictly required.
strictly required.
*/ */
virtual size_t GetTextLength() const; virtual size_t GetTextLength() const;
/** /**
Sets the text associated with the data object. This method is called 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 when the data object receives the data and, by default, copies the text
the member variable. If you want to process the text on the fly you may wish to into the member variable. If you want to process the text on the fly
override this function. you may wish to override this function.
*/ */
virtual void SetText(const wxString& strText); virtual void SetText(const wxString& strText);
}; };
@@ -669,24 +665,23 @@ public:
@class wxFileDataObject @class wxFileDataObject
@wxheader{dataobj.h} @wxheader{dataobj.h}
wxFileDataObject is a specialization of wxDataObject wxFileDataObject is a specialization of wxDataObject for file names. The
for file names. The program works with it just as if it were a list of absolute program works with it just as if it were a list of absolute file names, but
file internally it uses the same format as Explorer and other compatible
names, but internally it uses the same format as programs under Windows or GNOME/KDE filemanager under Unix which makes it
Explorer and other compatible programs under Windows or GNOME/KDE filemanager possible to receive files from them using this class.
under Unix which makes it possible to receive files from them using this
class.
@b Warning: Under all non-Windows platforms this class is currently @warning Under all non-Windows platforms this class is currently
"input-only", i.e. you can receive the files from another application, but "input-only", i.e. you can receive the files from another
copying (or dragging) file(s) from a wxWidgets application is not currently application, but copying (or dragging) file(s) from a wxWidgets
supported. PS: GTK2 should work as well. application is not currently supported. PS: GTK2 should work as
well.
@library{wxcore} @library{wxcore}
@category{dnd} @category{dnd}
@see wxDataObject, wxDataObjectSimple, wxTextDataObject, wxBitmapDataObject, @see wxDataObject, wxDataObjectSimple, wxTextDataObject,
wxDataObject wxBitmapDataObject, wxDataObject
*/ */
class wxFileDataObject : public wxDataObjectSimple class wxFileDataObject : public wxDataObjectSimple
{ {
@@ -697,12 +692,13 @@ public:
wxFileDataObject(); wxFileDataObject();
/** /**
@b MSW only: adds a file to the file list represented by this data object. Adds a file to the file list represented by this data object (Windows
only).
*/ */
virtual void AddFile(const wxString& file); virtual void AddFile(const wxString& file);
/** /**
Returns the array() of file names. Returns the array of file names.
*/ */
const wxArrayString GetFilenames() const; const wxArrayString GetFilenames() const;
}; };

View File

@@ -16,7 +16,7 @@
a wxVariant. a wxVariant.
@library{wxbase} @library{wxbase}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewIconText : public wxObject class wxDataViewIconText : public wxObject
{ {
@@ -60,7 +60,7 @@ public:
wxDataViewEvent - the event class for the wxDataViewCtrl notifications wxDataViewEvent - the event class for the wxDataViewCtrl notifications
@library{wxadv} @library{wxadv}
@category{FIXME} @category{events,dvc}
*/ */
class wxDataViewEvent : public wxNotifyEvent class wxDataViewEvent : public wxNotifyEvent
{ {
@@ -126,6 +126,9 @@ public:
*/ */
void SetValue(const wxVariant& value); void SetValue(const wxVariant& value);
}; };
/** /**
@class wxDataViewModel @class wxDataViewModel
@wxheader{dataview.h} @wxheader{dataview.h}
@@ -210,7 +213,7 @@ public:
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewModel : public wxObjectRefData class wxDataViewModel : public wxObjectRefData
{ {
@@ -392,7 +395,6 @@ public:
/** /**
@class wxDataViewIndexListModel @class wxDataViewIndexListModel
@wxheader{dataview.h} @wxheader{dataview.h}
@@ -409,7 +411,7 @@ public:
use a virtual control. use a virtual control.
@library{wxbase} @library{wxbase}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewIndexListModel : public wxDataViewModel class wxDataViewIndexListModel : public wxDataViewModel
{ {
@@ -526,7 +528,7 @@ public:
@see wxDataViewIndexListModel for the API. @see wxDataViewIndexListModel for the API.
@library{wxbase} @library{wxbase}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewVirtualListModel : public wxDataViewModel class wxDataViewVirtualListModel : public wxDataViewModel
{ {
@@ -539,8 +541,6 @@ public:
/** /**
@class wxDataViewItemAttr @class wxDataViewItemAttr
@wxheader{dataview.h} @wxheader{dataview.h}
@@ -554,7 +554,7 @@ public:
wxDataViewTextRendererText(). wxDataViewTextRendererText().
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewItemAttr class wxDataViewItemAttr
{ {
@@ -604,7 +604,7 @@ public:
wxDataViewModel::GetChildren. wxDataViewModel::GetChildren.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewItem class wxDataViewItem
{ {
@@ -679,8 +679,8 @@ public:
@endStyleTable @endStyleTable
@library{wxadv} @library{wxadv}
@category{ctrl} @category{ctrl,dvc}
@appearance{dataviewctrl.png} <!-- @appearance{dataviewctrl.png} -->
*/ */
class wxDataViewCtrl : public wxControl class wxDataViewCtrl : public wxControl
{ {
@@ -1003,7 +1003,7 @@ public:
information. information.
@library{wxbase} @library{wxbase}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewModelNotifier class wxDataViewModelNotifier
{ {
@@ -1134,7 +1134,7 @@ public:
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewRenderer : public wxObject class wxDataViewRenderer : public wxObject
{ {
@@ -1219,7 +1219,7 @@ public:
in-place editing if desired. in-place editing if desired.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewTextRenderer : public wxDataViewRenderer class wxDataViewTextRenderer : public wxDataViewRenderer
{ {
@@ -1246,7 +1246,7 @@ public:
operator. operator.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewIconTextRenderer : public wxDataViewRenderer class wxDataViewIconTextRenderer : public wxDataViewRenderer
{ {
@@ -1261,8 +1261,6 @@ public:
/** /**
@class wxDataViewProgressRenderer @class wxDataViewProgressRenderer
@wxheader{dataview.h} @wxheader{dataview.h}
@@ -1270,7 +1268,7 @@ public:
wxDataViewProgressRenderer wxDataViewProgressRenderer
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewProgressRenderer : public wxDataViewRenderer class wxDataViewProgressRenderer : public wxDataViewRenderer
{ {
@@ -1295,7 +1293,7 @@ public:
The renderer only support variants of type @e long. The renderer only support variants of type @e long.
@library{wxbase} @library{wxbase}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewSpinRenderer : public wxDataViewCustomRenderer class wxDataViewSpinRenderer : public wxDataViewCustomRenderer
{ {
@@ -1318,7 +1316,7 @@ public:
wxDataViewToggleRenderer wxDataViewToggleRenderer
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewToggleRenderer : public wxDataViewRenderer class wxDataViewToggleRenderer : public wxDataViewRenderer
{ {
@@ -1339,7 +1337,7 @@ public:
wxDataViewDateRenderer wxDataViewDateRenderer
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewDateRenderer : public wxDataViewRenderer class wxDataViewDateRenderer : public wxDataViewRenderer
{ {
@@ -1365,7 +1363,7 @@ public:
wxDataViewItemAttr. wxDataViewItemAttr.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewTextRendererAttr : public wxDataViewTextRenderer class wxDataViewTextRendererAttr : public wxDataViewTextRenderer
{ {
@@ -1379,6 +1377,7 @@ public:
}; };
/** /**
@class wxDataViewCustomRenderer @class wxDataViewCustomRenderer
@wxheader{dataview.h} @wxheader{dataview.h}
@@ -1400,7 +1399,7 @@ public:
in order to end the editing. in order to end the editing.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewCustomRenderer : public wxDataViewRenderer class wxDataViewCustomRenderer : public wxDataViewRenderer
{ {
@@ -1504,7 +1503,7 @@ public:
wxDataViewBitmapRenderer wxDataViewBitmapRenderer
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewBitmapRenderer : public wxDataViewRenderer class wxDataViewBitmapRenderer : public wxDataViewRenderer
{ {
@@ -1519,7 +1518,6 @@ public:
/** /**
@class wxDataViewColumn @class wxDataViewColumn
@wxheader{dataview.h} @wxheader{dataview.h}
@@ -1532,7 +1530,7 @@ public:
this class to render its data. this class to render its data.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewColumn : public wxObject class wxDataViewColumn : public wxObject
{ {
@@ -1660,8 +1658,8 @@ public:
to the wxDataViewCtrl class simpler. to the wxDataViewCtrl class simpler.
@library{wxbase} @library{wxbase}
@category{ctrl} @category{ctrl,dvc}
@appearance{dataviewtreectrl.png} <!-- @appearance{dataviewtreectrl.png} -->
*/ */
class wxDataViewTreeCtrl : public wxDataViewCtrl class wxDataViewTreeCtrl : public wxDataViewCtrl
{ {
@@ -1851,7 +1849,7 @@ public:
This comes at the price of much reduced flexibility. This comes at the price of much reduced flexibility.
@library{wxadv} @library{wxadv}
@category{FIXME} @category{dvc}
*/ */
class wxDataViewTreeStore : public wxDataViewModel class wxDataViewTreeStore : public wxDataViewModel
{ {
@@ -1982,5 +1980,3 @@ public:
void SetItemIcon(const wxDataViewItem& item, const wxIcon& icon); void SetItemIcon(const wxDataViewItem& item, const wxIcon& icon);
}; };