]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dataobj.tex
wxMenu implementations
[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$
8%% Copyright: (c) wxWindows team
9%% Licence: wxWindows licence
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
VZ
15dragged and dropped. The important thing about wxDataObject is that this is a
16"smart" piece of data unlike usual "dumb" data containers such as memory
17buffers or files. Being "smart" here means that the data object itself should
18know what data formats it supports and how to render itself in each of
19supported formats.
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
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
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
36which allows to distinguish between them. See
37\helpref{wxDataFormat}{wxdataformat} documentation for more about formats.
38
39Not surprizingly, being "smart" comes at a price of added complexity. This is
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
44To provide a solution for both cases, wxWindows has two predefined classes
45which derive from wxDataObject:
46\helpref{wxDataObjectSimple}{wxdataobjectsimple} and
47\helpref{wxDataObjectComposite}{wxdataobjectcomposite}.
48\helpref{wxDataObjectSimple}{wxdataobjectsimple} is
49the simplest wxDataObject possible and only holds data in a single format (such
50as HTML or text) and \helpref{wxDataObjectComposite}{wxdataobjectcomposite} is
51the simplest way to implement wxDataObject which does support multiple formats
52because it achievs this by simply holding several wxDataObjectSimple objects.
53
54So, you have several solutions when you need a wxDataObject class (and you need
55one as soon as you want to transfer data via the clipboard or drag and drop):
56
57\begin{twocollist}
58\twocolitem{0. Use one of built-in classes}{You may use wxTextDataObject,
59wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need
60to support one format and your data is either text, bitmap or list of files}
61\twocolitem{1. Derive your class from wxDataObjectSimple}{This is the simplest
62solution for custom data - you will only support one format and so probably
63won't be able to communicate with other programs, but data transfer will work
64in your program (or between different copies of it).}
65\twocolitem{2. Use wxDataObjectComposite}{This is a quite simple, but rather
66powerful solution which allows you to support any number of formats (either
67standard or custom if you combine it with the previous solution).}
68\twocolitem{3. Derive from wxDataObject directly}{This is the solution of
69maximal flexibility and efficiency, but it also is the most difficult to
70implement.}
71\end{twocollist}
72
73Please note that the easiest way to use Drag'n'Drop and the clipboard with
74multiple formats is by using wxDataObjectComposite, but it is not the most
75efficient one as each wxDataObjectSimple would contain the whole data in its
76respective formars. Now imagine that you want to paste 200 pages of text in
77your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to
78the clipboard and even today's computers are in trouble. For this case, you
79will have to derive from wxDataObject directly and make it enumerate its
80formats and provide the data in the requested format on demand.
81
82Note that neither the GTK data transfer mechanisms for the clipboard and
83Drag'n'Drop nor the OLE data transfer copies any data until another application
84actually requests the data. This is in contrast to the "feel" offered to the
85user of a program who would normally think that the data resides in the
86clipboard after having pressed "Copy" - in reality it is only declared to be
87available.
88
89There are several predefined data object classes derived from
90wxDataObjectSimple: \helpref{wxFileDataObject}{wxfiledataobject},
91\helpref{wxTextDataObject}{wxtextdataobject} and
92\helpref{wxBitmapDataObject}{wxbitmapdataobject} which can be used without
93change.
94
95You may also derive your own data object classes from
96\helpref{wxCustomDataObject}{wxprivatedataobject} for user-defined types. The
97format of user-defined data is given as mime-type string literal, such as
98"application/word" or "image/png". These strings are used as they are under
99Unix (so far only GTK) to identify a format and are translated into their
100Windows equivalent under Win32 (using the OLE IDataObject for data exchange to
101and from the clipboard and for Drag'n'Drop). Note that the format string
102translation under Windows is not yet finnished.
103
104\wxheading{Virtual functions to override}
105
106Each class derived directly from wxDataObject must override and implement all
107of its functions which are pure virtual in the base class.
108
109The data objects which only render their data or only set it (i.e. work in
110only one direction), should return 0 from
111\helpref{GetFormatCount}{wxdataobjectgetformatcount}.
f37615d7 112
dface61c
JS
113\wxheading{Derived from}
114
717a57c2 115None
dface61c 116
954b8ae6
JS
117\wxheading{Include files}
118
119<wx/dataobj.h>
120
dface61c
JS
121\wxheading{See also}
122
717a57c2
VZ
123\helpref{Clipboard and drag and drop overview}{wxclipboardonfigoverview},
124\helpref{DnD sample}{samplednd},
dface61c
JS
125\helpref{wxFileDataObject}{wxfiledataobject},
126\helpref{wxTextDataObject}{wxtextdataobject},
127\helpref{wxBitmapDataObject}{wxbitmapdataobject},
f37615d7 128\helpref{wxPrivateDataObject}{wxprivatedataobject},
717a57c2 129\helpref{wxDropTarget}{wxdroptarget},
dface61c 130\helpref{wxDropSource}{wxdropsource},
717a57c2
VZ
131\helpref{wxTextDropTarget}{wxtextdroptarget},
132\helpref{wxFileDropTarget}{wxfiledroptarget}
dface61c
JS
133
134\latexignore{\rtfignore{\wxheading{Members}}}
135
136\membersection{wxDataObject::wxDataObject}\label{wxdataobjectwxdataobject}
137
138\func{}{wxDataObject}{\void}
139
140Constructor.
141
142\membersection{wxDataObject::\destruct{wxDataObject}}\label{wxdataobjectdtor}
143
144\func{}{\destruct{wxDataObject}}{\void}
145
146Destructor.
147
717a57c2 148\membersection{wxDataObject::GetAllFormats}\label{wxdataobjectgetallformats}
fc9c7c09 149
717a57c2
VZ
150\constfunc{virtual void}{GetAllFormats}{
151 \param{wxDataFormat *}{formats},
152 \param{Direction}{ dir = Get}}
fc9c7c09 153
717a57c2
VZ
154Copy all supported formats in the given direction to the array pointed to by
155{\it formats} (there is enough place for GetFormatCount(dir) formats in it).
fc9c7c09
RR
156
157\membersection{wxDataObject::GetDataHere}\label{wxdataobjectgetdatahere}
158
717a57c2 159\constfunc{virtual bool}{GetDataHere}{\param{const wxDataFormat\&}{ format}, \param{void }{*buf} }
fc9c7c09 160
717a57c2
VZ
161The method will write the data of the format {\it format} in the buffer {\it
162buf} and return TRUE on success, FALSE on failure.
fc9c7c09
RR
163
164\membersection{wxDataObject::GetDataSize}\label{wxdataobjectgetdatasize}
165
166\constfunc{virtual size\_t}{GetDataSize}{\param{const wxDataFormat\&}{ format} }
167
168Returns the data size of the given format {\it format}.
169
717a57c2
VZ
170\membersection{wxDataObject::GetFormatCount}\label{wxdataobjectgetformatcount}
171
172\constfunc{virtual size\_t}{GetFormatCount}{\param{Direction}{ dir = Get}}
173
174Return the number of available formats for rendering or setting the data.
175
fc9c7c09 176\membersection{wxDataObject::GetPreferredFormat}\label{wxdataobjectgetpreferredformat}
f37615d7 177
717a57c2 178\constfunc{virtual wxDataFormat}{GetPreferredFormat}{\param{Direction}{ dir = Get}}
f37615d7 179
717a57c2
VZ
180Returns the preferred format for either rendering the data (if {\it dir} is
181{\tt Get}, its default value) or for setting it. Usually this will be the
182native format of the wxDataObject.
f37615d7 183
fc9c7c09 184\membersection{wxDataObject::SetData}\label{wxdataobjectsetdata}
f37615d7 185
717a57c2
VZ
186\func{virtual bool}{SetData}{
187 \param{const wxDataFormat\&}{ format},
188 \param{size\_t}{ len},
189 \param{const void }{*buf} }
190
191Set the data in the format {\it format} of the length {\it len} provided in the
192buffer {\it buf}.
dface61c 193
717a57c2 194Returns TRUE on sucess, FALSE on failure.
dface61c 195
dface61c 196