]>
Commit | Line | Data |
---|---|---|
e91a9dfc RD |
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 | %{ | |
d14a1e28 RD |
17 | #include "wx/wxPython/wxPython.h" |
18 | #include "wx/wxPython/pyclasses.h" | |
e91a9dfc | 19 | #include "oglhelpers.h" |
d14a1e28 | 20 | |
e91a9dfc RD |
21 | %} |
22 | ||
23 | //--------------------------------------------------------------------------- | |
24 | ||
e91a9dfc | 25 | %import windows.i |
54f9ee45 | 26 | %pythoncode { wx = _core } |
99109c0f | 27 | %pythoncode { __docfilter__ = wx.__DocFilter(globals()) } |
e91a9dfc | 28 | |
b2dc1044 RD |
29 | |
30 | MAKE_CONST_WXSTRING_NOSWIG(EmptyString); | |
31 | ||
d14a1e28 | 32 | %include _ogl_rename.i |
e91a9dfc | 33 | |
d14a1e28 RD |
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 | } | |
e91a9dfc | 58 | |
e91a9dfc RD |
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 | ||
1e7ecb7b | 154 | %{ |
e91a9dfc | 155 | //--------------------------------------------------------------------------- |
1e7ecb7b | 156 | |
d14a1e28 RD |
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) { | |
da32eb53 | 161 | bool blocked = wxPyBeginBlockThreads(); |
1e7ecb7b RD |
162 | if (!PyList_Check(pyList)) { |
163 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
da32eb53 | 164 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
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"); | |
da32eb53 | 171 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
172 | return NULL; |
173 | } | |
174 | for (int x=0; x<count; x++) { | |
175 | PyObject* pyo = PyList_GetItem(pyList, x); | |
176 | wxObject* wxo = NULL; | |
177 | ||
d14a1e28 RD |
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()); | |
da32eb53 | 182 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
183 | return NULL; |
184 | } | |
185 | list->Append(wxo); | |
186 | } | |
da32eb53 | 187 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
188 | return list; |
189 | } | |
190 | ||
e91a9dfc | 191 | //--------------------------------------------------------------------------- |
1e7ecb7b RD |
192 | |
193 | wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) { | |
da32eb53 | 194 | bool blocked = wxPyBeginBlockThreads(); |
1e7ecb7b RD |
195 | if (!PyList_Check(pyList)) { |
196 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
da32eb53 | 197 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
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"); | |
da32eb53 | 204 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
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; | |
d14a1e28 | 221 | if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) { |
1e7ecb7b | 222 | PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples"); |
da32eb53 | 223 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
224 | return NULL; |
225 | } | |
226 | list->Append((wxObject*) new wxRealPoint(*wxo)); | |
227 | } | |
228 | } | |
da32eb53 | 229 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
230 | return list; |
231 | } | |
232 | ||
2f4e9287 RD |
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; | |
4acff284 | 243 | wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject(); |
2f4e9287 RD |
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) | |
4acff284 | 252 | ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target)); |
2f4e9287 RD |
253 | } |
254 | return target; | |
255 | } | |
256 | ||
c893f25d RD |
257 | //--------------------------------------------------------------------------- |
258 | ||
d68a6b6d RD |
259 | PyObject* wxPy_ConvertRealPointList(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 = wxPyConstructObject(wxObj, wxT("wxRealPoint"), 0); | |
271 | PyList_Append(pyList, pyObj); | |
272 | node = node->GetNext(); | |
273 | } | |
274 | wxPyEndBlockThreads(blocked); | |
275 | return pyList; | |
1ce56f78 RD |
276 | } |
277 | ||
278 | //--------------------------------------------------------------------------- | |
279 | ||
d14a1e28 | 280 | PyObject* wxPy_ConvertShapeList(wxListBase* listbase) { |
26b8693b | 281 | wxList* list = (wxList*)listbase; |
c893f25d RD |
282 | PyObject* pyList; |
283 | PyObject* pyObj; | |
284 | wxObject* wxObj; | |
26b8693b | 285 | wxNode* node = list->GetFirst(); |
c893f25d | 286 | |
da32eb53 | 287 | bool blocked = wxPyBeginBlockThreads(); |
c893f25d RD |
288 | pyList = PyList_New(0); |
289 | while (node) { | |
26b8693b | 290 | wxObj = node->GetData(); |
c893f25d RD |
291 | pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj); |
292 | PyList_Append(pyList, pyObj); | |
26b8693b | 293 | node = node->GetNext(); |
c893f25d | 294 | } |
da32eb53 | 295 | wxPyEndBlockThreads(blocked); |
c893f25d RD |
296 | return pyList; |
297 | } | |
2f4e9287 | 298 | |
1e7ecb7b | 299 | |
e91a9dfc | 300 | //--------------------------------------------------------------------------- |
1e7ecb7b | 301 | |
9416aa89 RD |
302 | IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas); |
303 | IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler); | |
304 | IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape); | |
305 | IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape); | |
306 | IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint); | |
307 | IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape); | |
308 | IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape); | |
309 | IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape); | |
310 | IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape); | |
311 | IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape); | |
312 | IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape); | |
313 | IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape); | |
314 | IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape); | |
315 | IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape); | |
316 | IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape); | |
317 | ||
318 | //--------------------------------------------------------------------------- | |
1e7ecb7b | 319 | |
d14a1e28 RD |
320 | // extern "C" SWIGEXPORT(void) initoglbasicc(); |
321 | // extern "C" SWIGEXPORT(void) initoglshapesc(); | |
322 | // extern "C" SWIGEXPORT(void) initoglshapes2c(); | |
323 | // extern "C" SWIGEXPORT(void) initoglcanvasc(); | |
e91a9dfc RD |
324 | %} |
325 | ||
389c5527 | 326 | |
e91a9dfc RD |
327 | %init %{ |
328 | ||
d14a1e28 RD |
329 | // initoglbasicc(); |
330 | // initoglshapesc(); | |
331 | // initoglshapes2c(); | |
332 | // initoglcanvasc(); | |
e91a9dfc RD |
333 | |
334 | ||
856e03b7 RD |
335 | wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint"); |
336 | wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas"); | |
337 | wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler"); | |
338 | wxPyPtrTypeMap_Add("wxShape", "wxPyShape"); | |
339 | wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape"); | |
340 | wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape"); | |
341 | wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape"); | |
342 | wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape"); | |
343 | wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape"); | |
344 | wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape"); | |
345 | wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape"); | |
346 | wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape"); | |
347 | wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape"); | |
348 | wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape"); | |
349 | ||
e91a9dfc RD |
350 | %} |
351 | ||
e91a9dfc RD |
352 | //--------------------------------------------------------------------------- |
353 | //--------------------------------------------------------------------------- |