]>
Commit | Line | Data |
---|---|---|
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 |
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 | %{ | |
d14a1e28 | 54 | IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback); |
d14a1e28 RD |
55 | %} |
56 | ||
57 | ||
58 | %name(DropSource) class wxPyDropSource { | |
59 | public: | |
60 | #ifndef __WXGTK__ | |
e6477984 | 61 | wxPyDropSource(wxWindow *win, |
d14a1e28 RD |
62 | const wxCursor © = wxNullCursor, |
63 | const wxCursor &move = wxNullCursor, | |
64 | const wxCursor &none = wxNullCursor); | |
65 | #else | |
e6477984 | 66 | wxPyDropSource(wxWindow *win, |
d14a1e28 RD |
67 | const wxIcon& copy = wxNullIcon, |
68 | const wxIcon& move = wxNullIcon, | |
69 | const wxIcon& none = wxNullIcon); | |
70 | #endif | |
71 | ||
72 | void _setCallbackInfo(PyObject* self, PyObject* _class, int incref); | |
73 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)" | |
74 | ~wxPyDropSource(); | |
75 | ||
76 | // set the data which is transfered by drag and drop | |
77 | void SetData(wxDataObject& data); | |
78 | ||
79 | wxDataObject *GetDataObject(); | |
80 | ||
81 | // set the icon corresponding to given drag result | |
82 | void SetCursor(wxDragResult res, const wxCursor& cursor); | |
83 | ||
84 | wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); | |
85 | ||
86 | bool base_GiveFeedback(wxDragResult effect); | |
87 | }; | |
88 | ||
89 | ||
90 | //--------------------------------------------------------------------------- | |
91 | ||
92 | // wxDropTarget should be associated with a window if it wants to be able to | |
93 | // receive data via drag and drop. | |
94 | // | |
95 | // To use this class, you should derive from wxDropTarget and implement | |
96 | // OnData() pure virtual method. You may also wish to override OnDrop() if you | |
97 | // want to accept the data only inside some region of the window (this may | |
98 | // avoid having to copy the data to this application which happens only when | |
99 | // OnData() is called) | |
100 | ||
101 | ||
102 | // Just a place holder for the type system. The real base class for | |
103 | // wxPython is wxPyDropTarget | |
104 | // class wxDropTarget { | |
105 | // public: | |
106 | // }; | |
107 | ||
108 | ||
109 | %{ | |
d14a1e28 RD |
110 | IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave); |
111 | IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter); | |
112 | IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver); | |
113 | IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData); | |
114 | IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop); | |
d14a1e28 RD |
115 | %} |
116 | ||
117 | ||
118 | %name(DropTarget) class wxPyDropTarget // : public wxDropTarget | |
119 | { | |
120 | public: | |
2b9048c5 | 121 | %pythonAppend wxPyDropTarget |
8668c242 RD |
122 | "self._setCallbackInfo(self, DropTarget)" |
123 | %apply SWIGTYPE *DISOWN { wxDataObject *dataObject }; | |
d14a1e28 RD |
124 | |
125 | wxPyDropTarget(wxDataObject *dataObject = NULL); | |
126 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
127 | ||
128 | ~wxPyDropTarget(); | |
129 | ||
130 | // get/set the associated wxDataObject | |
131 | wxDataObject *GetDataObject(); | |
d14a1e28 RD |
132 | void SetDataObject(wxDataObject *dataObject); |
133 | ||
8668c242 RD |
134 | %clear wxDataObject *dataObject; |
135 | ||
d14a1e28 RD |
136 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); |
137 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
138 | void base_OnLeave(); | |
139 | bool base_OnDrop(wxCoord x, wxCoord y); | |
140 | ||
141 | // may be called *only* from inside OnData() and will fill m_dataObject | |
dd9f7fea | 142 | // with the data from the drop source if it returns True |
d14a1e28 RD |
143 | bool GetData(); |
144 | ||
145 | }; | |
146 | ||
147 | ||
148 | %pythoncode { PyDropTarget = DropTarget } | |
149 | ||
150 | //--------------------------------------------------------------------------- | |
151 | ||
152 | // A simple wxDropTarget derived class for text data: you only need to | |
153 | // override OnDropText() to get something working | |
154 | ||
155 | ||
156 | %{ | |
157 | class wxPyTextDropTarget : public wxTextDropTarget { | |
158 | public: | |
159 | wxPyTextDropTarget() {} | |
160 | ||
161 | DEC_PYCALLBACK_BOOL_INTINTSTR_pure(OnDropText); | |
162 | ||
163 | DEC_PYCALLBACK__(OnLeave); | |
164 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
165 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
166 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
167 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
168 | ||
169 | PYPRIVATE; | |
170 | }; | |
171 | ||
172 | IMP_PYCALLBACK_BOOL_INTINTSTR_pure(wxPyTextDropTarget, wxTextDropTarget, OnDropText); | |
173 | IMP_PYCALLBACK__(wxPyTextDropTarget, wxTextDropTarget, OnLeave); | |
174 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnEnter); | |
175 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnDragOver); | |
176 | IMP_PYCALLBACK_DR_2WXCDR(wxPyTextDropTarget, wxTextDropTarget, OnData); | |
177 | IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop); | |
178 | ||
179 | %} | |
180 | ||
181 | %name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget { | |
182 | public: | |
2b9048c5 | 183 | %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)" |
d14a1e28 RD |
184 | |
185 | wxPyTextDropTarget(); | |
186 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
187 | ||
188 | //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0; | |
189 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
190 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
191 | void base_OnLeave(); | |
192 | bool base_OnDrop(wxCoord x, wxCoord y); | |
193 | wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); | |
194 | }; | |
195 | ||
196 | //--------------------------------------------------------------------------- | |
197 | ||
198 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
199 | ||
200 | ||
201 | %{ | |
202 | class wxPyFileDropTarget : public wxFileDropTarget { | |
203 | public: | |
204 | wxPyFileDropTarget() {} | |
205 | ||
206 | virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); | |
207 | ||
208 | DEC_PYCALLBACK__(OnLeave); | |
209 | DEC_PYCALLBACK_DR_2WXCDR(OnEnter); | |
210 | DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); | |
211 | DEC_PYCALLBACK_DR_2WXCDR(OnData); | |
212 | DEC_PYCALLBACK_BOOL_INTINT(OnDrop); | |
213 | ||
214 | PYPRIVATE; | |
215 | }; | |
216 | ||
217 | bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, | |
218 | const wxArrayString& filenames) { | |
dd9f7fea | 219 | bool rval = False; |
da32eb53 | 220 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
221 | if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) { |
222 | PyObject* list = wxArrayString2PyList_helper(filenames); | |
223 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list)); | |
224 | Py_DECREF(list); | |
225 | } | |
da32eb53 | 226 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
227 | return rval; |
228 | } | |
229 | ||
230 | ||
231 | ||
232 | IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave); | |
233 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter); | |
234 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver); | |
235 | IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData); | |
236 | IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop); | |
237 | ||
238 | %} | |
239 | ||
240 | ||
241 | %name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget | |
242 | { | |
243 | public: | |
2b9048c5 | 244 | %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)" |
d14a1e28 RD |
245 | |
246 | wxPyFileDropTarget(); | |
247 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
248 | ||
249 | // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0; | |
250 | wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); | |
251 | wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); | |
252 | void base_OnLeave(); | |
253 | bool base_OnDrop(wxCoord x, wxCoord y); | |
254 | wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); | |
255 | }; | |
256 | ||
257 | ||
258 | //--------------------------------------------------------------------------- | |
259 | %init %{ | |
260 | wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource"); | |
261 | wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget"); | |
262 | wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget"); | |
263 | wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget"); | |
264 | %} | |
265 | //--------------------------------------------------------------------------- | |
f87da722 RD |
266 | |
267 | #endif |