]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tclipbrd.tex
GUI thread update and event corrections.
[wxWidgets.git] / docs / latex / wx / tclipbrd.tex
CommitLineData
23efdd02 1\section{wxDataObject overview}\label{wxdataobjectoverview}
23d277e6
VZ
2
3Classes: \helpref{wxDataObject}{wxdataobject},
88b1927c
JS
4 \helpref{wxClipboard}{wxclipboard},
5 \helpref{wxDataFormat}{wxdataformat},
6 \helpref{wxDropSource}{wxdropsource},
7 \helpref{wxDropTarget}{wxdroptarget}
23d277e6
VZ
8
9This overview discusses data transfer through clipboard or drag and drop. In
10wxWindows, these two ways to transfer data (either between different
11applications or inside one and the same) are very similar which allows to
717a57c2 12implement both of them using almost the same code - or, in other
23d277e6
VZ
13words, if you implement drag and drop support for your application, you get
14clipboard support for free and vice versa.
15
407f3681 16At the heart of both clipboard and drag and drop operations lies the
717a57c2
VZ
17\helpref{wxDataObject}{wxdataobject} class. The objects of this class (or, to
18be precise, classes derived from it) represent the data which is being carried
19by the mouse during drag and drop operation or copied to or pasted from the
20clipboard. wxDataObject is a "smart" piece of data because it knows which
21formats it supports (see GetFormatCount and GetAllFormats) and knows how to
22render itself in any of them (see GetDataHere). It can also receive its value
23from the outside in a format it supports if it implements the SetData method.
24Please see the documentation of this class for more details.
23d277e6
VZ
25
26Both clipboard and drag and drop operations have two sides: the source and
88b1927c 27target, the data provider and the data receiver. These which may be in the same
23d277e6 28application and even the same window when, for example, you drag some text from
88b1927c 29one position to another in a word processor. Let us describe what each of them
23d277e6
VZ
30should do.
31
407f3681 32\subsection{The data provider (source) duties}\label{wxdataobjectsource}
23d277e6
VZ
33
34The data provider is responsible for creating a
717a57c2
VZ
35\helpref{wxDataObject}{wxdataobject} containing the data to be
36transfered. Then it should either pass it to the clipboard using
37\helpref{SetData}{wxclipboardsetdata} function or to
38\helpref{wxDropSource}{wxdropsource} and call
23d277e6
VZ
39\helpref{DoDragDrop}{wxdropsourcedodragdrop} function.
40
41The only (but important) difference is that the object for the clipboard
42transfer must always be created on the heap (i.e. using {\tt new}) and it will
43be freed by the clipboard when it is no longer needed (indeed, it is not known
44in advance when, if ever, the data will be pasted from the clipboard). On the
45other hand, the object for drag and drop operation must only exist while
46\helpref{DoDragDrop}{wxdropsourcedodragdrop} executes and may be safely deleted
47afterwards and so can be created either on heap or on stack (i.e. as a local
48variable).
49
88b1927c 50Another small difference is that in the case of clipboard operation, the
23d277e6
VZ
51application usually knows in advance whether it copies or cuts (i.e. copies and
52deletes) data - in fact, this usually depends on which menu item the user
53chose. But for drag and drop it can only know it after
54\helpref{DoDragDrop}{wxdropsourcedodragdrop} returns (from its return value).
55
407f3681 56\subsection{The data receiver (target) duties}\label{wxdataobjecttarget}
23d277e6
VZ
57
58To receive (paste in usual terminology) data from the clipboard, you should
59create a \helpref{wxDataObject}{wxdataobject} derived class which supports the
60data formats you need and pass it as argument to
61\helpref{wxClipboard::GetData}{wxclipboardgetdata}. If it returns {\tt FALSE},
62no data in (any of) the supported format(s) is available. If it returns {\tt
63TRUE}, the data has been successfully transfered to wxDataObject.
64
717a57c2
VZ
65For drag and drop case, the \helpref{wxDropTarget::OnData}{wxdroptargetondata}
66virtual function will be called when a data object is dropped, from which the
67data itself may be requested by calling
68\helpref{wxDropTarget::GetData}{wxdroptargetwxdroptarget} method which fills
69the data object.
70