]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/drawlist.cpp
'[1219035] cleanup: miscellaneous' and minor source cleaning.
[wxWidgets.git] / wxPython / src / drawlist.cpp
index f05bf8b3dd86fa8d47dbd48c984dcaf1ace04f7b..c89342ac84dd5d0ee4186e24824872dc08eb2b7c 100644 (file)
 #include "wx/wxPython/pydrawxxx.h"
 
 
 #include "wx/wxPython/pydrawxxx.h"
 
 
-//----------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
 
 
 
+// Called from _gdiinit so we can do the API import while the GIL is held
+void wxPyDrawList_SetAPIPtr()
+{
+    wxPyCoreAPI_IMPORT();
+}
 
 
-PyObject* wxPyDrawXXXList(wxDC& dc, wxPyDrawListOp_t doDraw,
-                          PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) {
 
 
-    wxPyBeginBlockThreads(); 
+PyObject* wxPyDrawXXXList(wxDC& dc, wxPyDrawListOp_t doDraw,
+                          PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
+{
+    wxPyBlock_t blocked = wxPyBeginBlockThreads(); 
 
 
-    if ( !wxPyCoreAPIPtr)
-        wxPyCoreAPI_IMPORT();
-    
     bool      isFastSeq  = PyList_Check(pyCoords) || PyTuple_Check(pyCoords);
     bool      isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
     bool      isFastBrushes = PyList_Check(pyBrushes) || PyTuple_Check(pyBrushes);
     bool      isFastSeq  = PyList_Check(pyCoords) || PyTuple_Check(pyCoords);
     bool      isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
     bool      isFastBrushes = PyList_Check(pyBrushes) || PyTuple_Check(pyBrushes);
@@ -135,81 +138,85 @@ PyObject* wxPyDrawXXXList(wxDC& dc, wxPyDrawListOp_t doDraw,
 
 
  exit:
 
 
  exit:
-    wxPyEndBlockThreads();
+    wxPyEndBlockThreads(blocked);
     return retval;
 }
 
 
 
     return retval;
 }
 
 
 
-bool wxPyDrawXXXPoint(wxDC& dc, PyObject* coords) {
+bool wxPyDrawXXXPoint(wxDC& dc, PyObject* coords)
+{
     int x, y;
 
     if (! wxPy2int_seq_helper(coords, &x, &y)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
     int x, y;
 
     if (! wxPy2int_seq_helper(coords, &x, &y)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
-        return FALSE;
+        return false;
     }
     dc.DrawPoint(x, y);
     }
     dc.DrawPoint(x, y);
-    return TRUE;
+    return true;
 }
 
 }
 
-bool wxPyDrawXXXLine(wxDC& dc, PyObject* coords) {
+bool wxPyDrawXXXLine(wxDC& dc, PyObject* coords)
+{
     int x1, y1, x2, y2;
 
     if (! wxPy4int_seq_helper(coords, &x1, &y1, &x2, &y2)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x1,y2) sequences.");
     int x1, y1, x2, y2;
 
     if (! wxPy4int_seq_helper(coords, &x1, &y1, &x2, &y2)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x1,y2) sequences.");
-        return FALSE;
+        return false;
     }
     dc.DrawLine(x1,y1, x2,y2);
     }
     dc.DrawLine(x1,y1, x2,y2);
-    return TRUE;
+    return true;
 }
 
 }
 
-bool wxPyDrawXXXRectangle(wxDC& dc, PyObject* coords) {
+bool wxPyDrawXXXRectangle(wxDC& dc, PyObject* coords)
+{
     int x, y, w, h;
 
     if (! wxPy4int_seq_helper(coords, &x, &y, &w, &h)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y, w,h) sequences.");
     int x, y, w, h;
 
     if (! wxPy4int_seq_helper(coords, &x, &y, &w, &h)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y, w,h) sequences.");
-        return FALSE;
+        return false;
     }
     dc.DrawRectangle(x, y, w, h);
     }
     dc.DrawRectangle(x, y, w, h);
-    return TRUE;
+    return true;
 }
 
 }
 
