]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_dnd.i
Delay part of the setup
[wxWidgets.git] / wxPython / src / _dnd.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _dnd.i
3 // Purpose: SWIG definitions for the Drag-n-drop classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 31-October-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 #ifndef __WXX11__
18
19 %newgroup
20
21 // flags for wxDropSource::DoDragDrop()
22 //
23 // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1
24 // (== True) for compatibility with the old DoDragDrop(bool) method!
25 enum
26 {
27 wxDrag_CopyOnly = 0, // allow only copying
28 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
29 wxDrag_DefaultMove = 3 // the default operation is move, not copy
30 };
31
32 // result of wxDropSource::DoDragDrop() call
33 enum wxDragResult
34 {
35 wxDragError, // error prevented the d&d operation from completing
36 wxDragNone, // drag target didn't accept the data
37 wxDragCopy, // the data was successfully copied
38 wxDragMove, // the data was successfully moved (MSW only)
39 wxDragLink, // operation is a drag-link
40 wxDragCancel // the operation was cancelled by user (not an error)
41 };
42
43 bool wxIsDragResultOk(wxDragResult res);
44
45 //---------------------------------------------------------------------------
46
47
48 // wxDropSource is the object you need to create (and call DoDragDrop on it)
49 // to initiate a drag-and-drop operation
50
51
52
53 %{
54 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
55 %}
56
57
58 %rename(DropSource) wxPyDropSource;
59 class wxPyDropSource {
60 public:
61 %pythonAppend wxPyDropSource "self._setCallbackInfo(self, DropSource, 0)"
62 #ifndef __WXGTK__
63 wxPyDropSource(wxWindow *win,
64 const wxCursor &copy = wxNullCursor,
65 const wxCursor &move = wxNullCursor,
66 const wxCursor &none = wxNullCursor);
67 #else
68 wxPyDropSource(wxWindow *win,
69 const wxIcon& copy = wxNullIcon,
70 const wxIcon& move = wxNullIcon,
71 const wxIcon& none = wxNullIcon);
72 #endif
73
74 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
75 ~wxPyDropSource();
76
77 // set the data which is transfered by drag and drop
78 void SetData(wxDataObject& data);
79
80 wxDataObject *GetDataObject();
81
82 // set the icon corresponding to given drag result
83 void SetCursor(wxDragResult res, const wxCursor& cursor);
84
85 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
86
87 bool base_GiveFeedback(wxDragResult effect);
88 };
89
90
91 %pythoncode {
92 def DROP_ICON(filename):
93 """
94 Returns either a `wx.Cursor` or `wx.Icon` created from the image file
95 ``filename``. This function is useful with the `wx.DropSource` class
96 which, depending on platform accepts either a icon or a cursor.
97 """
98 img = wx.Image(filename)
99 if wx.Platform == '__WXGTK__':
100 return wx.IconFromBitmap(wx.BitmapFromImage(img))
101 else:
102 return wx.CursorFromImage(img)
103 }
104
105
106 //---------------------------------------------------------------------------
107
108 // wxDropTarget should be associated with a window if it wants to be able to
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)
116
117
118 // Just a place holder for the type system. The real base class for
119 // wxPython is wxPyDropTarget
120 // class wxDropTarget {
121 // public:
122 // };
123
124
125 %{
126 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
127 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
128 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
129 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
130 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
131 %}
132
133
134 %rename(DropTarget) wxPyDropTarget;
135 class wxPyDropTarget // : public wxDropTarget
136 {
137 public:
138 %pythonAppend wxPyDropTarget
139 "self._setCallbackInfo(self, DropTarget)"
140
141 %disownarg( wxDataObject *dataObject );
142
143 wxPyDropTarget(wxDataObject *dataObject = NULL);
144 void _setCallbackInfo(PyObject* self, PyObject* _class);
145
146 ~wxPyDropTarget();
147
148 // get/set the associated wxDataObject
149 wxDataObject *GetDataObject();
150 void SetDataObject(wxDataObject *dataObject);
151
152 %cleardisown( wxDataObject *dataObject );
153
154 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
155 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
156 void base_OnLeave();
157 bool base_OnDrop(wxCoord x, wxCoord y);
158
159 // may be called *only* from inside OnData() and will fill m_dataObject
160 // with the data from the drop source if it returns True
161 bool GetData();
162
163 // sets the default action for drag and drop:
164 // use wxDragMove or wxDragCopy to set deafult action to move or copy
165 // and use wxDragNone (default) to set default action specified by
166 // initialization of draging (see wxDropSourceBase::DoDragDrop())
167 void SetDefaultAction(wxDragResult action);
168
169 // returns default action for drag and drop or
170 // wxDragNone if this not specified
171 wxDragResult GetDefaultAction();
172 };
173
174
175 %pythoncode { PyDropTarget = DropTarget }
176
177 //---------------------------------------------------------------------------
178
179 // A simple wxDropTarget derived class for text data: you only need to
180 // override OnDropText() to get something working
181
182
183 %{
184 class wxPyTextDropTarget : public wxTextDropTarget {
185 public:
186 wxPyTextDropTarget() {}
187
188 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
189
190 DEC_PYCALLBACK__(OnLeave);
191 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
192 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
193 DEC_PYCALLBACK_DR_2WXCDR(OnData);
194 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
195
196 PYPRIVATE;
197 };
198
199 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
200 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
201 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
202 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
203 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
204 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
205
206 %}
207
208 %rename(TextDropTarget) wxPyTextDropTarget;
209 class wxPyTextDropTarget : public wxPyDropTarget {
210 public:
211 %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
212
213 wxPyTextDropTarget();
214 void _setCallbackInfo(PyObject* self, PyObject* _class);
215
216 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
217 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
218 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
219 void base_OnLeave();
220 bool base_OnDrop(wxCoord x, wxCoord y);
221 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
222 };
223
224 //---------------------------------------------------------------------------
225
226 // A drop target which accepts files (dragged from File Manager or Explorer)
227
228
229 %{
230 class wxPyFileDropTarget : public wxFileDropTarget {
231 public:
232 wxPyFileDropTarget() {}
233
234 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
235
236 DEC_PYCALLBACK__(OnLeave);
237 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
238 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
239 DEC_PYCALLBACK_DR_2WXCDR(OnData);
240 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
241
242 PYPRIVATE;
243 };
244
245 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
246 const wxArrayString& filenames) {
247 bool rval = false;
248 wxPyBlock_t blocked = wxPyBeginBlockThreads();
249 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
250 PyObject* list = wxArrayString2PyList_helper(filenames);
251 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
252 Py_DECREF(list);
253 }
254 wxPyEndBlockThreads(blocked);
255 return rval;
256 }
257
258
259
260 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
261 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
262 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
263 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
264 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
265
266 %}
267
268
269 %rename(FileDropTarget) wxPyFileDropTarget;
270 class wxPyFileDropTarget : public wxPyDropTarget
271 {
272 public:
273 %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
274
275 wxPyFileDropTarget();
276 void _setCallbackInfo(PyObject* self, PyObject* _class);
277
278 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
279 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
280 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
281 void base_OnLeave();
282 bool base_OnDrop(wxCoord x, wxCoord y);
283 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
284 };
285
286
287 //---------------------------------------------------------------------------
288 %init %{
289 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
290 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
291 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
292 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
293 %}
294 //---------------------------------------------------------------------------
295
296 #endif