]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_dnd.i
Allow unicode objects in wxPyDrawTextList
[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 //---------------------------------------------------------------------------
92
93 // wxDropTarget should be associated with a window if it wants to be able to
94 // receive data via drag and drop.
95 //
96 // To use this class, you should derive from wxDropTarget and implement
97 // OnData() pure virtual method. You may also wish to override OnDrop() if you
98 // want to accept the data only inside some region of the window (this may
99 // avoid having to copy the data to this application which happens only when
100 // OnData() is called)
101
102
103 // Just a place holder for the type system. The real base class for
104 // wxPython is wxPyDropTarget
105 // class wxDropTarget {
106 // public:
107 // };
108
109
110 %{
111 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
112 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
113 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
114 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
115 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
116 %}
117
118
119 %rename(DropTarget) wxPyDropTarget;
120 class wxPyDropTarget // : public wxDropTarget
121 {
122 public:
123 %pythonAppend wxPyDropTarget
124 "self._setCallbackInfo(self, DropTarget)"
125 %apply SWIGTYPE *DISOWN { wxDataObject *dataObject };
126
127 wxPyDropTarget(wxDataObject *dataObject = NULL);
128 void _setCallbackInfo(PyObject* self, PyObject* _class);
129
130 ~wxPyDropTarget();
131
132 // get/set the associated wxDataObject
133 wxDataObject *GetDataObject();
134 void SetDataObject(wxDataObject *dataObject);
135
136 %clear wxDataObject *dataObject;
137
138 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
139 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
140 void base_OnLeave();
141 bool base_OnDrop(wxCoord x, wxCoord y);
142
143 // may be called *only* from inside OnData() and will fill m_dataObject
144 // with the data from the drop source if it returns True
145 bool GetData();
146
147 };
148
149
150 %pythoncode { PyDropTarget = DropTarget }
151
152 //---------------------------------------------------------------------------
153
154 // A simple wxDropTarget derived class for text data: you only need to
155 // override OnDropText() to get something working
156
157
158 %{
159 class wxPyTextDropTarget : public wxTextDropTarget {
160 public:
161 wxPyTextDropTarget() {}
162
163 DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText);
164
165 DEC_PYCALLBACK__(OnLeave);
166 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
167 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
168 DEC_PYCALLBACK_DR_2WXCDR(OnData);
169 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
170
171 PYPRIVATE;
172 };
173
174 IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText);
175 IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave);
176 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter);
177 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver);
178 IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData);
179 IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop);
180
181 %}
182
183 %rename(TextDropTarget) wxPyTextDropTarget;
184 class wxPyTextDropTarget : public wxPyDropTarget {
185 public:
186 %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
187
188 wxPyTextDropTarget();
189 void _setCallbackInfo(PyObject* self, PyObject* _class);
190
191 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
192 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
193 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
194 void base_OnLeave();
195 bool base_OnDrop(wxCoord x, wxCoord y);
196 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
197 };
198
199 //---------------------------------------------------------------------------
200
201 // A drop target which accepts files (dragged from File Manager or Explorer)
202
203
204 %{
205 class wxPyFileDropTarget : public wxFileDropTarget {
206 public:
207 wxPyFileDropTarget() {}
208
209 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
210
211 DEC_PYCALLBACK__(OnLeave);
212 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
213 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
214 DEC_PYCALLBACK_DR_2WXCDR(OnData);
215 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
216
217 PYPRIVATE;
218 };
219
220 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
221 const wxArrayString& filenames) {
222 bool rval = false;
223 bool blocked = wxPyBeginBlockThreads();
224 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
225 PyObject* list = wxArrayString2PyList_helper(filenames);
226 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
227 Py_DECREF(list);
228 }
229 wxPyEndBlockThreads(blocked);
230 return rval;
231 }
232
233
234
235 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
236 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
237 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
238 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
239 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
240
241 %}
242
243
244 %rename(FileDropTarget) wxPyFileDropTarget;
245 class wxPyFileDropTarget : public wxPyDropTarget
246 {
247 public:
248 %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
249
250 wxPyFileDropTarget();
251 void _setCallbackInfo(PyObject* self, PyObject* _class);
252
253 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
254 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
255 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
256 void base_OnLeave();
257 bool base_OnDrop(wxCoord x, wxCoord y);
258 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
259 };
260
261
262 //---------------------------------------------------------------------------
263 %init %{
264 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
265 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
266 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
267 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
268 %}
269 //---------------------------------------------------------------------------
270
271 #endif