]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/grid.i
wxUniversal fixes:
[wxWidgets.git] / wxPython / src / grid.i
index b5af636a9d16f50f285a2bd5a974ffce262773e4..f09c7d064238e2f97ee904b6f42890c21a0da19d 100644 (file)
@@ -40,6 +40,8 @@
 %{
     // Put some wx default wxChar* values into wxStrings.
     DECLARE_DEF_STRING(PanelNameStr);
 %{
     // Put some wx default wxChar* values into wxStrings.
     DECLARE_DEF_STRING(PanelNameStr);
+    DECLARE_DEF_STRING2(DateTimeFormatStr, wxT("%c"));
+    static const wxString wxPyEmptyString(wxT(""));
 %}
 
 //---------------------------------------------------------------------------
 %}
 
 //---------------------------------------------------------------------------
 %}
 
 //---------------------------------------------------------------------------
 %}
 
 //---------------------------------------------------------------------------
+// OOR related typemaps and helper functions
 
 
-class wxGridCellCoords;
-class wxGridCellAttr;
+%typemap(python, out) wxGridCellRenderer*     { $target = wxPyMake_wxGridCellRenderer($source); }
+%typemap(python, out) wxGridCellEditor*       { $target = wxPyMake_wxGridCellEditor($source); }
+%typemap(python, out) wxGridCellAttr*         { $target = wxPyMake_wxGridCellAttr($source); }
+%typemap(python, out) wxGridCellAttrProvider* { $target = wxPyMake_wxGridCellAttrProvider($source); }
+%typemap(python, out) wxGridTableBase*        { $target = wxPyMake_wxGridTableBase($source); }
+
+%{
+
+
+#define wxPyMake_TEMPLATE(TYPE) \
+PyObject* wxPyMake_##TYPE(TYPE* source) { \
+    PyObject* target = NULL; \
+    if (source) { \
+        /* Check if there is already a pointer to a Python object in the \
+           OOR data that we can use. */ \
+        wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
+        if (data) { \
+            target = data->m_obj; \
+            Py_INCREF(target); \
+        } \
+        /* Otherwise make a new wrapper for it the old fashioned way and \
+           give it the OOR treatment */ \
+        if (! target) { \
+            target = wxPyConstructObject(source, #TYPE, FALSE); \
+            if (target) \
+                source->SetClientObject(new wxPyOORClientData(target)); \
+        } \
+    } else {  /* source was NULL so return None. */ \
+        Py_INCREF(Py_None); target = Py_None; \
+    } \
+    return target; \
+} \
+
+wxPyMake_TEMPLATE(wxGridCellRenderer)
+wxPyMake_TEMPLATE(wxGridCellEditor)
+wxPyMake_TEMPLATE(wxGridCellAttr)
+wxPyMake_TEMPLATE(wxGridCellAttrProvider)
+wxPyMake_TEMPLATE(wxGridTableBase)
+
+%}
 
 
+//---------------------------------------------------------------------------
 
 
+class wxGridCellCoords;
+class wxGridCellAttr;
 
 #define wxGRID_VALUE_STRING     "string"
 #define wxGRID_VALUE_BOOL       "bool"
 
 #define wxGRID_VALUE_STRING     "string"
 #define wxGRID_VALUE_BOOL       "bool"
@@ -460,6 +504,9 @@ class wxGridCellAttr;
 #define wxGRID_VALUE_CHOICE     "choice"
 #define wxGRID_VALUE_TEXT       "string"
 #define wxGRID_VALUE_LONG       "long"
 #define wxGRID_VALUE_CHOICE     "choice"
 #define wxGRID_VALUE_TEXT       "string"
 #define wxGRID_VALUE_LONG       "long"
+#define wxGRID_VALUE_CHOICEINT  "choiceint"
+#define wxGRID_VALUE_DATETIME   "datetime"
+
 
 %readonly
 wxGridCellCoords wxGridNoCellCoords;
 
 %readonly
 wxGridCellCoords wxGridNoCellCoords;
