]>
Commit | Line | Data |
---|---|---|
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 | ||
14 | A wxDataObject represents data that can be copied to or from the clipboard, or | |
717a57c2 VZ |
15 | dragged 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 | |
17 | buffers or files. Being "smart" here means that the data object itself should | |
18 | know what data formats it supports and how to render itself in each of | |
19 | supported formats. | |
20 | ||
21 | A supported format, incidentally, is exactly the format in which the data can | |
22 | be requested from a data object or from which the data object may be set. In | |
23 | the 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 | |
25 | created from data on this format or vice versa. wxDataObject defines an | |
26 | enumeration type | |
27 | ||
28 | \begin{verbatim} | |
29 | enum Direction | |
30 | { | |
31 | Get = 0x01, // format is supported by GetDataHere() | |
32 | Set = 0x02 // format is supported by SetData() | |
33 | }; | |
34 | \end{verbatim} | |
35 | ||
36 | which allows to distinguish between them. See | |
37 | \helpref{wxDataFormat}{wxdataformat} documentation for more about formats. | |
38 | ||
39 | Not surprizingly, being "smart" comes at a price of added complexity. This is | |
40 | reasonable for the situations when you really need to support multiple formats, | |
41 | but may be annoying if you only want to do something simple like cut and paste | |
42 | text. | |
43 | ||
44 | To provide a solution for both cases, wxWindows has two predefined classes | |
45 | which derive from wxDataObject: | |
46 | \helpref{wxDataObjectSimple}{wxdataobjectsimple} and | |
47 | \helpref{wxDataObjectComposite}{wxdataobjectcomposite}. | |
48 | \helpref{wxDataObjectSimple}{wxdataobjectsimple} is | |
49 | the simplest wxDataObject possible and only holds data in a single format (such | |
50 | as HTML or text) and \helpref{wxDataObjectComposite}{wxdataobjectcomposite} is | |
51 | the simplest way to implement wxDataObject which does support multiple formats | |
52 | because it achievs this by simply holding several wxDataObjectSimple objects. | |
53 | ||
54 | So, you have several solutions when you need a wxDataObject class (and you need | |
55 | one 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, | |
59 | wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need | |
60 | to 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 | |
62 | solution for custom data - you will only support one format and so probably | |
63 | won't be able to communicate with other programs, but data transfer will work | |
64 | in your program (or between different copies of it).} | |
65 | \twocolitem{2. Use wxDataObjectComposite}{This is a quite simple, but rather | |
66 | powerful solution which allows you to support any number of formats (either | |
67 | standard or custom if you combine it with the previous solution).} | |
68 | \twocolitem{3. Derive from wxDataObject directly}{This is the solution of | |
69 | maximal flexibility and efficiency, but it also is the most difficult to | |
70 | implement.} | |
71 | \end{twocollist} | |
72 | ||
73 | Please note that the easiest way to use Drag'n'Drop and the clipboard with | |
74 | multiple formats is by using wxDataObjectComposite, but it is not the most | |
75 | efficient one as each wxDataObjectSimple would contain the whole data in its | |
76 | respective formars. Now imagine that you want to paste 200 pages of text in | |
77 | your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to | |
78 | the clipboard and even today's computers are in trouble. For this case, you | |
79 | will have to derive from wxDataObject directly and make it enumerate its | |
80 | formats and provide the data in the requested format on demand. | |
81 | ||
82 | Note that neither the GTK data transfer mechanisms for the clipboard and | |
83 | Drag'n'Drop nor the OLE data transfer copies any data until another application | |
84 | actually requests the data. This is in contrast to the "feel" offered to the | |
85 | user of a program who would normally think that the data resides in the | |
86 | clipboard after having pressed "Copy" - in reality it is only declared to be | |
87 | available. | |
88 | ||
89 | There are several predefined data object classes derived from | |
90 | wxDataObjectSimple: \helpref{wxFileDataObject}{wxfiledataobject}, | |
91 | \helpref{wxTextDataObject}{wxtextdataobject} and | |
92 | \helpref{wxBitmapDataObject}{wxbitmapdataobject} which can be used without | |
93 | change. | |
94 | ||
95 | You may also derive your own data object classes from | |
96 | \helpref{wxCustomDataObject}{wxprivatedataobject} for user-defined types. The | |
97 | format 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 | |
99 | Unix (so far only GTK) to identify a format and are translated into their | |
100 | Windows equivalent under Win32 (using the OLE IDataObject for data exchange to | |
101 | and from the clipboard and for Drag'n'Drop). Note that the format string | |
102 | translation under Windows is not yet finnished. | |
103 | ||
104 | \wxheading{Virtual functions to override} | |
105 | ||
106 | Each class derived directly from wxDataObject must override and implement all | |
107 | of its functions which are pure virtual in the base class. | |
108 | ||
109 | The data objects which only render their data or only set it (i.e. work in | |
110 | only one direction), should return 0 from | |
111 | \helpref{GetFormatCount}{wxdataobjectgetformatcount}. | |
f37615d7 | 112 | |
dface61c JS |
113 | \wxheading{Derived from} |
114 | ||
717a57c2 | 115 | None |
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 | ||
140 | Constructor. | |
141 | ||
142 | \membersection{wxDataObject::\destruct{wxDataObject}}\label{wxdataobjectdtor} | |
143 | ||
144 | \func{}{\destruct{wxDataObject}}{\void} | |
145 | ||
146 | Destructor. | |
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 |
154 | Copy 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 |
161 | The method will write the data of the format {\it format} in the buffer {\it |
162 | buf} 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 | ||
168 | Returns 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 | ||
174 | Return 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 |
180 | Returns 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 | |
182 | native 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 | ||
191 | Set the data in the format {\it format} of the length {\it len} provided in the | |
192 | buffer {\it buf}. | |
dface61c | 193 | |
717a57c2 | 194 | Returns TRUE on sucess, FALSE on failure. |
dface61c | 195 | |
dface61c | 196 |