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