]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dnd.h
type corrections, adding support for listctrl editable columns
[wxWidgets.git] / include / wx / dnd.h
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) wxWidgets Team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DND_H_BASE_
13 #define _WX_DND_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DRAG_AND_DROP
18
19 #include "wx/dataobj.h"
20 #include "wx/cursor.h"
21
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25
26 // flags for wxDropSource::DoDragDrop()
27 //
28 // NB: wxDrag_CopyOnly must be 0 (== FALSE) and wxDrag_AllowMove must be 1
29 // (== TRUE) for compatibility with the old DoDragDrop(bool) method!
30 enum
31 {
32 wxDrag_CopyOnly = 0, // allow only copying
33 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
34 wxDrag_DefaultMove = 3 // the default operation is move, not copy
35 };
36
37 // result of wxDropSource::DoDragDrop() call
38 enum wxDragResult
39 {
40 wxDragError, // error prevented the d&d operation from completing
41 wxDragNone, // drag target didn't accept the data
42 wxDragCopy, // the data was successfully copied
43 wxDragMove, // the data was successfully moved (MSW only)
44 wxDragLink, // operation is a drag-link
45 wxDragCancel // the operation was cancelled by user (not an error)
46 };
47
48 inline WXDLLEXPORT bool wxIsDragResultOk(wxDragResult res)
49 {
50 return res == wxDragCopy || res == wxDragMove || res == wxDragLink;
51 }
52
53 // ----------------------------------------------------------------------------
54 // wxDropSource is the object you need to create (and call DoDragDrop on it)
55 // to initiate a drag-and-drop operation
56 // ----------------------------------------------------------------------------
57
58 class WXDLLEXPORT wxDropSourceBase
59 {
60 public:
61 wxDropSourceBase(const wxCursor &cursorCopy = wxNullCursor,
62 const wxCursor &cursorMove = wxNullCursor,
63 const wxCursor &cursorStop = wxNullCursor)
64 : m_cursorCopy(cursorCopy),
65 m_cursorMove(cursorMove),
66 m_cursorStop(cursorStop)
67 { m_data = (wxDataObject *)NULL; }
68 virtual ~wxDropSourceBase() { }
69
70 // set the data which is transfered by drag and drop
71 void SetData(wxDataObject& data)
72 { m_data = &data; }
73
74 wxDataObject *GetDataObject()
75 { return m_data; }
76
77 // set the icon corresponding to given drag result
78 void SetCursor(wxDragResult res, const wxCursor& cursor)
79 {
80 if ( res == wxDragCopy )
81 m_cursorCopy = cursor;
82 else if ( res == wxDragMove )
83 m_cursorMove = cursor;
84 else
85 m_cursorStop = cursor;
86 }
87
88 // start drag action, see enum wxDragResult for return value description
89 //
90 // if flags contains wxDrag_AllowMove, moving (and only copying) data is
91 // allowed, if it contains wxDrag_DefaultMove (which includes the previous
92 // flag), it is even the default operation
93 virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly) = 0;
94
95 // override to give feedback depending on the current operation result
96 // "effect" and return true if you did something, false to let the library
97 // give the default feedback
98 virtual bool GiveFeedback(wxDragResult WXUNUSED(effect)) { return false; }
99
100 protected:
101 const wxCursor& GetCursor(wxDragResult res) const
102 {
103 if ( res == wxDragCopy )
104 return m_cursorCopy;
105 else if ( res == wxDragMove )
106 return m_cursorMove;
107 else
108 return m_cursorStop;
109 }
110
111 // the data we're dragging
112 wxDataObject *m_data;
113
114 // the cursors to use for feedback
115 wxCursor m_cursorCopy,
116 m_cursorMove,
117 m_cursorStop;
118
119 DECLARE_NO_COPY_CLASS(wxDropSourceBase)
120 };
121
122 // ----------------------------------------------------------------------------
123 // wxDropTarget should be associated with a window if it wants to be able to
124 // receive data via drag and drop.
125 //
126 // To use this class, you should derive from wxDropTarget and implement
127 // OnData() pure virtual method. You may also wish to override OnDrop() if you
128 // want to accept the data only inside some region of the window (this may
129 // avoid having to copy the data to this application which happens only when
130 // OnData() is called)
131 // ----------------------------------------------------------------------------
132
133 class WXDLLEXPORT wxDropTargetBase
134 {
135 public:
136 // ctor takes a pointer to heap-allocated wxDataObject which will be owned
137 // by wxDropTarget and deleted by it automatically. If you don't give it
138 // here, you can use SetDataObject() later.
139 wxDropTargetBase(wxDataObject *dataObject = (wxDataObject*)NULL)
140 { m_dataObject = dataObject; m_defaultAction = wxDragNone; }
141 // dtor deletes our data object
142 virtual ~wxDropTargetBase()
143 { delete m_dataObject; }
144
145 // get/set the associated wxDataObject
146 wxDataObject *GetDataObject() const
147 { return m_dataObject; }
148 void SetDataObject(wxDataObject *dataObject)
149 { if (m_dataObject) delete m_dataObject;
150 m_dataObject = dataObject; }
151
152 // these functions are called when data is moved over position (x, y) and
153 // may return either wxDragCopy, wxDragMove or wxDragNone depending on
154 // what would happen if the data were dropped here.
155 //
156 // the last parameter is what would happen by default and is determined by
157 // the platform-specific logic (for example, under Windows it's wxDragCopy
158 // if Ctrl key is pressed and wxDragMove otherwise) except that it will
159 // always be wxDragNone if the carried data is in an unsupported format.
160
161 // called when the mouse enters the window (only once until OnLeave())
162 virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def)
163 { return OnDragOver(x, y, def); }
164
165 // called when the mouse moves in the window - shouldn't take long to
166 // execute or otherwise mouse movement would be too slow
167 virtual wxDragResult OnDragOver(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
168 wxDragResult def)
169 { return def; }
170
171 // called when mouse leaves the window: might be used to remove the
172 // feedback which was given in OnEnter()
173 virtual void OnLeave() { }
174
175 // this function is called when data is dropped at position (x, y) - if it
176 // returns true, OnData() will be called immediately afterwards which will
177 // allow to retrieve the data dropped.
178 virtual bool OnDrop(wxCoord x, wxCoord y) = 0;
179
180 // called after OnDrop() returns TRUE: you will usually just call
181 // GetData() from here and, probably, also refresh something to update the
182 // new data and, finally, return the code indicating how did the operation
183 // complete (returning default value in case of success and wxDragError on
184 // failure is usually ok)
185 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) = 0;
186
187 // may be called *only* from inside OnData() and will fill m_dataObject
188 // with the data from the drop source if it returns true
189 virtual bool GetData() = 0;
190
191 // sets the default action for drag and drop:
192 // use wxDragMove or wxDragCopy to set deafult action to move or copy
193 // and use wxDragNone (default) to set default action specified by
194 // initialization of draging (see wxDropSourceBase::DoDragDrop())
195 void SetDefaultAction(wxDragResult action)
196 { m_defaultAction = action; }
197
198 // returns default action for drag and drop or
199 // wxDragNone if this not specified
200 wxDragResult GetDefaultAction()
201 { return m_defaultAction; }
202
203 protected:
204 wxDataObject *m_dataObject;
205 wxDragResult m_defaultAction;
206
207 DECLARE_NO_COPY_CLASS(wxDropTargetBase)
208 };
209
210 // ----------------------------------------------------------------------------
211 // include platform dependent class declarations
212 // ----------------------------------------------------------------------------
213
214 #if defined(__WXMSW__)
215 #include "wx/msw/ole/dropsrc.h"
216 #include "wx/msw/ole/droptgt.h"
217 #elif defined(__WXMOTIF__)
218 #include "wx/motif/dnd.h"
219 #elif defined(__WXX11__)
220 #include "wx/x11/dnd.h"
221 #elif defined(__WXGTK20__)
222 #include "wx/gtk/dnd.h"
223 #elif defined(__WXGTK__)
224 #include "wx/gtk1/dnd.h"
225 #elif defined(__WXMAC__)
226 #include "wx/mac/dnd.h"
227 #elif defined(__WXPM__)
228 #include "wx/os2/dnd.h"
229 #endif
230
231 // ----------------------------------------------------------------------------
232 // standard wxDropTarget implementations (implemented in common/dobjcmn.cpp)
233 // ----------------------------------------------------------------------------
234
235 // A simple wxDropTarget derived class for text data: you only need to
236 // override OnDropText() to get something working
237 class WXDLLEXPORT wxTextDropTarget : public wxDropTarget
238 {
239 public:
240 wxTextDropTarget();
241
242 virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
243
244 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
245
246 private:
247 DECLARE_NO_COPY_CLASS(wxTextDropTarget)
248 };
249
250 // A drop target which accepts files (dragged from File Manager or Explorer)
251 class WXDLLEXPORT wxFileDropTarget : public wxDropTarget
252 {
253 public:
254 wxFileDropTarget();
255
256 // parameters are the number of files and the array of file names
257 virtual bool OnDropFiles(wxCoord x, wxCoord y,
258 const wxArrayString& filenames) = 0;
259
260 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
261
262 private:
263 DECLARE_NO_COPY_CLASS(wxFileDropTarget)
264 };
265
266 #endif // wxUSE_DRAG_AND_DROP
267
268 #endif // _WX_DND_H_BASE_