]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/gdi.i
Changes needed to solve wxPython's OOR problem for the wxOGL shapes.
[wxWidgets.git] / wxPython / src / gdi.i
index f80dd7e1caca279ebc25c9340925c3c464eaaef4..5d0cdaf57e6edf1247cf438ab04a4532665acf36 100644 (file)
 
 %{
 #include "helpers.h"
-#include <wx/metafile.h>
 #include <wx/imaglist.h>
-#ifndef __WXMSW__
-#include <wx/dcps.h>
-#endif
 #include <wx/fontmap.h>
 #include <wx/fontenc.h>
 #include <wx/fontmap.h>
@@ -58,13 +54,13 @@ public:
 class wxBitmap : public wxGDIObject
 {
 public:
-    wxBitmap(const wxString& name, wxBitmapType type);
+    wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_BMP);
     ~wxBitmap();
 
     wxPalette* GetPalette();
     wxMask* GetMask();
-    bool LoadFile(const wxString& name, long flags);
-    bool SaveFile(const wxString& name, int type, wxPalette* palette = NULL);
+    bool LoadFile(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_BMP);
+    bool SaveFile(const wxString& name, wxBitmapType type, wxPalette* palette = NULL);
     void SetMask(wxMask* mask);
 #ifdef __WXMSW__
     void SetPalette(wxPalette& palette);
@@ -366,6 +362,10 @@ enum wxFontEncoding
     wxFONTENCODING_CP866,           // and another one
         // and for Windows
     wxFONTENCODING_CP874,           // WinThai
+    wxFONTENCODING_CP932,           // Japanese (shift-JIS)
+    wxFONTENCODING_CP936,           // Chiniese simplified (GB)
+    wxFONTENCODING_CP949,           // Korean (Hangul charset)
+    wxFONTENCODING_CP950,           // Chinese (traditional - Big5)
     wxFONTENCODING_CP1250,          // WinLatin2
     wxFONTENCODING_CP1251,          // WinCyrillic
     wxFONTENCODING_CP1252,          // WinLatin1
@@ -543,6 +543,8 @@ public:
                               bool underline = FALSE, const char* facename = NULL,
                               wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
     void RemoveFont(wxFont *font);
+
+    int GetCount();
 };
 
 
@@ -628,6 +630,11 @@ public:
 
 
 
+
+// The list of ints for the dashes needs to exist for the life of the pen
+// so we make it part of the class to save it.  wxPyPen is aliased to wxPen
+// in _extras.py
+
 %{
 class wxPyPen : public wxPen {
 public:
@@ -636,13 +643,16 @@ public:
         { m_dash = NULL; }
     ~wxPyPen() {
         if (m_dash)
-            delete m_dash;
+            delete [] m_dash;
     }
 
     void SetDashes(int nb_dashes, const wxDash *dash) {
+        if (m_dash)
+            delete [] m_dash;
         m_dash = new wxDash[nb_dashes];
-        for (int i=0; i<nb_dashes; i++)
+        for (int i=0; i<nb_dashes; i++) {
             m_dash[i] = dash[i];
+        }
         wxPen::SetDashes(nb_dashes, m_dash);
     }
 
@@ -652,7 +662,6 @@ private:
 %}
 
 
-
 class wxPyPen : public wxPen {
 public:
     wxPyPen(wxColour& colour, int width=1, int style=wxSOLID);
@@ -663,12 +672,15 @@ public:
 
 
 
+
 class wxPenList : public wxObject {
 public:
 
     void AddPen(wxPen* pen);
     wxPen* FindOrCreatePen(const wxColour& colour, int width, int style);
     void RemovePen(wxPen* pen);
+
+    int GetCount();
 };
 
 
@@ -696,6 +708,8 @@ public:
     void AddBrush(wxBrush *brush);
     wxBrush * FindOrCreateBrush(const wxColour& colour, int style);
     void RemoveBrush(wxBrush *brush);
+
+    int GetCount();
 };
 
 //----------------------------------------------------------------------
@@ -818,12 +832,202 @@ public:
     void CalcBoundingBox(int x, int y);
     void ResetBoundingBox();
 
+    %addmethods {
+        void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT);
+        // See below for implementation
+    }
+
 #ifdef __WXMSW__
     long GetHDC();
 #endif