-bool wxPyDrawXXXEllipse(wxDC& dc, PyObject* coords) {
+bool wxPyDrawXXXEllipse(wxDC& dc, PyObject* coords)
+{
     int x, y, w, h;
 
     if (! wxPy4int_seq_helper(coords, &x, &y, &w, &h)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y, w,h) sequences.");
     int x, y, w, h;
 
     if (! wxPy4int_seq_helper(coords, &x, &y, &w, &h)) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y, w,h) sequences.");
-        return FALSE;
+        return false;
     }
     dc.DrawEllipse(x, y, w, h);
     }
     dc.DrawEllipse(x, y, w, h);
-    return TRUE;
+    return true;
 }
 
 
 }
 
 
-bool wxPyDrawXXXPolygon(wxDC& dc, PyObject* coords) {
+bool wxPyDrawXXXPolygon(wxDC& dc, PyObject* coords)
+{
     wxPoint* points;
     int numPoints;
 
     points = wxPoint_LIST_helper(coords, &numPoints);
     if (! points) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of sequences of (x,y) sequences.");
     wxPoint* points;
     int numPoints;
 
     points = wxPoint_LIST_helper(coords, &numPoints);
     if (! points) {
         PyErr_SetString(PyExc_TypeError, "Expected a sequence of sequences of (x,y) sequences.");
-        return FALSE;
+        return false;
     }
     dc.DrawPolygon(numPoints, points);
     }
     dc.DrawPolygon(numPoints, points);
-    return TRUE;
+    delete [] points;
+    return true;
 }
 
 
 }
 
 
-//----------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
 
 
 
 
 
-PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints, PyObject* foregroundList, PyObject* backgroundList) {
-    wxPyBeginBlockThreads();
+PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints, PyObject* foregroundList, PyObject* backgroundList)
+{
+    wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 
-    if ( !wxPyCoreAPIPtr)
-        wxPyCoreAPI_IMPORT();
-    
     bool      isFastSeq  = PyList_Check(pyPoints) || PyTuple_Check(pyPoints);
     bool      isFastText = PyList_Check(textList) || PyTuple_Check(textList);
     bool      isFastForeground = PyList_Check(foregroundList) || PyTuple_Check(foregroundList);
     bool      isFastSeq  = PyList_Check(pyPoints) || PyTuple_Check(pyPoints);
     bool      isFastText = PyList_Check(textList) || PyTuple_Check(textList);
     bool      isFastForeground = PyList_Check(foregroundList) || PyTuple_Check(foregroundList);
@@ -251,7 +258,7 @@ PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints, PyO
             else {
                 obj = PySequence_GetItem(textList, i);
             }
             else {
                 obj = PySequence_GetItem(textList, i);
             }
-            if (! PyString_Check(obj) ) {
+            if (! PyString_Check(obj) && !PyUnicode_Check(obj) ) {
                 Py_DECREF(obj);
                 goto err1;
             }
                 Py_DECREF(obj);
                 goto err1;
             }
@@ -268,7 +275,7 @@ PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints, PyO
             else {
                 obj = PySequence_GetItem(foregroundList, i);
             }
             else {
                 obj = PySequence_GetItem(foregroundList, i);
             }
-            if (! wxPyConvertSwigPtr(obj, (void **) &color, wxT("wxColour_p"))) {
+            if (! wxPyConvertSwigPtr(obj, (void **) &color, wxT("wxColour"))) {
                 if (!isFastForeground)
                     Py_DECREF(obj);
                 goto err2;
                 if (!isFastForeground)
                     Py_DECREF(obj);
                 goto err2;
@@ -347,10 +354,10 @@ PyObject* wxPyDrawTextList(wxDC& dc, PyObject* textList, PyObject* pyPoints, PyO
     goto exit;
 
  exit:
     goto exit;
 
  exit:
-    wxPyEndBlockThreads();
+    wxPyEndBlockThreads(blocked);
     return retval;
 }
 
 
 
     return retval;
 }
 
 
 
-//----------------------------------------------------------------------
+//---------------------------------------------------------------------------