]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dataobj.tex
don't assign the returned value in wxMDIParentFrame::OnCreateClient() to any member...
[wxWidgets.git] / docs / latex / wx / dataobj.tex
CommitLineData
717a57c2
VZ
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: dataobj.tex
3%% Purpose: wxDataObject documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 18.10.99
7%% RCS-ID: $Id$
fc2171bd 8%% Copyright: (c) wxWidgets team
8795498c 9%% License: wxWindows license
717a57c2
VZ
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
dface61c
JS
12\section{\class{wxDataObject}}\label{wxdataobject}
13
14A wxDataObject represents data that can be copied to or from the clipboard, or
717a57c2 15dragged and dropped. The important thing about wxDataObject is that this is a
f6bb64a6 16'smart' piece of data unlike 'dumb' data containers such as memory
407f3681 17buffers or files. Being 'smart' here means that the data object itself should
717a57c2 18know what data formats it supports and how to render itself in each of
f6bb64a6 19its supported formats.
717a57c2
VZ
20
21A supported format, incidentally, is exactly the format in which the data can
22be requested from a data object or from which the data object may be set. In
407f3681
JS
23the general case, an object may support different formats on 'input' and
24'output', i.e. it may be able to render itself in a given format but not be
717a57c2
VZ
25created from data on this format or vice versa. wxDataObject defines an
26enumeration type
27
28\begin{verbatim}
29enum Direction
30{
31 Get = 0x01, // format is supported by GetDataHere()
32 Set = 0x02 // format is supported by SetData()
33};
34\end{verbatim}
35
f6bb64a6 36which distinguishes between them. See
717a57c2
VZ
37\helpref{wxDataFormat}{wxdataformat} documentation for more about formats.
38
2edb0bde 39Not surprisingly, being 'smart' comes at a price of added complexity. This is
717a57c2
VZ
40reasonable for the situations when you really need to support multiple formats,
41but may be annoying if you only want to do something simple like cut and paste
42text.
43
fc2171bd 44To provide a solution for both cases, wxWidgets has two predefined classes
fa482912
JS
45which derive from wxDataObject: \helpref{wxDataObjectSimple}{wxdataobjectsimple} and
46\helpref{wxDataObjectComposite}{wxdataobjectcomposite}.
717a57c2
VZ
47\helpref{wxDataObjectSimple}{wxdataobjectsimple} is
48the simplest wxDataObject possible and only holds data in a single format (such
49as HTML or text) and \helpref{wxDataObjectComposite}{wxdataobjectcomposite} is
3980000c 50the simplest way to implement a wxDataObject that does support multiple formats
f6bb64a6 51because it achieves this by simply holding several wxDataObjectSimple objects.
717a57c2
VZ
52
53So, you have several solutions when you need a wxDataObject class (and you need
54one as soon as you want to transfer data via the clipboard or drag and drop):
55
c03648c2 56\begin{twocollist}\itemsep=1cm
fa482912 57\twocolitem{{\bf 1. Use one of the built-in classes}}{You may use wxTextDataObject,
717a57c2 58wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need
407f3681 59to support one format and your data is either text, bitmap or list of files.}
fa482912 60\twocolitem{{\bf 2. Use wxDataObjectSimple}}{Deriving from wxDataObjectSimple is the simplest
717a57c2
VZ
61solution for custom data - you will only support one format and so probably
62won't be able to communicate with other programs, but data transfer will work
63in your program (or between different copies of it).}
fa482912 64\twocolitem{{\bf 3. Use wxDataObjectComposite}}{This is a simple but powerful
407f3681 65solution which allows you to support any number of formats (either
717a57c2 66standard or custom if you combine it with the previous solution).}
fa482912 67\twocolitem{{\bf 4. Use wxDataObject directly}}{This is the solution for
f6bb64a6 68maximal flexibility and efficiency, but it is also the most difficult to
717a57c2
VZ
69implement.}
70\end{twocollist}
71
407f3681 72Please note that the easiest way to use drag and drop and the clipboard with
717a57c2
VZ
73multiple formats is by using wxDataObjectComposite, but it is not the most
74efficient one as each wxDataObjectSimple would contain the whole data in its
f59d80ca 75respective formats. Now imagine that you want to paste 200 pages of text in
717a57c2
VZ
76your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to
77the clipboard and even today's computers are in trouble. For this case, you
78will have to derive from wxDataObject directly and make it enumerate its
79formats and provide the data in the requested format on demand.
80
f6bb64a6
JS
81Note that neither the GTK+ data transfer mechanisms for clipboard and
82drag and drop, nor OLE data transfer, copy any data until another application
407f3681 83actually requests the data. This is in contrast to the 'feel' offered to the
717a57c2 84user of a program who would normally think that the data resides in the
407f3681 85clipboard after having pressed 'Copy' - in reality it is only declared to be
717a57c2
VZ
86available.
87
88There are several predefined data object classes derived from
fa482912 89wxDataObjectSimple: \helpref{wxFileDataObject}{wxfiledataobject},
c12bf406
RR
90\helpref{wxTextDataObject}{wxtextdataobject},
91\helpref{wxBitmapDataObject}{wxbitmapdataobject} and
92\helpref{wxURLDataObject}{wxurldataobject}
93which can be used without change.
717a57c2 94
fa482912 95You may also derive your own data object classes from
0a2017e0 96\helpref{wxCustomDataObject}{wxcustomdataobject} for user-defined types. The
f6bb64a6 97format of user-defined data is given as a mime-type string literal, such as
717a57c2 98"application/word" or "image/png". These strings are used as they are under
f6bb64a6 99Unix (so far only GTK+) to identify a format and are translated into their
717a57c2 100Windows equivalent under Win32 (using the OLE IDataObject for data exchange to
407f3681
JS
101and from the clipboard and for drag and drop). Note that the format string
102translation under Windows is not yet finished.
717a57c2 103
874a1686 104\pythonnote{At this time this class is not directly usable from wxPython.
fa482912 105Derive a class from \helpref{wxPyDataObjectSimple}{wxdataobjectsimple}
b1462dfa
RD
106instead.}
107
d3f3e857
MB
108\perlnote{This class is not currently usable from wxPerl; you may
109use \helpref{Wx::PlDataObjectSimple}{wxdataobjectsimple} instead.}
110
717a57c2
VZ
111\wxheading{Virtual functions to override}
112
113Each class derived directly from wxDataObject must override and implement all
114of its functions which are pure virtual in the base class.
115
116The data objects which only render their data or only set it (i.e. work in
fa482912 117only one direction), should return 0 from
717a57c2 118\helpref{GetFormatCount}{wxdataobjectgetformatcount}.
f37615d7 119
dface61c
JS
120\wxheading{Derived from}
121
717a57c2 122None
dface61c 123
954b8ae6
JS
124\wxheading{Include files}
125
126<wx/dataobj.h>
127
a7af285d
VZ
128\wxheading{Library}
129
130\helpref{wxCore}{librarieslist}
131
dface61c
JS
132\wxheading{See also}
133
fa482912
JS
134\helpref{Clipboard and drag and drop overview}{wxdndoverview},
135\helpref{DnD sample}{samplednd},
136\helpref{wxFileDataObject}{wxfiledataobject},
137\helpref{wxTextDataObject}{wxtextdataobject},
138\helpref{wxBitmapDataObject}{wxbitmapdataobject},
139\helpref{wxCustomDataObject}{wxcustomdataobject},
140\helpref{wxDropTarget}{wxdroptarget},
141\helpref{wxDropSource}{wxdropsource},
142\helpref{wxTextDropTarget}{wxtextdroptarget},
717a57c2 143\helpref{wxFileDropTarget}{wxfiledroptarget}
dface61c
JS
144
145\latexignore{\rtfignore{\wxheading{Members}}}
146
147\membersection{wxDataObject::wxDataObject}\label{wxdataobjectwxdataobject}
148
149\func{}{wxDataObject}{\void}
150
151Constructor.
152
153\membersection{wxDataObject::\destruct{wxDataObject}}\label{wxdataobjectdtor}
154
155\func{}{\destruct{wxDataObject}}{\void}
156
157Destructor.
158
717a57c2 159\membersection{wxDataObject::GetAllFormats}\label{wxdataobjectgetallformats}
fc9c7c09 160
407f3681 161\constfunc{virtual void}{GetAllFormats}{ \param{wxDataFormat *}{formats}, \param{Direction}{ dir = Get}}
fc9c7c09 162
fa482912 163Copy all supported formats in the given direction to the array pointed to by
407f3681 164{\it formats}. There is enough space for GetFormatCount(dir) formats in it.
fc9c7c09 165
0a67eeac
MB
166\perlnote{In wxPerl this method only takes the {\tt dir} parameter.
167In scalar context it returns the first format,
168in list context it returns a list containing all the supported formats.}
169
fc9c7c09
RR
170\membersection{wxDataObject::GetDataHere}\label{wxdataobjectgetdatahere}
171
717a57c2 172\constfunc{virtual bool}{GetDataHere}{\param{const wxDataFormat\&}{ format}, \param{void }{*buf} }
fc9c7c09 173
717a57c2 174The method will write the data of the format {\it format} in the buffer {\it
cc81d32f 175buf} and return true on success, false on failure.
fc9c7c09
RR
176
177\membersection{wxDataObject::GetDataSize}\label{wxdataobjectgetdatasize}
178
179\constfunc{virtual size\_t}{GetDataSize}{\param{const wxDataFormat\&}{ format} }
180
181Returns the data size of the given format {\it format}.
182
717a57c2
VZ
183\membersection{wxDataObject::GetFormatCount}\label{wxdataobjectgetformatcount}
184
185\constfunc{virtual size\_t}{GetFormatCount}{\param{Direction}{ dir = Get}}
186
407f3681 187Returns the number of available formats for rendering or setting the data.
717a57c2 188
fc9c7c09 189\membersection{wxDataObject::GetPreferredFormat}\label{wxdataobjectgetpreferredformat}
f37615d7 190
717a57c2 191\constfunc{virtual wxDataFormat}{GetPreferredFormat}{\param{Direction}{ dir = Get}}
f37615d7 192
407f3681
JS
193Returns the preferred format for either rendering the data (if {\it dir} is {\tt Get},
194its default value) or for setting it. Usually this will be the
717a57c2 195native format of the wxDataObject.
f37615d7 196
fc9c7c09 197\membersection{wxDataObject::SetData}\label{wxdataobjectsetdata}
f37615d7 198
407f3681 199\func{virtual bool}{SetData}{ \param{const wxDataFormat\&}{ format}, \param{size\_t}{ len}, \param{const void }{*buf} }
717a57c2
VZ
200
201Set the data in the format {\it format} of the length {\it len} provided in the
202buffer {\it buf}.
dface61c 203
cc81d32f 204Returns true on success, false on failure.
dface61c 205