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