]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_dnd.i
use wx.CallAfter to set the insertion point
[wxWidgets.git] / wxPython / src / _dnd.i
CommitLineData
d14a1e28
RD
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//---------------------------------------------------------------------------
f87da722 17#ifndef __WXX11__
d14a1e28 18
d14a1e28
RD
19%newgroup
20
21// flags for wxDropSource::DoDragDrop()
22//
dd9f7fea
RD
23// NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1
24// (== True) for compatibility with the old DoDragDrop(bool) method!
d14a1e28
RD
25enum
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
33enum 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
43bool 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%{
d14a1e28 54IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
d14a1e28
RD
55%}
56
57
1b8c7ba6
RD
58%rename(DropSource) wxPyDropSource;
59class wxPyDropSource {
d14a1e28 60public:
864a91c8 61 %pythonAppend wxPyDropSource "self._setCallbackInfo(self, DropSource, 0)"
d14a1e28 62#ifndef __WXGTK__
e6477984 63 wxPyDropSource(wxWindow *win,
d14a1e28
RD
64 const wxCursor &copy = wxNullCursor,
65 const wxCursor &move = wxNullCursor,
66 const wxCursor &none = wxNullCursor);
67#else
e6477984 68 wxPyDropSource(wxWindow *win,
d14a1e28
RD
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);
d14a1e28
RD
75 ~wxPyDropSource();
76
77 // set the data which is transfered by drag and drop
78 void SetData(wxDataObject& data);
864a91c8 79
d14a1e28 80 wxDataObject *GetDataObject();
864a91c8 81
d14a1e28
RD
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
f66cece3
RD
91%pythoncode {
92def 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
d14a1e28
RD
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%{
d14a1e28
RD
126IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
127IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
128IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
129IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
130IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
d14a1e28
RD
131%}
132
133
1b8c7ba6
RD
134%rename(DropTarget) wxPyDropTarget;
135class wxPyDropTarget // : public wxDropTarget
d14a1e28
RD
136{
137public:
2b9048c5 138 %pythonAppend wxPyDropTarget
8668c242
RD
139 "self._setCallbackInfo(self, DropTarget)"
140 %apply SWIGTYPE *DISOWN { wxDataObject *dataObject };
d14a1e28
RD
141
142 wxPyDropTarget(wxDataObject *dataObject = NULL);
143 void _setCallbackInfo(PyObject* self, PyObject* _class);
144
145 ~wxPyDropTarget();
146
147 // get/set the associated wxDataObject
148 wxDataObject *GetDataObject();
d14a1e28
RD
149 void SetDataObject(wxDataObject *dataObject);
150
8668c242
RD
151 %clear wxDataObject *dataObject;
152
d14a1e28
RD
153 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
154 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
155 void base_OnLeave();
156 bool base_OnDrop(wxCoord x, wxCoord y);
157
158 // may be called *only* from inside OnData() and will fill m_dataObject
dd9f7fea 159 // with the data from the drop source if it returns True
d14a1e28
RD
160 bool GetData();
161
303f572e
RD
162 // sets the default action for drag and drop:
163 // use wxDragMove or wxDragCopy to set deafult action to move or copy
164 // and use wxDragNone (default) to set default action specified by
165 // initialization of draging (see wxDropSourceBase::DoDragDrop())
166 void SetDefaultAction(wxDragResult action);
167
168 // returns default action for drag and drop or
169 // wxDragNone if this not specified
170 wxDragResult GetDefaultAction();
d14a1e28
RD
171};
172
173
174%pythoncode { PyDropTarget = DropTarget }
175
176//---------------------------------------------------------------------------
177
178// A simple wxDropTarget derived class for text data: you only need to
179// override OnDropText() to get something working
180
181
182%{
183class wxPyTextDropTarget : public wxTextDropTarget {
184public:
185 wxPyTextDropTarget() {}
186
187 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
188
189 DEC_PYCALLBACK__(OnLeave);
190 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
191 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
192 DEC_PYCALLBACK_DR_2WXCDR(OnData);
193 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
194
195 PYPRIVATE;
196};
197
198IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
199IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
200IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
201IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
202IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
203IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
204
205%}
206
1b8c7ba6
RD
207%rename(TextDropTarget) wxPyTextDropTarget;
208class wxPyTextDropTarget : public wxPyDropTarget {
d14a1e28 209public:
2b9048c5 210 %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
d14a1e28
RD
211
212 wxPyTextDropTarget();
213 void _setCallbackInfo(PyObject* self, PyObject* _class);
214
215 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
216 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
217 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
218 void base_OnLeave();
219 bool base_OnDrop(wxCoord x, wxCoord y);
220 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
221};
222
223//---------------------------------------------------------------------------
224
225// A drop target which accepts files (dragged from File Manager or Explorer)
226
227
228%{
229class wxPyFileDropTarget : public wxFileDropTarget {
230public:
231 wxPyFileDropTarget() {}
232
233 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
234
235 DEC_PYCALLBACK__(OnLeave);
236 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
237 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
238 DEC_PYCALLBACK_DR_2WXCDR(OnData);
239 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
240
241 PYPRIVATE;
242};
243
244bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
245 const wxArrayString& filenames) {
a72f4631 246 bool rval = false;
6e6b3557 247 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
248 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
249 PyObject* list = wxArrayString2PyList_helper(filenames);
250 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
251 Py_DECREF(list);
252 }
da32eb53 253 wxPyEndBlockThreads(blocked);
d14a1e28
RD
254 return rval;
255}
256
257
258
259IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
260IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
261IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
262IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
263IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
264
265%}
266
267
1b8c7ba6
RD
268%rename(FileDropTarget) wxPyFileDropTarget;
269class wxPyFileDropTarget : public wxPyDropTarget
d14a1e28
RD
270{
271public:
2b9048c5 272 %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
d14a1e28
RD
273
274 wxPyFileDropTarget();
275 void _setCallbackInfo(PyObject* self, PyObject* _class);
276
277// bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
278 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
279 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
280 void base_OnLeave();
281 bool base_OnDrop(wxCoord x, wxCoord y);
282 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
283};
284
285
286//---------------------------------------------------------------------------
287%init %{
288 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
289 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
290 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
291 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
292%}
293//---------------------------------------------------------------------------
f87da722
RD
294
295#endif