]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/dataobj.tex
SetTitle method (internal use only) changed to virtual OnSetTitle, added GetOpenedPag...
[wxWidgets.git] / docs / latex / wx / dataobj.tex
... / ...
CommitLineData
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
12\section{\class{wxDataObject}}\label{wxdataobject}
13
14A wxDataObject represents data that can be copied to or from the clipboard, or
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: \helpref{wxDataObjectSimple}{wxdataobjectsimple} and
46\helpref{wxDataObjectComposite}{wxdataobjectcomposite}.
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
50the simplest way to implement wxDataObject which does support multiple formats
51because it achievs this by simply holding several wxDataObjectSimple objects.
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
56\begin{twocollist}\itemsep=1cm
57\twocolitem{{\bf 0. Use one of built-in classes}}{You may use wxTextDataObject,
58wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need
59to support one format and your data is either text, bitmap or list of files.}
60\twocolitem{{\bf 1. Use wxDataObjectSimple}}{Deriving from wxDataObjectSimple is the simplest
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).}
64\twocolitem{{\bf 2. Use wxDataObjectComposite}}{This is a simple but powerful
65solution which allows you to support any number of formats (either
66standard or custom if you combine it with the previous solution).}
67\twocolitem{{\bf 3. Use wxDataObject directly}}{This is the solution for
68maximal flexibility and efficiency, but it also is the most difficult to
69implement.}
70\end{twocollist}
71
72Please note that the easiest way to use drag and drop and the clipboard with
73multiple formats is by using wxDataObjectComposite, but it is not the most
74efficient one as each wxDataObjectSimple would contain the whole data in its
75respective formars. Now imagine that you want to paste 200 pages of text in
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
81Note that neither the GTK data transfer mechanisms for the clipboard and
82drag and drop, neither does the OLE data transfer copy any data until another application
83actually requests the data. This is in contrast to the 'feel' offered to the
84user of a program who would normally think that the data resides in the
85clipboard after having pressed 'Copy' - in reality it is only declared to be
86available.
87
88There are several predefined data object classes derived from
89wxDataObjectSimple: \helpref{wxFileDataObject}{wxfiledataobject},
90\helpref{wxTextDataObject}{wxtextdataobject} and
91\helpref{wxBitmapDataObject}{wxbitmapdataobject} which can be used without
92change.
93
94You may also derive your own data object classes from
95\helpref{wxCustomDataObject}{wxcustomdataobject} for user-defined types. The
96format of user-defined data is given as mime-type string literal, such as
97"application/word" or "image/png". These strings are used as they are under
98Unix (so far only GTK) to identify a format and are translated into their
99Windows equivalent under Win32 (using the OLE IDataObject for data exchange to
100and from the clipboard and for drag and drop). Note that the format string
101translation under Windows is not yet finished.
102
103\pythonnote{At this time this class is directly usable from wxPython.
104Derive a class from \helpref{wxPyDataObjectSimple}{wxdataobjectsimple}
105instead.}
106
107\wxheading{Virtual functions to override}
108
109Each class derived directly from wxDataObject must override and implement all
110of its functions which are pure virtual in the base class.
111
112The data objects which only render their data or only set it (i.e. work in
113only one direction), should return 0 from
114\helpref{GetFormatCount}{wxdataobjectgetformatcount}.
115
116\wxheading{Derived from}
117
118None
119
120\wxheading{Include files}
121
122<wx/dataobj.h>
123
124\wxheading{See also}
125
126\helpref{Clipboard and drag and drop overview}{wxdndoverview},
127\helpref{DnD sample}{samplednd},
128\helpref{wxFileDataObject}{wxfiledataobject},
129\helpref{wxTextDataObject}{wxtextdataobject},
130\helpref{wxBitmapDataObject}{wxbitmapdataobject},
131\helpref{wxCustomDataObject}{wxcustomdataobject},
132\helpref{wxDropTarget}{wxdroptarget},
133\helpref{wxDropSource}{wxdropsource},
134\helpref{wxTextDropTarget}{wxtextdroptarget},
135\helpref{wxFileDropTarget}{wxfiledroptarget}
136
137\latexignore{\rtfignore{\wxheading{Members}}}
138
139\membersection{wxDataObject::wxDataObject}\label{wxdataobjectwxdataobject}
140
141\func{}{wxDataObject}{\void}
142
143Constructor.
144
145\membersection{wxDataObject::\destruct{wxDataObject}}\label{wxdataobjectdtor}
146
147\func{}{\destruct{wxDataObject}}{\void}
148
149Destructor.
150
151\membersection{wxDataObject::GetAllFormats}\label{wxdataobjectgetallformats}
152
153\constfunc{virtual void}{GetAllFormats}{ \param{wxDataFormat *}{formats}, \param{Direction}{ dir = Get}}
154
155Copy all supported formats in the given direction to the array pointed to by
156{\it formats}. There is enough space for GetFormatCount(dir) formats in it.
157
158\membersection{wxDataObject::GetDataHere}\label{wxdataobjectgetdatahere}
159
160\constfunc{virtual bool}{GetDataHere}{\param{const wxDataFormat\&}{ format}, \param{void }{*buf} }
161
162The method will write the data of the format {\it format} in the buffer {\it
163buf} and return TRUE on success, FALSE on failure.
164
165\membersection{wxDataObject::GetDataSize}\label{wxdataobjectgetdatasize}
166
167\constfunc{virtual size\_t}{GetDataSize}{\param{const wxDataFormat\&}{ format} }
168
169Returns the data size of the given format {\it format}.
170
171\membersection{wxDataObject::GetFormatCount}\label{wxdataobjectgetformatcount}
172
173\constfunc{virtual size\_t}{GetFormatCount}{\param{Direction}{ dir = Get}}
174
175Returns the number of available formats for rendering or setting the data.
176
177\membersection{wxDataObject::GetPreferredFormat}\label{wxdataobjectgetpreferredformat}
178
179\constfunc{virtual wxDataFormat}{GetPreferredFormat}{\param{Direction}{ dir = Get}}
180
181Returns the preferred format for either rendering the data (if {\it dir} is {\tt Get},
182its default value) or for setting it. Usually this will be the
183native format of the wxDataObject.
184
185\membersection{wxDataObject::SetData}\label{wxdataobjectsetdata}
186
187\func{virtual bool}{SetData}{ \param{const wxDataFormat\&}{ format}, \param{size\_t}{ len}, \param{const void }{*buf} }
188
189Set the data in the format {\it format} of the length {\it len} provided in the
190buffer {\it buf}.
191
192Returns TRUE on success, FALSE on failure.
193