]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tdnd.tex
wxImage changes
[wxWidgets.git] / docs / latex / wx / tdnd.tex
CommitLineData
c18ecb11
VZ
1\section{Drag-and-drop and clipboard overview}\label{wxdndoverview}
2
b1327f57 3Classes: \helpref{wxDataObject}{wxdataobject}
c18ecb11 4
b1327f57
JS
5% \helpref{wxTextDataObject}{wxtextdataobject}
6% \helpref{wxDropSource}{wxdropsource}
c18ecb11
VZ
7% \helpref{wxDropTarget}{wxdroptarget}
8% \helpref{wxTextDropTarget}{wxtextdroptarget}
9% \helpref{wxFileDropTarget}{wxfiledroptarget}
10
11Samples: see the dnd sample.
12
13This overview describes wxWindows support for drag and drop and clipboard
14operations. Both of these topics are discussed here because, in fact, they're
15quite related. Drag and drop and clipboard are just too ways of passing the
16data around and so the code required to implement both types of the operations
17is almost the same.
18
b1327f57
JS
19In any case, you work with some data which is represented by
20the \helpref{wxDataObject}{wxdataobject} class. It is capable to contain any kind
21data in one of any of predefined formats (see enum \helpref{StdFormatand}{stdformat}) and is smart enough to describe the format
c18ecb11 22of data it contains. There is also a specialization of this class which stores
b1327f57 23only text - the only difference between \helpref{wxTextDataObject}{wxtextdataobject} and wxDataObject is that the
c18ecb11
VZ
24first one is easily constructed from wxString.
25
26Also, for both kinds of operations, there is a sender which provides data and
27a receiver who gets it. The sender is responsible for constructing the
28wxDataObject and the receiver can query it and process the data it contains
29in any way he likes.
30
31In the case of a drag and drop operation, the sender is called a {\it drop
32source} while the receiver is a {\it dtop target}. There are several steps in
33the dragging process:
b1327f57 34
c18ecb11 35\begin{itemize}\itemsep=0pt
b1327f57 36\item {\bf preparation} First of all, the data object must be created and
c18ecb11 37initilized with the data you wish to drag. For example:
b1327f57 38
c18ecb11
VZ
39\begin{verbatim}
40 wxTextDataObject data("This string will be dragged.");
41\end{verbatim}. Of course, the data object may contain arbitrary data of any
42type.
b1327f57
JS
43
44\item{drag start} This happens when you call \helpref{DoDragDrop}{wxdropsourcedodragdrop} function. For this you must first
c18ecb11
VZ
45construct a wxDropSource object and associate the data object from the
46previous step with it like this:
b1327f57 47
c18ecb11
VZ
48\begin{verbatim}
49 wxDropSource dragSource(data, this);
50
51 // or also:
52 wxDropSource dragSource(this);
53 dragSource.SetData(data);
54\end{verbatim},
b1327f57
JS
55
56\item {\bf dragging} The call to DoDragDrop() blocks until the user release the
57mouse button (unless you override \helpref{GiveFeedback}{wxdropsourcegivefeedback} function to do something
c18ecb11
VZ
58special). When the mouse moves in a window of a wxWindows program, the
59corresponding wxDropTarget methods are called (the data can be also dragged to
60any other program under Windows or to any program supporting the same protocol
61under X Windows).
b1327f57
JS
62\item {\bf drop} When the user releases the mouse over a window, wxWindows verifies
63if the wxDropTarget object associated (with \helpref{SetDropTarget}{setdroptarget}) with this window accepts the data. For
64this, \helpref{GetFormatCount}{wxdroptargetgetformatcount} and \helpref{GetFormat}{wxdroptargetgetformat} are used and if the format is
65supported (i.e. is one of returned by GetFormat()), then \helpref{OnDrop}{wxdroptargetondrop} is called. Otherwise, wxDragNone is
c18ecb11 66returned by DoDragDrop() and nothing happens.
b1327f57
JS
67\item {\bf the end} Finally, the receiver processes the data (e.g. pastes the text
68in its window). DoDragDrop() returns either wxDragCopy or wxDragMove
c18ecb11
VZ
69depending on the state of the keys (<Ctrl>, <Shift> and <Alt>) at the moment
70of drop.
71\end{itemize}
72