]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dnd.h
disable dialup manager for MGL, it doesn't link as there is no DOS implementation...
[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$
77ffb593 8// Copyright: (c) wxWidgets Team
65571936 9// Licence: wxWindows licence
e1ee679c
VZ
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"
974e8d94 20#include "wx/cursor.h"
e1ee679c
VZ
21
22// ----------------------------------------------------------------------------
23// constants
24// ----------------------------------------------------------------------------
25
2245b2b2
VZ
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!
30enum
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
e1ee679c
VZ
37// result of wxDropSource::DoDragDrop() call
38enum 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)
e6d318c2 44 wxDragLink, // operation is a drag-link
e1ee679c
VZ
45 wxDragCancel // the operation was cancelled by user (not an error)
46};
47
8ee9d618
VZ
48inline WXDLLEXPORT bool wxIsDragResultOk(wxDragResult res)
49{
e6d318c2 50 return res == wxDragCopy || res == wxDragMove || res == wxDragLink;
8ee9d618
VZ
51}
52
e1ee679c
VZ
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
58class WXDLLEXPORT wxDropSourceBase
59{
60public:
2d93e133
VZ
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; }
e1ee679c
VZ
68 virtual ~wxDropSourceBase() { }
69
70 // set the data which is transfered by drag and drop
6dddc146 71 void SetData(wxDataObject& data)
97c79de2 72 { m_data = &data; }
6dddc146 73
97c79de2
RR
74 wxDataObject *GetDataObject()
75 { return m_data; }
e1ee679c 76
2d93e133
VZ
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
e1ee679c
VZ
88 // start drag action, see enum wxDragResult for return value description
89 //
2245b2b2
VZ
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;
e1ee679c
VZ
94
95 // override to give feedback depending on the current operation result
68379eaf 96 // "effect" and return true if you did something, false to let the library
2d93e133 97 // give the default feedback
68379eaf 98 virtual bool GiveFeedback(wxDragResult WXUNUSED(effect)) { return false; }
2d93e133
VZ
99
100protected:
101 const wxCursor& GetCursor(wxDragResult res) const
e1ee679c 102 {
2d93e133
VZ
103 if ( res == wxDragCopy )
104 return m_cursorCopy;
105 else if ( res == wxDragMove )
106 return m_cursorMove;
107 else
108 return m_cursorStop;
e1ee679c
VZ
109 }
110
2245b2b2 111 // the data we're dragging
e1ee679c 112 wxDataObject *m_data;
2d93e133
VZ
113
114 // the cursors to use for feedback
2245b2b2
VZ
115 wxCursor m_cursorCopy,
116 m_cursorMove,
117 m_cursorStop;
22f3361e
VZ
118
119 DECLARE_NO_COPY_CLASS(wxDropSourceBase)
e1ee679c
VZ
120};
121
122// ----------------------------------------------------------------------------
123// wxDropTarget should be associated with a window if it wants to be able to
9e2896e5
VZ
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)
e1ee679c
VZ
131// ----------------------------------------------------------------------------
132
133class WXDLLEXPORT wxDropTargetBase
134{
135public:
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.
b068c4e8 139 wxDropTargetBase(wxDataObject *dataObject = (wxDataObject*)NULL)
917ae499 140 { m_dataObject = dataObject; m_defaultAction = wxDragNone; }
e1ee679c
VZ
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)
6dddc146
DW
149 { if (m_dataObject) delete m_dataObject;
150 m_dataObject = dataObject; }
e1ee679c 151
c9057ae1
VZ
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; }
6dddc146 170
c9057ae1
VZ
171 // called when mouse leaves the window: might be used to remove the
172 // feedback which was given in OnEnter()
173 virtual void OnLeave() { }
6dddc146 174
e1ee679c 175 // this function is called when data is dropped at position (x, y) - if it
68379eaf 176 // returns true, OnData() will be called immediately afterwards which will
e1ee679c
VZ
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
8ee9d618
VZ
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;
e1ee679c
VZ
186
187 // may be called *only* from inside OnData() and will fill m_dataObject
68379eaf 188 // with the data from the drop source if it returns true
e1ee679c
VZ
189 virtual bool GetData() = 0;
190
917ae499
RR
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
e1ee679c
VZ
203protected:
204 wxDataObject *m_dataObject;
917ae499 205 wxDragResult m_defaultAction;
22f3361e
VZ
206
207 DECLARE_NO_COPY_CLASS(wxDropTargetBase)
e1ee679c
VZ
208};
209
210// ----------------------------------------------------------------------------
211// include platform dependent class declarations
212// ----------------------------------------------------------------------------
213
214#if defined(__WXMSW__)
e1ee679c
VZ
215 #include "wx/msw/ole/dropsrc.h"
216 #include "wx/msw/ole/droptgt.h"
2049ba38 217#elif defined(__WXMOTIF__)
e1ee679c 218 #include "wx/motif/dnd.h"
83df96d6
JS
219#elif defined(__WXX11__)
220 #include "wx/x11/dnd.h"
1be7a35c 221#elif defined(__WXGTK20__)
e1ee679c 222 #include "wx/gtk/dnd.h"
1be7a35c
MR
223#elif defined(__WXGTK__)
224 #include "wx/gtk1/dnd.h"
34138703 225#elif defined(__WXMAC__)
e1ee679c 226 #include "wx/mac/dnd.h"
1777b9bb 227#elif defined(__WXPM__)
e1ee679c 228 #include "wx/os2/dnd.h"
c801d85f
KB
229#endif
230
8ee9d618
VZ
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
237class WXDLLEXPORT wxTextDropTarget : public wxDropTarget
238{
239public:
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);
fc7a2a60
VZ
245
246private:
247 DECLARE_NO_COPY_CLASS(wxTextDropTarget)
8ee9d618
VZ
248};
249
250// A drop target which accepts files (dragged from File Manager or Explorer)
251class WXDLLEXPORT wxFileDropTarget : public wxDropTarget
252{
253public:
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);
fc7a2a60
VZ
261
262private:
263 DECLARE_NO_COPY_CLASS(wxFileDropTarget)
8ee9d618
VZ
264};
265
e1ee679c
VZ
266#endif // wxUSE_DRAG_AND_DROP
267
268#endif // _WX_DND_H_BASE_