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