]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/my_typemaps.i
Updated layout test
[wxWidgets.git] / wxPython / src / my_typemaps.i
index 968ff7a26b8ef50abf0ab375ed0985c0c9f4b056..dbf2433fe06114e21427f0df427e857fd66359ed 100644 (file)
 %#else
         PyObject* str  = PyObject_Str(item);
 %#endif
+        if (PyErr_Occurred())  SWIG_fail;
         $1->Add(Py2wxString(str));
         Py_DECREF(item);
         Py_DECREF(str);
 
 //---------------------------------------------------------------------------
 
-%typemap(out) bool "$result = $1 ? Py_True : Py_False; Py_INCREF($result);"
+%typemap(out) bool {
+    $result = $1 ? Py_True : Py_False; Py_INCREF($result);
+}
+
+
+// These fragments are iserted in modules that need to convert PyObjects to
+// integer values, my versions allow any numeric type to be used, as long as
+// it can be converted to a PyInt.  (Specifically, I allow floats where the
+// default SWIG_AsLong would raise an obsucre exception from within
+// PyLong_AsLong.)
+
+%fragment("SWIG_AsLong","header") %{
+SWIGSTATICINLINE(long)
+SWIG_AsLong(PyObject * obj)
+{
+    if (PyNumber_Check(obj))
+        return PyInt_AsLong(obj);
+    else {
+        PyObject* errmsg = PyString_FromFormat("Expected number, got %s",
+                                               obj->ob_type->tp_name);
+        PyErr_SetObject(PyExc_TypeError, errmsg);
+        Py_DECREF(errmsg);
+        return 0;
+    }
+}
+%}
+
+%fragment("SWIG_AsUnsignedLong","header", fragment="SWIG_AsLong") %{
+SWIGSTATICINLINE(unsigned long)
+SWIG_AsUnsignedLong(PyObject * obj) 
+{
+  if (PyLong_Check(obj)) {
+    return PyLong_AsUnsignedLong(obj);
+  } else {
+    long i = SWIG_AsLong(obj);
+    if ( !PyErr_Occurred() && (i < 0)) {
+      PyErr_SetString(PyExc_TypeError, "negative value received for unsigned type");
+    }
+    return i;
+  }
+}
+%}
+
+
+%fragment("SWIG_AsDouble","header") %{
+SWIGSTATICINLINE(double)
+SWIG_AsDouble(PyObject *obj)
+{
+    if (PyNumber_Check(obj))
+        return PyFloat_AsDouble(obj);
+    else {
+        PyObject* errmsg = PyString_FromFormat("Expected number, got %s",
+                                               obj->ob_type->tp_name);
+        PyErr_SetObject(PyExc_TypeError, errmsg);
+        Py_DECREF(errmsg);
+        return 0;
+    }
+}
+%}
+
+
+//---------------------------------------------------------------------------
+// Typemap for when GDI objects are returned by reference.  This will cause a
+// copy to be made instead of returning a reference to the same instance.  The
+// GDI object's internal refcounting scheme will do a copy-on-write of the
+// internal data as needed.
+
+// These too?
+//, wxRegion&, wxPalette&
+
+%typemap(out) wxBrush&, wxPen&, wxFont&, wxBitmap&, wxIcon&, wxCursor& {
+    $*1_ltype* resultptr = new $*1_ltype(*$1);
+    $result = SWIG_NewPointerObj((void*)(resultptr), $1_descriptor, 1);
+}
 
 
 //---------------------------------------------------------------------------