File: dataobj.tex

package info (click to toggle)
wxwidgets2.8 2.8.10.1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 239,052 kB
  • ctags: 289,550
  • sloc: cpp: 1,838,857; xml: 396,717; python: 282,506; ansic: 126,171; makefile: 51,406; sh: 14,581; asm: 299; sql: 258; lex: 194; perl: 139; yacc: 128; pascal: 95; php: 39; lisp: 38; tcl: 24; haskell: 20; java: 18; cs: 18; erlang: 17; ruby: 16; ada: 9; ml: 9; csh: 9
file content (200 lines) | stat: -rw-r--r-- 8,801 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Name:        dataobj.tex
%% Purpose:     wxDataObject documentation
%% Author:      Vadim Zeitlin
%% Modified by:
%% Created:     18.10.99
%% RCS-ID:      $Id: dataobj.tex 32309 2005-02-22 15:09:56Z ABX $
%% Copyright:   (c) wxWidgets team
%% License:     wxWindows license
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{\class{wxDataObject}}\label{wxdataobject}

A wxDataObject represents data that can be copied to or from the clipboard, or
dragged and dropped. The important thing about wxDataObject is that this is a
'smart' piece of data unlike 'dumb' data containers such as memory
buffers or files. Being 'smart' here means that the data object itself should
know what data formats it supports and how to render itself in each of
its supported formats.

A supported format, incidentally, is exactly the format in which the data can
be requested from a data object or from which the data object may be set. In
the general case, an object may support different formats on 'input' and
'output', i.e. it may be able to render itself in a given format but not be
created from data on this format or vice versa. wxDataObject defines an
enumeration type

\begin{verbatim}
enum Direction
{
    Get  = 0x01,    // format is supported by GetDataHere()
    Set  = 0x02     // format is supported by SetData()
};
\end{verbatim}

which distinguishes between them. See 
\helpref{wxDataFormat}{wxdataformat} documentation for more about formats.

Not surprisingly, being 'smart' comes at a price of added complexity. This is
reasonable for the situations when you really need to support multiple formats,
but may be annoying if you only want to do something simple like cut and paste
text.

To provide a solution for both cases, wxWidgets has two predefined classes
which derive from wxDataObject: \helpref{wxDataObjectSimple}{wxdataobjectsimple} and 
\helpref{wxDataObjectComposite}{wxdataobjectcomposite}. 
\helpref{wxDataObjectSimple}{wxdataobjectsimple} is
the simplest wxDataObject possible and only holds data in a single format (such
as HTML or text) and \helpref{wxDataObjectComposite}{wxdataobjectcomposite} is
the simplest way to implement a wxDataObject that does support multiple formats
because it achieves this by simply holding several wxDataObjectSimple objects.

So, you have several solutions when you need a wxDataObject class (and you need
one as soon as you want to transfer data via the clipboard or drag and drop):

\begin{twocollist}\itemsep=1cm
\twocolitem{{\bf 1. Use one of the built-in classes}}{You may use wxTextDataObject,
wxBitmapDataObject or wxFileDataObject in the simplest cases when you only need
to support one format and your data is either text, bitmap or list of files.}
\twocolitem{{\bf 2. Use wxDataObjectSimple}}{Deriving from wxDataObjectSimple is the simplest
solution for custom data - you will only support one format and so probably
won't be able to communicate with other programs, but data transfer will work
in your program (or between different copies of it).}
\twocolitem{{\bf 3. Use wxDataObjectComposite}}{This is a simple but powerful
solution which allows you to support any number of formats (either
standard or custom if you combine it with the previous solution).}
\twocolitem{{\bf 4. Use wxDataObject directly}}{This is the solution for
maximal flexibility and efficiency, but it is also the most difficult to
implement.}
\end{twocollist}

Please note that the easiest way to use drag and drop and the clipboard with
multiple formats is by using wxDataObjectComposite, but it is not the most
efficient one as each wxDataObjectSimple would contain the whole data in its
respective formats. Now imagine that you want to paste 200 pages of text in
your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to
the clipboard and even today's computers are in trouble. For this case, you
will have to derive from wxDataObject directly and make it enumerate its
formats and provide the data in the requested format on demand.

Note that neither the GTK+ data transfer mechanisms for clipboard and
drag and drop, nor OLE data transfer, copy any data until another application
actually requests the data. This is in contrast to the 'feel' offered to the
user of a program who would normally think that the data resides in the
clipboard after having pressed 'Copy' - in reality it is only declared to be
available.

