]>
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 | ||
d14a1e28 | 259 | PyObject* wxPy_ConvertShapeList(wxListBase* listbase) { |
26b8693b | 260 | wxList* list = (wxList*)listbase; |
c893f25d RD |
261 | PyObject* pyList; |
262 | PyObject* pyObj; | |
263 | wxObject* wxObj; | |
26b8693b | 264 | wxNode* node = list->GetFirst(); |
c893f25d | 265 | |
da32eb53 | 266 | bool blocked = wxPyBeginBlockThreads(); |
c893f25d RD |
267 | pyList = PyList_New(0); |
268 | while (node) { | |
26b8693b | 269 | wxObj = node->GetData(); |
c893f25d RD |
270 | pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj); |
271 | PyList_Append(pyList, pyObj); | |
26b8693b | 272 | node = node->GetNext(); |
c893f25d | 273 | } |
da32eb53 | 274 | wxPyEndBlockThreads(blocked); |
c893f25d RD |
275 | return pyList; |
276 | } | |
2f4e9287 | 277 | |
1e7ecb7b | 278 | |
e91a9dfc | 279 | //--------------------------------------------------------------------------- |
1e7ecb7b | 280 | |
9416aa89 RD |
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 | //--------------------------------------------------------------------------- | |
1e7ecb7b | 298 | |
d14a1e28 RD |
299 | // extern "C" SWIGEXPORT(void) initoglbasicc(); |
300 | // extern "C" SWIGEXPORT(void) initoglshapesc(); | |
301 | // extern "C" SWIGEXPORT(void) initoglshapes2c(); | |
302 | // extern "C" SWIGEXPORT(void) initoglcanvasc(); | |
e91a9dfc RD |
303 | %} |
304 | ||
389c5527 | 305 | |
e91a9dfc RD |
306 | %init %{ |
307 | ||
d14a1e28 RD |
308 | // initoglbasicc(); |
309 | // initoglshapesc(); | |
310 | // initoglshapes2c(); | |
311 | // initoglcanvasc(); | |
e91a9dfc RD |
312 | |
313 | ||
856e03b7 RD |
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 | ||
e91a9dfc RD |
329 | %} |
330 | ||
e91a9dfc RD |
331 | //--------------------------------------------------------------------------- |
332 | //--------------------------------------------------------------------------- |