]>
Commit | Line | Data |
---|---|---|
15b6757b | 1 | ///////////////////////////////////////////////////////////////////////////// |
d54cf7ff | 2 | // Name: dataobject.h |
15b6757b FM |
3 | // Purpose: topic overview |
4 | // Author: wxWidgets team | |
526954c5 | 5 | // Licence: wxWindows licence |
15b6757b FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
880efa2a | 8 | /** |
36c9828f | 9 | |
dc28cdf8 | 10 | @page overview_dataobject wxDataObject Overview |
36c9828f | 11 | |
ce154616 | 12 | @tableofcontents |
d54cf7ff | 13 | |
ce154616 BP |
14 | This overview discusses data transfer through clipboard or drag and drop. In |
15 | wxWidgets, these two ways to transfer data (either between different | |
dc28cdf8 | 16 | applications or inside one and the same) are very similar which allows to |
ce154616 BP |
17 | implement both of them using almost the same code - or, in other words, if you |
18 | implement drag and drop support for your application, you get clipboard support | |
19 | for free and vice versa. | |
d54cf7ff | 20 | |
dc28cdf8 | 21 | At the heart of both clipboard and drag and drop operations lies the |
ce154616 BP |
22 | wxDataObject class. The objects of this class (or, to be precise, classes |
23 | derived from it) represent the data which is being carried by the mouse during | |
24 | drag and drop operation or copied to or pasted from the clipboard. wxDataObject | |
25 | is a "smart" piece of data because it knows which formats it supports (see | |
26 | GetFormatCount and GetAllFormats) and knows how to render itself in any of them | |
27 | (see GetDataHere). It can also receive its value from the outside in a format | |
28 | it supports if it implements the SetData method. Please see the documentation | |
29 | of this class for more details. | |
d54cf7ff | 30 | |
dc28cdf8 FM |
31 | Both clipboard and drag and drop operations have two sides: the source and |
32 | target, the data provider and the data receiver. These which may be in the same | |
33 | application and even the same window when, for example, you drag some text from | |
34 | one position to another in a word processor. Let us describe what each of them | |
35 | should do. | |
d54cf7ff | 36 | |
ce154616 | 37 | @see @ref overview_dnd, @ref group_class_dnd, @ref page_samples_dnd |
98ba1eee | 38 | |
36c9828f FM |
39 | |
40 | ||
ce154616 | 41 | @section overview_dataobject_source The Data Provider (Source) |
d54cf7ff | 42 | |
dc28cdf8 FM |
43 | The data provider is responsible for creating a wxDataObject containing the |
44 | data to be transferred. Then it should either pass it to the clipboard using | |
ce154616 BP |
45 | wxClipboard::SetData function or to wxDropSource and call |
46 | wxDropSource::DoDragDrop function. | |
36c9828f | 47 | |
dc28cdf8 | 48 | The only (but important) difference is that the object for the clipboard |
ce154616 BP |
49 | transfer must always be created on the heap (i.e. using @c new) and it will be |
50 | freed by the clipboard when it is no longer needed (indeed, it is not known in | |
51 | advance when, if ever, the data will be pasted from the clipboard). On the | |
dc28cdf8 FM |
52 | other hand, the object for drag and drop operation must only exist while |
53 | wxDropSource::DoDragDrop executes and may be safely deleted afterwards and so | |
54 | can be created either on heap or on stack (i.e. as a local variable). | |
d54cf7ff | 55 | |
dc28cdf8 FM |
56 | Another small difference is that in the case of clipboard operation, the |
57 | application usually knows in advance whether it copies or cuts (i.e. copies and | |
58 | deletes) data - in fact, this usually depends on which menu item the user | |
ce154616 BP |
59 | chose. But for drag and drop it can only know it after wxDropSource::DoDragDrop |
60 | returns (from its return value). | |
36c9828f | 61 | |
d54cf7ff | 62 | |
ce154616 BP |
63 | |
64 | @section overview_dataobject_target The Data Receiver (Target) | |
36c9828f | 65 | |
dc28cdf8 FM |
66 | To receive (paste in usual terminology) data from the clipboard, you should |
67 | create a wxDataObject derived class which supports the data formats you need | |
68 | and pass it as argument to wxClipboard::GetData. If it returns @false, | |
69 | no data in (any of) the supported format(s) is available. If it returns @true, | |
70 | the data has been successfully transferred to wxDataObject. | |
d54cf7ff | 71 | |
ce154616 BP |
72 | For drag and drop case, the wxDropTarget::OnData virtual function will be |
73 | called when a data object is dropped, from which the data itself may be | |
74 | requested by calling wxDropTarget::GetData method which fills the data object. | |
36c9828f | 75 | |
d54cf7ff | 76 | */ |