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