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