There are several predefined data object classes derived from
wxDataObjectSimple: \helpref{wxFileDataObject}{wxfiledataobject}, 
\helpref{wxTextDataObject}{wxtextdataobject} and 
\helpref{wxBitmapDataObject}{wxbitmapdataobject} which can be used without
change.

You may also derive your own data object classes from 
\helpref{wxCustomDataObject}{wxcustomdataobject} for user-defined types. The
format of user-defined data is given as a mime-type string literal, such as
"application/word" or "image/png". These strings are used as they are under
Unix (so far only GTK+) to identify a format and are translated into their
Windows equivalent under Win32 (using the OLE IDataObject for data exchange to
and from the clipboard and for drag and drop). Note that the format string
translation under Windows is not yet finished.

\pythonnote{At this time this class is not directly usable from wxPython.
Derive a class from \helpref{wxPyDataObjectSimple}{wxdataobjectsimple} 
instead.}

\perlnote{This class is not currently usable from wxPerl; you may
use \helpref{Wx::PlDataObjectSimple}{wxdataobjectsimple} instead.}

\wxheading{Virtual functions to override}

Each class derived directly from wxDataObject must override and implement all
of its functions which are pure virtual in the base class.

The data objects which only render their data or only set it (i.e. work in
only one direction), should return 0 from 
\helpref{GetFormatCount}{wxdataobjectgetformatcount}.

\wxheading{Derived from}

None

\wxheading{Include files}

<wx/dataobj.h>

\wxheading{See also}

\helpref{Clipboard and drag and drop overview}{wxdndoverview}, 
\helpref{DnD sample}{samplednd}, 
\helpref{wxFileDataObject}{wxfiledataobject}, 
\helpref{wxTextDataObject}{wxtextdataobject}, 
\helpref{wxBitmapDataObject}{wxbitmapdataobject}, 
\helpref{wxCustomDataObject}{wxcustomdataobject}, 
\helpref{wxDropTarget}{wxdroptarget}, 
\helpref{wxDropSource}{wxdropsource}, 
\helpref{wxTextDropTarget}{wxtextdroptarget}, 
\helpref{wxFileDropTarget}{wxfiledroptarget}

\latexignore{\rtfignore{\wxheading{Members}}}

\membersection{wxDataObject::wxDataObject}\label{wxdataobjectwxdataobject}

\func{}{wxDataObject}{\void}

Constructor.

\membersection{wxDataObject::\destruct{wxDataObject}}\label{wxdataobjectdtor}

\func{}{\destruct{wxDataObject}}{\void}

Destructor.

\membersection{wxDataObject::GetAllFormats}\label{wxdataobjectgetallformats}

\constfunc{virtual void}{GetAllFormats}{ \param{wxDataFormat *}{formats}, \param{Direction}{ dir = Get}}

Copy all supported formats in the given direction to the array pointed to by 
{\it formats}. There is enough space for GetFormatCount(dir) formats in it.

\perlnote{In wxPerl this method only takes the {\tt dir} parameter. 
In scalar context it returns the first format,
in list context it returns a list containing all the supported formats.}

\membersection{wxDataObject::GetDataHere}\label{wxdataobjectgetdatahere}

\constfunc{virtual bool}{GetDataHere}{\param{const wxDataFormat\&}{ format}, \param{void }{*buf} }

The method will write the data of the format {\it format} in the buffer {\it
buf} and return true on success, false on failure.

\membersection{wxDataObject::GetDataSize}\label{wxdataobjectgetdatasize}

\constfunc{virtual size\_t}{GetDataSize}{\param{const wxDataFormat\&}{ format} }

Returns the data size of the given format {\it format}.

\membersection{wxDataObject::GetFormatCount}\label{wxdataobjectgetformatcount}

\constfunc{virtual size\_t}{GetFormatCount}{\param{Direction}{ dir = Get}}

Returns the number of available formats for rendering or setting the data.

\membersection{wxDataObject::GetPreferredFormat}\label{wxdataobjectgetpreferredformat}

\constfunc{virtual wxDataFormat}{GetPreferredFormat}{\param{Direction}{ dir = Get}}

Returns the preferred format for either rendering the data (if {\it dir} is {\tt Get},
its default value) or for setting it. Usually this will be the
native format of the wxDataObject.

\membersection{wxDataObject::SetData}\label{wxdataobjectsetdata}

\func{virtual bool}{SetData}{ \param{const wxDataFormat\&}{ format}, \param{size\_t}{ len}, \param{const void }{*buf} }

Set the data in the format {\it format} of the length {\it len} provided in the
buffer {\it buf}.

Returns true on success, false on failure.