]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_dnd.i
This file should not have been checked in!
[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
18 %{
19 %}
20
21 //---------------------------------------------------------------------------
22 %newgroup
23
24 // flags for wxDropSource::DoDragDrop()
25 //
26 // NB: wxDrag_CopyOnly must be 0 (== False) and wxDrag_AllowMove must be 1
27 // (== True) for compatibility with the old DoDragDrop(bool) method!
28 enum
29 {
30 wxDrag_CopyOnly = 0, // allow only copying
31 wxDrag_AllowMove = 1, // allow moving (copying is always allowed)
32 wxDrag_DefaultMove = 3 // the default operation is move, not copy
33 };
34
35 // result of wxDropSource::DoDragDrop() call
36 enum wxDragResult
37 {
38 wxDragError, // error prevented the d&d operation from completing
39 wxDragNone, // drag target didn't accept the data
40 wxDragCopy, // the data was successfully copied
41 wxDragMove, // the data was successfully moved (MSW only)
42 wxDragLink, // operation is a drag-link
43 wxDragCancel // the operation was cancelled by user (not an error)
44 };
45
46 bool wxIsDragResultOk(wxDragResult res);
47
48 //---------------------------------------------------------------------------
49
50
51 // wxDropSource is the object you need to create (and call DoDragDrop on it)
52 // to initiate a drag-and-drop operation
53
54
55
56 %{
57 IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback);
58 %}
59
60
61 %name(DropSource) class wxPyDropSource {
62 public:
63 #ifndef __WXGTK__
64 wxPyDropSource(wxWindow *win = NULL,
65 const wxCursor &copy = wxNullCursor,
66 const wxCursor &move = wxNullCursor,
67 const wxCursor &none = wxNullCursor);
68 #else
69 wxPyDropSource(wxWindow *win = NULL,
70 const wxIcon& copy = wxNullIcon,
71 const wxIcon& move = wxNullIcon,
72 const wxIcon& none = wxNullIcon);
73 #endif
74
75 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref);
76 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)"
77 ~wxPyDropSource();
78
79 // set the data which is transfered by drag and drop
80 void SetData(wxDataObject& data);
81
82 wxDataObject *GetDataObject();
83
84 // set the icon corresponding to given drag result
85 void SetCursor(wxDragResult res, const wxCursor& cursor);
86
87 wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
88
89 bool base_GiveFeedback(wxDragResult effect);
90 };
91
92
93 //---------------------------------------------------------------------------
94
95 // wxDropTarget should be associated with a window if it wants to be able to
96 // receive data via drag and drop.
97 //
98 // To use this class, you should derive from wxDropTarget and implement
99 // OnData() pure virtual method. You may also wish to override OnDrop() if you
100 // want to accept the data only inside some region of the window (this may
101 // avoid having to copy the data to this application which happens only when
102 // OnData() is called)
103
104
105 // Just a place holder for the type system. The real base class for
106 // wxPython is wxPyDropTarget
107 // class wxDropTarget {
108 // public:
109 // };
110
111
112 %{
113 IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave);
114 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter);
115 IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver);
116 IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData);
117 IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop);
118 %}
119
120
121 %name(DropTarget) class wxPyDropTarget // : public wxDropTarget
122 {
123 public:
124 %addtofunc wxPyDropTarget
125 "if args: args[0].thisown = 0;
126 self._setCallbackInfo(self, DropTarget)"
127
128 wxPyDropTarget(wxDataObject *dataObject = NULL);
129 void _setCallbackInfo(PyObject* self, PyObject* _class);
130
131 ~wxPyDropTarget();
132
133 // get/set the associated wxDataObject
134 wxDataObject *GetDataObject();
135 %addtofunc SetDataObject "args[1].thisown = 0"
136 void SetDataObject(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 %name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget {
184 public:
185 %addtofunc wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)"
186
187 wxPyTextDropTarget();
188 void _setCallbackInfo(PyObject* self, PyObject* _class);
189
190 //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
191 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
192 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
193 void base_OnLeave();
194 bool base_OnDrop(wxCoord x, wxCoord y);
195 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
196 };
197
198 //---------------------------------------------------------------------------
199
200 // A drop target which accepts files (dragged from File Manager or Explorer)
201
202
203 %{
204 class wxPyFileDropTarget : public wxFileDropTarget {
205 public:
206 wxPyFileDropTarget() {}
207
208 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
209
210 DEC_PYCALLBACK__(OnLeave);
211 DEC_PYCALLBACK_DR_2WXCDR(OnEnter);
212 DEC_PYCALLBACK_DR_2WXCDR(OnDragOver);
213 DEC_PYCALLBACK_DR_2WXCDR(OnData);
214 DEC_PYCALLBACK_BOOL_INTINT(OnDrop);
215
216 PYPRIVATE;
217 };
218
219 bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y,
220 const wxArrayString& filenames) {
221 bool rval = False;
222 wxPyBeginBlockThreads();
223 if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) {
224 PyObject* list = wxArrayString2PyList_helper(filenames);
225 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list));
226 Py_DECREF(list);
227 }
228 wxPyEndBlockThreads();
229 return rval;
230 }
231
232
233
234 IMP_PYCALLBACK__(wxPyFileDropTarget, wxFileDropTarget, OnLeave);
235 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnEnter);
236 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnDragOver);
237 IMP_PYCALLBACK_DR_2WXCDR(wxPyFileDropTarget, wxFileDropTarget, OnData);
238 IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop);
239
240 %}
241
242
243 %name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget
244 {
245 public:
246 %addtofunc wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)"
247
248 wxPyFileDropTarget();
249 void _setCallbackInfo(PyObject* self, PyObject* _class);
250
251 // bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0;
252 wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def);
253 wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
254 void base_OnLeave();
255 bool base_OnDrop(wxCoord x, wxCoord y);
256 wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def);
257 };
258
259
260 //---------------------------------------------------------------------------
261 %init %{
262 wxPyPtrTypeMap_Add("wxDropSource", "wxPyDropSource");
263 wxPyPtrTypeMap_Add("wxDropTarget", "wxPyDropTarget");
264 wxPyPtrTypeMap_Add("wxTextDropTarget", "wxPyTextDropTarget");
265 wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget");
266 %}
267 //---------------------------------------------------------------------------