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