@@ -475,6 +522,12 @@ wxRect           wxGridNoCellRect;
 class wxGridCellRenderer
 {
 public:
 class wxGridCellRenderer
 {
 public:
+    %addmethods {
+        void _setOORInfo(PyObject* _self) {
+            self->SetClientObject(new wxPyOORClientData(_self));
+        }
+    }
+
     void SetParameters(const wxString& params);
     void IncRef();
     void DecRef();
     void SetParameters(const wxString& params);
     void IncRef();
     void DecRef();
@@ -531,8 +584,23 @@ public:
                               wxPyConstructObject((void*)&dc,   "wxDC", 0),
                               row, col));
             if (ro) {
                               wxPyConstructObject((void*)&dc,   "wxDC", 0),
                               row, col));
             if (ro) {
-                if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p"))
+                const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
+                if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) {
                     rval = *ptr;
                     rval = *ptr;
+                }
+                else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
+                    PyObject* o1 = PySequence_GetItem(ro, 0);
+                    PyObject* o2 = PySequence_GetItem(ro, 1);
+                    if (PyNumber_Check(o1) && PyNumber_Check(o2))
+                        rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
+                    else
+                        PyErr_SetString(PyExc_TypeError, errmsg);
+                    Py_DECREF(o1);
+                    Py_DECREF(o2);
+                }
+                else {
+                    PyErr_SetString(PyExc_TypeError, errmsg);
+                }
                 Py_DECREF(ro);
             }
         }
                 Py_DECREF(ro);
             }
         }
@@ -574,6 +642,7 @@ public:
     wxPyGridCellRenderer();
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
     wxPyGridCellRenderer();
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
     void base_SetParameters(const wxString& params);
 };
 
     void base_SetParameters(const wxString& params);
 };
