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