+
+
+    %addmethods {
+        // NOTE: These methods are VERY SIMILAR in implentation.  It would be
+        // nice to factor out common code and or turn them into a set of
+        // template-like macros.
+
+        // Draw a point for every set of coordinants in pyPoints, optionally
+        // setting a new pen for each
+        PyObject* _DrawPointList(PyObject* pyPoints, PyObject* pyPens) {
+            bool      isFastSeq  = PyList_Check(pyPoints) || PyTuple_Check(pyPoints);
+            bool      isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
+            int       numObjs = 0;
+            int       numPens = 0;
+            wxPen*    pen;
+            PyObject* obj;
+            int       x1, y1;
+            int       i = 0;
+
+            if (!PySequence_Check(pyPoints)) {
+                goto err0;
+            }
+            if (!PySequence_Check(pyPens)) {
+                goto err1;
+            }
+            numObjs = PySequence_Length(pyPoints);
+            numPens = PySequence_Length(pyPens);
+
+            for (i = 0; i < numObjs; i++) {
+                // Use a new pen?
+                if (i < numPens) {
+                    if (isFastPens) {
+                        obj = PySequence_Fast_GET_ITEM(pyPens, i);
+                    }
+                    else {
+                        obj = PySequence_GetItem(pyPens, i);
+                    }
+                    if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
+                        if (!isFastPens)
+                            Py_DECREF(obj);
+                        goto err1;
+                    }
+
+                    self->SetPen(*pen);
+                    if (!isFastPens)
+                        Py_DECREF(obj);
+                }
+
+                // Get the point coordinants
+                if (isFastSeq) {
+                    obj = PySequence_Fast_GET_ITEM(pyPoints, i);
+                }
+                else {
+                    obj = PySequence_GetItem(pyPoints, i);
+                }
+                if (! _2int_seq_helper(obj, &x1, &y1)) {
+                    if (!isFastPens)
+                        Py_DECREF(obj);
+                    goto err0;
+                }
+
+                // Now draw the point
+                self->DrawPoint(x1, y1);
+
+                if (!isFastSeq)
+                    Py_DECREF(obj);
+            }
+
+            Py_INCREF(Py_None);
+            return Py_None;
+
+        err1:
+            PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
+            return NULL;
+        err0:
+            PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
+            return NULL;
+        }
+
+
+        // Draw a line for every set of coordinants in pyLines, optionally
+        // setting a new pen for each
+        PyObject* _DrawLineList(PyObject* pyLines, PyObject* pyPens) {
+            bool      isFastSeq  = PyList_Check(pyLines) || PyTuple_Check(pyLines);
+            bool      isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
+            int       numObjs = 0;
+            int       numPens = 0;
+            wxPen*    pen;
+            PyObject* obj;
+            int       x1, y1, x2, y2;
+            int       i = 0;
+
+            if (!PySequence_Check(pyLines)) {
+                goto err0;
+            }
+            if (!PySequence_Check(pyPens)) {
+                goto err1;
+            }
+            numObjs = PySequence_Length(pyLines);
+            numPens = PySequence_Length(pyPens);
+
+            for (i = 0; i < numObjs; i++) {
+                // Use a new pen?
+                if (i < numPens) {
+                    if (isFastPens) {
+                        obj = PySequence_Fast_GET_ITEM(pyPens, i);
+                    }
+                    else {
+                        obj = PySequence_GetItem(pyPens, i);
+                    }
+                    if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
+                        if (!isFastPens)
+                            Py_DECREF(obj);
+                        goto err1;
+                    }
+
+                    self->SetPen(*pen);
+                    if (!isFastPens)
+                        Py_DECREF(obj);
+                }
+
+                // Get the line coordinants
+                if (isFastSeq) {
+                    obj = PySequence_Fast_GET_ITEM(pyLines, i);
+                }
+                else {
+                    obj = PySequence_GetItem(pyLines, i);
+                }
+                if (! _4int_seq_helper(obj, &x1, &y1, &x2, &y2)) {
+                    if (!isFastPens)
+                        Py_DECREF(obj);
+                    goto err0;
+                }
+
+                // Now draw the line
+                self->DrawLine(x1, y1, x2, y2);
+
+                if (!isFastSeq)
+                    Py_DECREF(obj);
+            }
+
+            Py_INCREF(Py_None);
+            return Py_None;
+
+        err1:
+            PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
+            return NULL;
+        err0:
+            PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x2,y2) sequences.");
+            return NULL;
+        }
+    }
+
+
+    %pragma(python) addtoclass = "
+    def DrawPointList(self, points, pens=None):
+        if pens is None:
+           pens = []
+        elif isinstance(pens, wxPenPtr):
+           pens = [pens]
+        elif len(pens) != len(points):
+           raise ValueError('points and pens must have same length')
+        return self._DrawPointList(points, pens)
+
+    def DrawLineList(self, lines, pens=None):
+        if pens is None:
+           pens = []
+        elif isinstance(pens, wxPenPtr):
+           pens = [pens]
+        elif len(pens) != len(lines):
+           raise ValueError('lines and pens must have same length')
+        return self._DrawLineList(lines, pens)
+"
+
+
 };
 
 
+
+%{
+static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) {
+    *x1 = dc->MinX();
+    *y1 = dc->MinY();
+    *x2 = dc->MaxX();
+    *y2 = dc->MaxY();
+}
+%}
+
 //----------------------------------------------------------------------
 
 class wxMemoryDC : public wxDC {
@@ -875,22 +1079,41 @@ public:
 
 //---------------------------------------------------------------------------
 
-#ifndef __WXMSW__
-class wxPostScriptDC : public wxDC {
+
+#ifdef __WXMSW__
+
+%{
+#include <wx/metafile.h>
+%}
+
+class wxMetaFile : public wxObject {
 public:
-      wxPostScriptDC(const wxString& output, bool interactive = TRUE, wxWindow* win = NULL);
+    wxMetaFile(const wxString& filename = wxPyEmptyStr);
+    ~wxMetaFile();
+
+    bool Ok();
+    bool SetClipboard(int width = 0, int height = 0);
+
+    wxSize GetSize();
+    int GetWidth();
+    int GetHeight();
+
+    const wxString& GetFileName() const { return m_filename; }
+
 };
-#endif
 
-//---------------------------------------------------------------------------
+// bool wxMakeMetaFilePlaceable(const wxString& filename,
+//                              int minX, int minY, int maxX, int maxY, float scale=1.0);
 
 
-#ifdef __WXMSW__
 class wxMetaFileDC : public wxDC {
 public:
-    wxMetaFileDC(const wxString& filename = wxPyEmptyStr);
+    wxMetaFileDC(const wxString& filename = wxPyEmptyStr,
+                 int width = 0, int height = 0,
+                 const wxString& description = wxPyEmptyStr);
     wxMetaFile* Close();
 };
+
 #endif
 
 //---------------------------------------------------------------------------