]>
Commit | Line | Data |
---|---|---|
e1ee679c VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/dnd.h | |
3 | // Purpose: Drag and drop classes declarations | |
4 | // Author: Vadim Zeitlin, Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 26.05.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWindows Team | |
9 | // Licence: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_DND_H_BASE_ |
13 | #define _WX_DND_H_BASE_ | |
c801d85f | 14 | |
e1ee679c VZ |
15 | #include "wx/defs.h" |
16 | ||
17 | #if wxUSE_DRAG_AND_DROP | |
18 | ||
3f480da3 | 19 | #include "wx/dataobj.h" |
e1ee679c VZ |
20 | |
21 | // ---------------------------------------------------------------------------- | |
22 | // constants | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | // result of wxDropSource::DoDragDrop() call | |
26 | enum wxDragResult | |
27 | { | |
28 | wxDragError, // error prevented the d&d operation from completing | |
29 | wxDragNone, // drag target didn't accept the data | |
30 | wxDragCopy, // the data was successfully copied | |
31 | wxDragMove, // the data was successfully moved (MSW only) | |
32 | wxDragCancel // the operation was cancelled by user (not an error) | |
33 | }; | |
34 | ||
35 | // ---------------------------------------------------------------------------- | |
36 | // wxDropSource is the object you need to create (and call DoDragDrop on it) | |
37 | // to initiate a drag-and-drop operation | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | class WXDLLEXPORT wxDropSourceBase | |
41 | { | |
42 | public: | |
43 | wxDropSourceBase() { m_data = (wxDataObject *)NULL; } | |
44 | virtual ~wxDropSourceBase() { } | |
45 | ||
46 | // set the data which is transfered by drag and drop | |
b068c4e8 | 47 | void SetData(wxDataObject& data) |
97c79de2 RR |
48 | { m_data = &data; } |
49 | ||
50 | wxDataObject *GetDataObject() | |
51 | { return m_data; } | |
e1ee679c VZ |
52 | |
53 | // start drag action, see enum wxDragResult for return value description | |
54 | // | |
55 | // if bAllowMove is TRUE, data can be moved, if not - only copied | |
9e2896e5 | 56 | virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE) = 0; |
e1ee679c VZ |
57 | |
58 | // override to give feedback depending on the current operation result | |
59 | // "effect" | |
60 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), | |
61 | bool WXUNUSED(bScrolling) ) | |
62 | { | |
63 | return TRUE; | |
64 | } | |
65 | ||
66 | protected: | |
67 | wxDataObject *m_data; | |
68 | }; | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // wxDropTarget should be associated with a window if it wants to be able to | |
9e2896e5 VZ |
72 | // receive data via drag and drop. |
73 | // | |
74 | // To use this class, you should derive from wxDropTarget and implement | |
75 | // OnData() pure virtual method. You may also wish to override OnDrop() if you | |
76 | // want to accept the data only inside some region of the window (this may | |
77 | // avoid having to copy the data to this application which happens only when | |
78 | // OnData() is called) | |
e1ee679c VZ |
79 | // ---------------------------------------------------------------------------- |
80 | ||
81 | class WXDLLEXPORT wxDropTargetBase | |
82 | { | |
83 | public: | |
84 | // ctor takes a pointer to heap-allocated wxDataObject which will be owned | |
85 | // by wxDropTarget and deleted by it automatically. If you don't give it | |
86 | // here, you can use SetDataObject() later. | |
b068c4e8 | 87 | wxDropTargetBase(wxDataObject *dataObject = (wxDataObject*)NULL) |
e1ee679c VZ |
88 | { m_dataObject = dataObject; } |
89 | // dtor deletes our data object | |
90 | virtual ~wxDropTargetBase() | |
91 | { delete m_dataObject; } | |
92 | ||
93 | // get/set the associated wxDataObject | |
94 | wxDataObject *GetDataObject() const | |
95 | { return m_dataObject; } | |
96 | void SetDataObject(wxDataObject *dataObject) | |
b068c4e8 RR |
97 | { if (m_dataObject) delete m_dataObject; |
98 | m_dataObject = dataObject; } | |
e1ee679c VZ |
99 | |
100 | // called when mouse enters/leaves the window: might be used to give | |
101 | // some visual feedback to the user | |
e1ee679c | 102 | virtual void OnLeave() { } |
b068c4e8 RR |
103 | |
104 | // this function is called when data enters over position (x, y) - if it | |
105 | // returns TRUE, the dragging icon can indicate that the window would | |
106 | // accept a drop here | |
107 | virtual bool OnEnter(wxCoord x, wxCoord y) = 0; | |
108 | ||
109 | // this function is called when data is move over position (x, y) - if it | |
110 | // returns TRUE, the dragging icon can indicate that the window would | |
111 | // accept a drop here | |
112 | virtual bool OnMove(wxCoord x, wxCoord y) = 0; | |
113 | ||
e1ee679c VZ |
114 | // this function is called when data is dropped at position (x, y) - if it |
115 | // returns TRUE, OnData() will be called immediately afterwards which will | |
116 | // allow to retrieve the data dropped. | |
117 | virtual bool OnDrop(wxCoord x, wxCoord y) = 0; | |
118 | ||
119 | // called after OnDrop() returns TRUE: you will usually just call | |
120 | // GetData() from here and, probably, also refresh something to update the | |
121 | // new data | |
9e2896e5 | 122 | virtual bool OnData(wxCoord x, wxCoord y) = 0; |
e1ee679c VZ |
123 | |
124 | // may be called *only* from inside OnData() and will fill m_dataObject | |
125 | // with the data from the drop source if it returns TRUE | |
126 | virtual bool GetData() = 0; | |
127 | ||
128 | protected: | |
129 | wxDataObject *m_dataObject; | |
130 | }; | |
131 | ||
9e2896e5 VZ |
132 | // ---------------------------------------------------------------------------- |
133 | // the platform-specific headers also define standard wxDropTarget | |
134 | // implementations wxTextDropTarget and wxFileDropTarget | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
e1ee679c VZ |
137 | // ---------------------------------------------------------------------------- |
138 | // include platform dependent class declarations | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
141 | #if defined(__WXMSW__) | |
e1ee679c VZ |
142 | #include "wx/msw/ole/dropsrc.h" |
143 | #include "wx/msw/ole/droptgt.h" | |
2049ba38 | 144 | #elif defined(__WXMOTIF__) |
e1ee679c | 145 | #include "wx/motif/dnd.h" |
2049ba38 | 146 | #elif defined(__WXGTK__) |
e1ee679c | 147 | #include "wx/gtk/dnd.h" |
b4e76e0d | 148 | #elif defined(__WXQT__) |
e1ee679c | 149 | #include "wx/qt/dnd.h" |
34138703 | 150 | #elif defined(__WXMAC__) |
e1ee679c | 151 | #include "wx/mac/dnd.h" |
1777b9bb | 152 | #elif defined(__WXPM__) |
e1ee679c | 153 | #include "wx/os2/dnd.h" |
34138703 | 154 | #elif defined(__WXSTUBS__) |
e1ee679c | 155 | #include "wx/stubs/dnd.h" |
c801d85f KB |
156 | #endif |
157 | ||
e1ee679c VZ |
158 | #endif // wxUSE_DRAG_AND_DROP |
159 | ||
160 | #endif // _WX_DND_H_BASE_ |