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