]>
Commit | Line | Data |
---|---|---|
c18ecb11 VZ |
1 | \section{Drag-and-drop and clipboard overview}\label{wxdndoverview} |
2 | ||
b1327f57 | 3 | Classes: \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 | ||
11 | Samples: see the dnd sample. | |
12 | ||
13 | This overview describes wxWindows support for drag and drop and clipboard | |
14 | operations. Both of these topics are discussed here because, in fact, they're | |
15 | quite related. Drag and drop and clipboard are just too ways of passing the | |
16 | data around and so the code required to implement both types of the operations | |
17 | is almost the same. | |
18 | ||
b1327f57 JS |
19 | In any case, you work with some data which is represented by |
20 | the \helpref{wxDataObject}{wxdataobject} class. It is capable to contain any kind | |
21 | data in one of any of predefined formats (see enum \helpref{StdFormatand}{stdformat}) and is smart enough to describe the format | |
c18ecb11 | 22 | of data it contains. There is also a specialization of this class which stores |
b1327f57 | 23 | only text - the only difference between \helpref{wxTextDataObject}{wxtextdataobject} and wxDataObject is that the |
c18ecb11 VZ |
24 | first one is easily constructed from wxString. |
25 | ||
26 | Also, for both kinds of operations, there is a sender which provides data and | |
27 | a receiver who gets it. The sender is responsible for constructing the | |
28 | wxDataObject and the receiver can query it and process the data it contains | |
29 | in any way he likes. | |
30 | ||
31 | In the case of a drag and drop operation, the sender is called a {\it drop | |
32 | source} while the receiver is a {\it dtop target}. There are several steps in | |
33 | the 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 | 37 | initilized 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 | |
42 | type. | |
b1327f57 JS |
43 | |
44 | \item{drag start} This happens when you call \helpref{DoDragDrop}{wxdropsourcedodragdrop} function. For this you must first | |
c18ecb11 VZ |
45 | construct a wxDropSource object and associate the data object from the |
46 | previous 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 | |
57 | mouse button (unless you override \helpref{GiveFeedback}{wxdropsourcegivefeedback} function to do something | |
c18ecb11 VZ |
58 | special). When the mouse moves in a window of a wxWindows program, the |
59 | corresponding wxDropTarget methods are called (the data can be also dragged to | |
60 | any other program under Windows or to any program supporting the same protocol | |
61 | under X Windows). | |
b1327f57 JS |
62 | \item {\bf drop} When the user releases the mouse over a window, wxWindows verifies |
63 | if the wxDropTarget object associated (with \helpref{SetDropTarget}{setdroptarget}) with this window accepts the data. For | |
64 | this, \helpref{GetFormatCount}{wxdroptargetgetformatcount} and \helpref{GetFormat}{wxdroptargetgetformat} are used and if the format is | |
65 | supported (i.e. is one of returned by GetFormat()), then \helpref{OnDrop}{wxdroptargetondrop} is called. Otherwise, wxDragNone is | |
c18ecb11 | 66 | returned by DoDragDrop() and nothing happens. |
b1327f57 JS |
67 | \item {\bf the end} Finally, the receiver processes the data (e.g. pastes the text |
68 | in its window). DoDragDrop() returns either wxDragCopy or wxDragMove | |
c18ecb11 VZ |
69 | depending on the state of the keys (<Ctrl>, <Shift> and <Alt>) at the moment |
70 | of drop. | |
71 | \end{itemize} | |
72 |