]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/ogl/ogl.i
reSWIGged
[wxWidgets.git] / wxPython / contrib / ogl / ogl.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: ogl.i
3 // Purpose: SWIG definitions for the wxWindows Object Graphics Library
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 30-June-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 %module ogl
15
16 %{
17 #include "wx/wxPython/wxPython.h"
18 #include "wx/wxPython/pyclasses.h"
19 #include "oglhelpers.h"
20
21 %}
22
23 //---------------------------------------------------------------------------
24
25 %import windows.i
26 %pythoncode { wx = _core }
27 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
28
29
30 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
31
32 %include _ogl_rename.i
33
34 %include _ogldefs.i
35 %include _oglbasic.i
36 %include _oglshapes.i
37 %include _oglshapes2.i
38 %include _oglcanvas.i
39
40 %pythoncode {
41 %# Aliases
42 ShapeCanvas = PyShapeCanvas
43 ShapeEvtHandler = PyShapeEvtHandler
44 Shape = PyShape
45 RectangleShape = PyRectangleShape
46 BitmapShape = PyBitmapShape
47 DrawnShape = PyDrawnShape
48 CompositeShape = PyCompositeShape
49 DividedShape = PyDividedShape
50 DivisionShape = PyDivisionShape
51 EllipseShape = PyEllipseShape
52 CircleShape = PyCircleShape
53 LineShape = PyLineShape
54 PolygonShape = PyPolygonShape
55 TextShape = PyTextShape
56 ControlPoint = PyControlPoint
57 }
58
59
60 //---------------------------------------------------------------------------
61
62
63 enum {
64 KEY_SHIFT,
65 KEY_CTRL,
66 ARROW_NONE,
67 ARROW_END,
68 ARROW_BOTH,
69 ARROW_MIDDLE,
70 ARROW_START,
71 ARROW_HOLLOW_CIRCLE,
72 ARROW_FILLED_CIRCLE,
73 ARROW_ARROW,
74 ARROW_SINGLE_OBLIQUE,
75 ARROW_DOUBLE_OBLIQUE,
76 ARROW_METAFILE,
77 ARROW_POSITION_END,
78 ARROW_POSITION_START,
79 CONTROL_POINT_VERTICAL,
80 CONTROL_POINT_HORIZONTAL,
81 CONTROL_POINT_DIAGONAL,
82 CONTROL_POINT_ENDPOINT_TO,
83 CONTROL_POINT_ENDPOINT_FROM,
84 CONTROL_POINT_LINE,
85 FORMAT_NONE,
86 FORMAT_CENTRE_HORIZ,
87 FORMAT_CENTRE_VERT,
88 FORMAT_SIZE_TO_CONTENTS,
89 LINE_ALIGNMENT_HORIZ,
90 LINE_ALIGNMENT_VERT,
91 LINE_ALIGNMENT_TO_NEXT_HANDLE,
92 LINE_ALIGNMENT_NONE,
93 SHADOW_NONE,
94 SHADOW_LEFT,
95 SHADOW_RIGHT,
96 // SHAPE_BASIC,
97 // SHAPE_RECTANGLE,
98 // SHAPE_ELLIPSE,
99 // SHAPE_POLYGON,
100 // SHAPE_CIRCLE,
101 // SHAPE_LINE,
102 // SHAPE_DIVIDED_RECTANGLE,
103 // SHAPE_COMPOSITE,
104 // SHAPE_CONTROL_POINT,
105 // SHAPE_DRAWN,
106 // SHAPE_DIVISION,
107 // SHAPE_LABEL_OBJECT,
108 // SHAPE_BITMAP,
109 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
110 // OBJECT_REGION,
111 OP_CLICK_LEFT,
112 OP_CLICK_RIGHT,
113 OP_DRAG_LEFT,
114 OP_DRAG_RIGHT,
115 OP_ALL,
116 ATTACHMENT_MODE_NONE,
117 ATTACHMENT_MODE_EDGE,
118 ATTACHMENT_MODE_BRANCHING,
119 BRANCHING_ATTACHMENT_NORMAL,
120 BRANCHING_ATTACHMENT_BLOB,
121
122 gyCONSTRAINT_CENTRED_VERTICALLY,
123 gyCONSTRAINT_CENTRED_HORIZONTALLY,
124 gyCONSTRAINT_CENTRED_BOTH,
125 gyCONSTRAINT_LEFT_OF,
126 gyCONSTRAINT_RIGHT_OF,
127 gyCONSTRAINT_ABOVE,
128 gyCONSTRAINT_BELOW,
129 gyCONSTRAINT_ALIGNED_TOP,
130 gyCONSTRAINT_ALIGNED_BOTTOM,
131 gyCONSTRAINT_ALIGNED_LEFT,
132 gyCONSTRAINT_ALIGNED_RIGHT,
133 gyCONSTRAINT_MIDALIGNED_TOP,
134 gyCONSTRAINT_MIDALIGNED_BOTTOM,
135 gyCONSTRAINT_MIDALIGNED_LEFT,
136 gyCONSTRAINT_MIDALIGNED_RIGHT,
137
138 DIVISION_SIDE_NONE,
139 DIVISION_SIDE_LEFT,
140 DIVISION_SIDE_TOP,
141 DIVISION_SIDE_RIGHT,
142 DIVISION_SIDE_BOTTOM,
143
144 };
145
146
147
148 //---------------------------------------------------------------------------
149
150 void wxOGLInitialize();
151 void wxOGLCleanUp();
152
153
154 %{
155 //---------------------------------------------------------------------------
156
157 // Convert from a Python list to a list of className objects. This one will
158 // work for any class for the VERY generic cases, but beyond that the helper
159 // needs to know more about the type.
160 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
161 bool blocked = wxPyBeginBlockThreads();
162 if (!PyList_Check(pyList)) {
163 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
164 wxPyEndBlockThreads(blocked);
165 return NULL;
166 }
167 int count = PyList_Size(pyList);
168 wxList* list = new wxList;
169 if (! list) {
170 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
171 wxPyEndBlockThreads(blocked);
172 return NULL;
173 }
174 for (int x=0; x<count; x++) {
175 PyObject* pyo = PyList_GetItem(pyList, x);
176 wxObject* wxo = NULL;
177
178 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
179 wxString errmsg;
180 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
181 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
182 wxPyEndBlockThreads(blocked);
183 return NULL;
184 }
185 list->Append(wxo);
186 }
187 wxPyEndBlockThreads(blocked);
188 return list;
189 }
190
191 //---------------------------------------------------------------------------
192
193 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
194 bool blocked = wxPyBeginBlockThreads();
195 if (!PyList_Check(pyList)) {
196 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
197 wxPyEndBlockThreads(blocked);
198 return NULL;
199 }
200 int count = PyList_Size(pyList);
201 wxList* list = new wxList;
202 if (! list) {
203 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
204 wxPyEndBlockThreads(blocked);
205 return NULL;
206 }
207 for (int x=0; x<count; x++) {
208 PyObject* pyo = PyList_GetItem(pyList, x);
209
210 if (PyTuple_Check(pyo)) {
211 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
212 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
213
214 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
215 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
216
217 list->Append((wxObject*) new wxRealPoint(val1, val2));
218
219 } else {
220 wxRealPoint* wxo = NULL;
221 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
222 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
223 wxPyEndBlockThreads(blocked);
224 return NULL;
225 }
226 list->Append((wxObject*) new wxRealPoint(*wxo));
227 }
228 }
229 wxPyEndBlockThreads(blocked);
230 return list;
231 }
232
233 //---------------------------------------------------------------------------
234
235 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source) {
236 PyObject* target = NULL;
237
238 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
239 // If it's derived from wxShapeEvtHandler then there may
240 // already be a pointer to a Python object that we can use
241 // in the OOR data.
242 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
243 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
244 if (data) {
245 target = data->m_obj;
246 Py_INCREF(target);
247 }
248 }
249 if (! target) {
250 target = wxPyMake_wxObject2(source, FALSE);
251 if (target != Py_None)
252 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
253 }
254 return target;
255 }
256
257 //---------------------------------------------------------------------------
258
259 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
260 wxList* list = (wxList*)listbase;
261 PyObject* pyList;
262 PyObject* pyObj;
263 wxObject* wxObj;
264 wxNode* node = list->GetFirst();
265
266 bool blocked = wxPyBeginBlockThreads();
267 pyList = PyList_New(0);
268 while (node) {
269 wxObj = node->GetData();
270 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj);
271 PyList_Append(pyList, pyObj);
272 node = node->GetNext();
273 }
274 wxPyEndBlockThreads(blocked);
275 return pyList;
276 }
277
278
279 //---------------------------------------------------------------------------
280
281 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
282 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
283 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
284 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
285 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
286 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
287 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
288 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
289 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
290 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
291 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
292 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
293 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
294 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
295 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
296
297 //---------------------------------------------------------------------------
298
299 // extern "C" SWIGEXPORT(void) initoglbasicc();
300 // extern "C" SWIGEXPORT(void) initoglshapesc();
301 // extern "C" SWIGEXPORT(void) initoglshapes2c();
302 // extern "C" SWIGEXPORT(void) initoglcanvasc();
303 %}
304
305
306 %init %{
307
308 // initoglbasicc();
309 // initoglshapesc();
310 // initoglshapes2c();
311 // initoglcanvasc();
312
313
314 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
315 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
316 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
317 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
318 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
319 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
320 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
321 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
322 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
323 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
324 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
325 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
326 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
327 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
328
329 %}
330
331 //---------------------------------------------------------------------------
332 //---------------------------------------------------------------------------