@@ -585,6 +654,7 @@ class wxGridCellStringRenderer : public wxGridCellRenderer
 {
 public:
     wxGridCellStringRenderer();
 {
 public:
     wxGridCellStringRenderer();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -592,6 +662,7 @@ class  wxGridCellNumberRenderer : public wxGridCellStringRenderer
 {
 public:
     wxGridCellNumberRenderer();
 {
 public:
     wxGridCellNumberRenderer();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -599,6 +670,7 @@ class  wxGridCellFloatRenderer : public wxGridCellStringRenderer
 {
 public:
     wxGridCellFloatRenderer(int width = -1, int precision = -1);
 {
 public:
     wxGridCellFloatRenderer(int width = -1, int precision = -1);
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
     int GetWidth() const;
     void SetWidth(int width);
 
     int GetWidth() const;
     void SetWidth(int width);
@@ -611,21 +683,24 @@ class  wxGridCellBoolRenderer : public wxGridCellRenderer
 {
 public:
     wxGridCellBoolRenderer();
 {
 public:
     wxGridCellBoolRenderer();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
 {
 public:
 };
 
 
 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
 {
 public:
-    wxGridCellDateTimeRenderer(wxString outformat = "%c",
-                               wxString informat =  "%c");
+    wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
+                               wxString informat =  wxPyDateTimeFormatStr);
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
 {
 public:
 };
 
 
 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
 {
 public:
-    wxGridCellEnumRenderer( const wxString& choices = "" );
+    wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -633,6 +708,7 @@ class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
 {
 public:
     wxGridCellAutoWrapStringRenderer();
 {
 public:
     wxGridCellAutoWrapStringRenderer();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -643,6 +719,12 @@ public:
 class  wxGridCellEditor
 {
 public:
 class  wxGridCellEditor
 {
 public:
+    %addmethods {
+        void _setOORInfo(PyObject* _self) {
+            self->SetClientObject(new wxPyOORClientData(_self));
+        }
+    }
+
     bool IsCreated();
     wxControl* GetControl();
     void SetControl(wxControl* control);
     bool IsCreated();
     wxControl* GetControl();
     void SetControl(wxControl* control);
@@ -797,6 +879,7 @@ public:
     wxPyGridCellEditor();
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
     wxPyGridCellEditor();
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
     void base_SetSize(const wxRect& rect);
     void base_Show(bool show, wxGridCellAttr *attr = NULL);
 
     void base_SetSize(const wxRect& rect);
     void base_Show(bool show, wxGridCellAttr *attr = NULL);
@@ -816,6 +899,7 @@ class wxGridCellTextEditor : public wxGridCellEditor
 {
 public:
     wxGridCellTextEditor();
 {
 public:
     wxGridCellTextEditor();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -823,6 +907,7 @@ class wxGridCellNumberEditor : public wxGridCellTextEditor
 {
 public:
     wxGridCellNumberEditor(int min = -1, int max = -1);
 {
 public:
     wxGridCellNumberEditor(int min = -1, int max = -1);
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -830,6 +915,7 @@ class wxGridCellFloatEditor : public wxGridCellTextEditor
 {
 public:
     wxGridCellFloatEditor();
 {
 public:
     wxGridCellFloatEditor();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -837,6 +923,7 @@ class wxGridCellBoolEditor : public wxGridCellEditor
 {
 public:
     wxGridCellBoolEditor();
 {
 public:
     wxGridCellBoolEditor();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 class wxGridCellChoiceEditor : public wxGridCellEditor
 };
 
 class wxGridCellChoiceEditor : public wxGridCellEditor
@@ -845,13 +932,15 @@ public:
     wxGridCellChoiceEditor(int LCOUNT = 0,
                            const wxString* choices = NULL,
                            bool allowOthers = FALSE);
     wxGridCellChoiceEditor(int LCOUNT = 0,
                            const wxString* choices = NULL,
                            bool allowOthers = FALSE);
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
 {
 public:
 };
 
 
 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
 {
 public:
-    wxGridCellEnumEditor( const wxString& choices = "" );
+    wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -859,6 +948,7 @@ class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
 {
 public:
     wxGridCellAutoWrapStringEditor();
 {
 public:
     wxGridCellAutoWrapStringEditor();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 
 };
 
 
@@ -879,7 +969,14 @@ public:
         Merged
     };
 
         Merged
     };
 
+    %addmethods {
+        void _setOORInfo(PyObject* _self) {
+            self->SetClientObject(new wxPyOORClientData(_self));
+        }
+    }
+
     wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
     wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
     wxGridCellAttr *Clone() const;
     void MergeWith(wxGridCellAttr *mergefrom);
 
     wxGridCellAttr *Clone() const;
     void MergeWith(wxGridCellAttr *mergefrom);
@@ -921,6 +1018,13 @@ class wxGridCellAttrProvider
 public:
     wxGridCellAttrProvider();
     // ???? virtual ~wxGridCellAttrProvider();
 public:
     wxGridCellAttrProvider();
     // ???? virtual ~wxGridCellAttrProvider();
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
+
+    %addmethods {
+        void _setOORInfo(PyObject* _self) {
+            self->SetClientObject(new wxPyOORClientData(_self));
+        }
+    }
 
     wxGridCellAttr *GetAttr(int row, int col,
                             wxGridCellAttr::wxAttrKind  kind) const;
 
     wxGridCellAttr *GetAttr(int row, int col,
                             wxGridCellAttr::wxAttrKind  kind) const;
@@ -971,13 +1075,18 @@ public:
 // Grid Table Base class and Python aware version
 
 
 // Grid Table Base class and Python aware version
 
 
-
 class wxGridTableBase : public wxObject
 {
 public:
     // wxGridTableBase();   This is an ABC
     //~wxGridTableBase();
 
 class wxGridTableBase : public wxObject
 {
 public:
     // wxGridTableBase();   This is an ABC
     //~wxGridTableBase();
 
+    %addmethods {
+        void _setOORInfo(PyObject* _self) {
+            self->SetClientObject(new wxPyOORClientData(_self));
+        }
+    }
+
     void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
     wxGridCellAttrProvider *GetAttrProvider() const;
     void SetView( wxGrid *grid );
     void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
     wxGridCellAttrProvider *GetAttrProvider() const;
     void SetView( wxGrid *grid );
@@ -1165,6 +1274,7 @@ public:
     wxPyGridTableBase();
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
     wxPyGridTableBase();
     void _setCallbackInfo(PyObject* self, PyObject* _class);
     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
     %addmethods { void Destroy() { delete self; } }
 
 
     %addmethods { void Destroy() { delete self; } }
 
@@ -1198,6 +1308,7 @@ class  wxGridStringTable : public wxGridTableBase
 {
 public:
     wxGridStringTable( int numRows=0, int numCols=0 );
 {
 public:
     wxGridStringTable( int numRows=0, int numCols=0 );
+    %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 };
 
 //---------------------------------------------------------------------------
 };
 
 //---------------------------------------------------------------------------