1 ////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the new wxGrid and related classes
7 // Created: 17-March-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
20 #include <wx/generic/gridctrl.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
36 %pragma(python) code = "import wx"
38 //----------------------------------------------------------------------
41 // Put some wx default wxChar* values into wxStrings.
42 DECLARE_DEF_STRING(PanelNameStr);
43 DECLARE_DEF_STRING2(DateTimeFormatStr, wxT("%c"));
44 static const wxString wxPyEmptyString(wxT(""));
47 //---------------------------------------------------------------------------
48 // OOR related typemaps and helper functions
50 %typemap(python, out) wxGridCellRenderer* { $target = wxPyMake_wxGridCellRenderer($source); }
51 %typemap(python, out) wxGridCellEditor* { $target = wxPyMake_wxGridCellEditor($source); }
52 %typemap(python, out) wxGridCellAttr* { $target = wxPyMake_wxGridCellAttr($source); }
53 %typemap(python, out) wxGridCellAttrProvider* { $target = wxPyMake_wxGridCellAttrProvider($source); }
54 %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxGridTableBase($source); }
59 #define wxPyMake_TEMPLATE(TYPE) \
60 PyObject* wxPyMake_##TYPE(TYPE* source) { \
61 PyObject* target = NULL; \
63 /* Check if there is already a pointer to a Python object in the \
64 OOR data that we can use. */ \
65 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
67 target = data->m_obj; \
70 /* Otherwise make a new wrapper for it the old fashioned way and \
71 give it the OOR treatment */ \
73 target = wxPyConstructObject(source, wxT(#TYPE), FALSE); \
75 source->SetClientObject(new wxPyOORClientData(target)); \
77 } else { /* source was NULL so return None. */ \
78 Py_INCREF(Py_None); target = Py_None; \
84 wxPyMake_TEMPLATE(wxGridCellRenderer)
85 wxPyMake_TEMPLATE(wxGridCellEditor)
86 wxPyMake_TEMPLATE(wxGridCellAttr)
87 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
88 wxPyMake_TEMPLATE(wxGridTableBase)
92 //---------------------------------------------------------------------------
93 // Macros, similar to what's in helpers.h, to aid in the creation of
94 // virtual methods that are able to make callbacks to Python. Many of these
95 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
100 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
101 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
102 wxGridCellAttr* rval = NULL; \
104 wxPyBeginBlockThreads(); \
105 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
107 wxGridCellAttr* ptr; \
108 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
110 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellAttr_p")) \
115 wxPyEndBlockThreads(); \
117 rval = PCLASS::CBNAME(a, b, c); \
120 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
121 return PCLASS::CBNAME(a, b, c); \
126 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
127 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
128 wxPyBeginBlockThreads(); \
130 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
131 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
132 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
135 wxPyEndBlockThreads(); \
137 PCLASS::CBNAME(attr, a, b); \
139 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
140 PCLASS::CBNAME(attr, a, b); \
145 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
146 void CBNAME(wxGridCellAttr *attr, int val) { \
147 wxPyBeginBlockThreads(); \
149 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
150 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
151 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
154 wxPyEndBlockThreads(); \
156 PCLASS::CBNAME(attr, val); \
158 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
159 PCLASS::CBNAME(attr, val); \
164 #define PYCALLBACK_INT__pure(CBNAME) \
166 wxPyBeginBlockThreads(); \
168 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
169 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
170 wxPyEndBlockThreads(); \
176 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
177 bool CBNAME(int a, int b) { \
178 wxPyBeginBlockThreads(); \
180 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
181 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
182 wxPyEndBlockThreads(); \
187 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
188 wxString CBNAME(int a, int b) { \
189 wxPyBeginBlockThreads(); \
191 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
193 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
195 rval = Py2wxString(ro); \
199 wxPyEndBlockThreads(); \
204 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
205 void CBNAME(int a, int b, const wxString& c) { \
206 wxPyBeginBlockThreads(); \
207 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
208 PyObject* s = wx2PyString(c); \
209 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
212 wxPyEndBlockThreads(); \
216 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
217 wxString CBNAME(int a, int b) { \
219 wxPyBeginBlockThreads(); \
221 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
223 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
225 rval = Py2wxString(ro); \
229 wxPyEndBlockThreads(); \
231 rval = PCLASS::CBNAME(a, b); \
234 wxString base_##CBNAME(int a, int b) { \
235 return PCLASS::CBNAME(a, b); \
239 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
240 bool CBNAME(int a, int b, const wxString& c) { \
243 wxPyBeginBlockThreads(); \
244 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
245 PyObject* s = wx2PyString(c); \
246 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
249 wxPyEndBlockThreads(); \
251 rval = PCLASS::CBNAME(a,b,c); \
254 bool base_##CBNAME(int a, int b, const wxString& c) { \
255 return PCLASS::CBNAME(a,b,c); \
261 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
262 long CBNAME(int a, int b) { \
265 wxPyBeginBlockThreads(); \
266 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
267 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
268 wxPyEndBlockThreads(); \
270 rval = PCLASS::CBNAME(a,b); \
273 long base_##CBNAME(int a, int b) { \
274 return PCLASS::CBNAME(a,b); \
279 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
280 bool CBNAME(int a, int b) { \
283 wxPyBeginBlockThreads(); \
284 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
285 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
286 wxPyEndBlockThreads(); \
288 rval = PCLASS::CBNAME(a,b); \
291 bool base_##CBNAME(int a, int b) { \
292 return PCLASS::CBNAME(a,b); \
297 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
298 double CBNAME(int a, int b) { \
300 wxPyBeginBlockThreads(); \
302 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
304 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
306 PyObject* str = PyObject_Str(ro); \
307 rval = PyFloat_AsDouble(str); \
308 Py_DECREF(ro); Py_DECREF(str); \
311 wxPyEndBlockThreads(); \
313 rval = PCLASS::CBNAME(a, b); \
316 double base_##CBNAME(int a, int b) { \
317 return PCLASS::CBNAME(a, b); \
322 #define PYCALLBACK__(PCLASS, CBNAME) \
325 wxPyBeginBlockThreads(); \
326 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
327 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
328 wxPyEndBlockThreads(); \
332 void base_##CBNAME() { \
339 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
340 bool CBNAME(size_t a, size_t b) { \
343 wxPyBeginBlockThreads(); \
344 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
345 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
346 wxPyEndBlockThreads(); \
348 rval = PCLASS::CBNAME(a,b); \
351 bool base_##CBNAME(size_t a, size_t b) { \
352 return PCLASS::CBNAME(a,b); \
357 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
358 bool CBNAME(size_t a) { \
361 wxPyBeginBlockThreads(); \
362 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
363 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
364 wxPyEndBlockThreads(); \
366 rval = PCLASS::CBNAME(a); \
369 bool base_##CBNAME(size_t a) { \
370 return PCLASS::CBNAME(a); \
374 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
375 wxString CBNAME(int a) { \
377 wxPyBeginBlockThreads(); \
379 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
381 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
383 rval = Py2wxString(ro); \
387 wxPyEndBlockThreads(); \
389 rval = PCLASS::CBNAME(a); \
392 wxString base_##CBNAME(int a) { \
393 return PCLASS::CBNAME(a); \
397 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
398 void CBNAME(int a, const wxString& c) { \
400 wxPyBeginBlockThreads(); \
401 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
402 PyObject* s = wx2PyString(c); \
403 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \
406 wxPyEndBlockThreads(); \
408 PCLASS::CBNAME(a,c); \
410 void base_##CBNAME(int a, const wxString& c) { \
411 PCLASS::CBNAME(a,c); \
417 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
421 wxPyBeginBlockThreads(); \
422 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
423 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
424 wxPyEndBlockThreads(); \
426 rval = PCLASS::CBNAME(); \
429 bool base_##CBNAME() { \
430 return PCLASS::CBNAME(); \
435 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
436 void CBNAME(size_t a, int b) { \
438 wxPyBeginBlockThreads(); \
439 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
440 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
441 wxPyEndBlockThreads(); \
443 PCLASS::CBNAME(a,b); \
445 void base_##CBNAME(size_t a, int b) { \
446 PCLASS::CBNAME(a,b); \
452 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
453 void CBNAME(int a, int b, long c) { \
455 wxPyBeginBlockThreads(); \
456 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
457 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
458 wxPyEndBlockThreads(); \
460 PCLASS::CBNAME(a,b,c); \
462 void base_##CBNAME(int a, int b, long c) { \
463 PCLASS::CBNAME(a,b,c); \
469 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
470 void CBNAME(int a, int b, double c) { \
472 wxPyBeginBlockThreads(); \
473 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
474 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
475 wxPyEndBlockThreads(); \
477 PCLASS::CBNAME(a,b,c); \
479 void base_##CBNAME(int a, int b, double c) { \
480 PCLASS::CBNAME(a,b,c); \
485 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
486 void CBNAME(int a, int b, bool c) { \
488 wxPyBeginBlockThreads(); \
489 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
490 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
491 wxPyEndBlockThreads(); \
493 PCLASS::CBNAME(a,b,c); \
495 void base_##CBNAME(int a, int b, bool c) { \
496 PCLASS::CBNAME(a,b,c); \
504 //---------------------------------------------------------------------------
506 class wxGridCellCoords;
507 class wxGridCellAttr;
509 #define wxGRID_VALUE_STRING "string"
510 #define wxGRID_VALUE_BOOL "bool"
511 #define wxGRID_VALUE_NUMBER "long"
512 #define wxGRID_VALUE_FLOAT "double"
513 #define wxGRID_VALUE_CHOICE "choice"
514 #define wxGRID_VALUE_TEXT "string"
515 #define wxGRID_VALUE_LONG "long"
516 #define wxGRID_VALUE_CHOICEINT "choiceint"
517 #define wxGRID_VALUE_DATETIME "datetime"
521 wxGridCellCoords wxGridNoCellCoords;
522 wxRect wxGridNoCellRect;
526 //---------------------------------------------------------------------------
527 // wxGridCellRenderer is an ABC, and several derived classes are available.
528 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
531 class wxGridCellRenderer
535 void _setOORInfo(PyObject* _self) {
536 self->SetClientObject(new wxPyOORClientData(_self));
540 void SetParameters(const wxString& params);
544 virtual void Draw(wxGrid& grid,
545 wxGridCellAttr& attr,
549 bool isSelected) = 0;
550 virtual wxSize GetBestSize(wxGrid& grid,
551 wxGridCellAttr& attr,
553 int row, int col) = 0;
554 virtual wxGridCellRenderer *Clone() const = 0;
558 // The C++ version of wxPyGridCellRenderer
560 class wxPyGridCellRenderer : public wxGridCellRenderer
563 wxPyGridCellRenderer() : wxGridCellRenderer() {};
565 // Implement Python callback aware virtual methods
566 void Draw(wxGrid& grid, wxGridCellAttr& attr,
567 wxDC& dc, const wxRect& rect,
568 int row, int col, bool isSelected) {
569 wxPyBeginBlockThreads();
570 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
571 PyObject* go = wxPyMake_wxObject(&grid);
572 PyObject* dco = wxPyMake_wxObject(&dc);
573 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
574 PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
576 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
577 row, col, isSelected));
583 wxPyEndBlockThreads();
586 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
589 wxPyBeginBlockThreads();
590 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
593 PyObject* go = wxPyMake_wxObject(&grid);
594 PyObject* dco = wxPyMake_wxObject(&dc);
595 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
597 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
605 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
606 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) {
609 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
610 PyObject* o1 = PySequence_GetItem(ro, 0);
611 PyObject* o2 = PySequence_GetItem(ro, 1);
612 if (PyNumber_Check(o1) && PyNumber_Check(o2))
613 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
615 PyErr_SetString(PyExc_TypeError, errmsg);
620 PyErr_SetString(PyExc_TypeError, errmsg);
625 wxPyEndBlockThreads();
630 wxGridCellRenderer *Clone() const {
631 wxGridCellRenderer* rval = NULL;
632 wxPyBeginBlockThreads();
633 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
635 wxGridCellRenderer* ptr;
636 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
638 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellRenderer_p"))
643 wxPyEndBlockThreads();
647 DEC_PYCALLBACK__STRING(SetParameters);
652 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
657 // Let SWIG know about it so it can create the Python version
658 class wxPyGridCellRenderer : public wxGridCellRenderer {
660 wxPyGridCellRenderer();
661 void _setCallbackInfo(PyObject* self, PyObject* _class);
662 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellRenderer)"
663 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
665 void base_SetParameters(const wxString& params);
668 //---------------------------------------------------------------------------
669 // Predefined Renderers
671 class wxGridCellStringRenderer : public wxGridCellRenderer
674 wxGridCellStringRenderer();
675 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
679 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
682 wxGridCellNumberRenderer();
683 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
687 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
690 wxGridCellFloatRenderer(int width = -1, int precision = -1);
691 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
693 int GetWidth() const;
694 void SetWidth(int width);
695 int GetPrecision() const;
696 void SetPrecision(int precision);
700 class wxGridCellBoolRenderer : public wxGridCellRenderer
703 wxGridCellBoolRenderer();
704 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
708 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
711 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
712 wxString informat = wxPyDateTimeFormatStr);
713 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
717 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
720 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
721 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
725 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
728 wxGridCellAutoWrapStringRenderer();
729 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
733 //---------------------------------------------------------------------------
734 // wxGridCellEditor is an ABC, and several derived classes are available.
735 // Classes implemented in Python should be derived from wxPyGridCellEditor.
737 class wxGridCellEditor
741 void _setOORInfo(PyObject* _self) {
742 self->SetClientObject(new wxPyOORClientData(_self));
747 wxControl* GetControl();
748 void SetControl(wxControl* control);
750 wxGridCellAttr* GetCellAttr();
751 void SetCellAttr(wxGridCellAttr* attr);
753 void SetParameters(const wxString& params);
757 virtual void Create(wxWindow* parent,
759 wxEvtHandler* evtHandler) = 0;
760 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
761 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
762 virtual void Reset() = 0;
763 virtual wxGridCellEditor *Clone() const = 0;
765 virtual void SetSize(const wxRect& rect);
766 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
767 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
768 virtual bool IsAcceptedKey(wxKeyEvent& event);
769 virtual void StartingKey(wxKeyEvent& event);
770 virtual void StartingClick();
771 virtual void HandleReturn(wxKeyEvent& event);
772 virtual void Destroy();
777 // The C++ version of wxPyGridCellEditor
779 class wxPyGridCellEditor : public wxGridCellEditor
782 wxPyGridCellEditor() : wxGridCellEditor() {}
784 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
785 wxPyBeginBlockThreads();
786 if (wxPyCBH_findCallback(m_myInst, "Create")) {
787 PyObject* po = wxPyMake_wxObject(parent);
788 PyObject* eo = wxPyMake_wxObject(evtHandler);
790 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
794 wxPyEndBlockThreads();
798 void BeginEdit(int row, int col, wxGrid* grid) {
799 wxPyBeginBlockThreads();
800 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
801 PyObject* go = wxPyMake_wxObject(grid);
802 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
805 wxPyEndBlockThreads();
809 bool EndEdit(int row, int col, wxGrid* grid) {
811 wxPyBeginBlockThreads();
812 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
813 PyObject* go = wxPyMake_wxObject(grid);
814 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
817 wxPyEndBlockThreads();
822 wxGridCellEditor* Clone() const {
823 wxGridCellEditor* rval = NULL;
824 wxPyBeginBlockThreads();
825 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
827 wxGridCellEditor* ptr;
828 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
830 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
835 wxPyEndBlockThreads();
840 void Show(bool show, wxGridCellAttr *attr) {
842 wxPyBeginBlockThreads();
843 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
844 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
845 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
848 wxPyEndBlockThreads();
850 wxGridCellEditor::Show(show, attr);
852 void base_Show(bool show, wxGridCellAttr *attr) {
853 wxGridCellEditor::Show(show, attr);
857 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
859 wxPyBeginBlockThreads();
860 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
861 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
862 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
864 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
869 wxPyEndBlockThreads();
871 wxGridCellEditor::PaintBackground(rectCell, attr);
873 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
874 wxGridCellEditor::PaintBackground(rectCell, attr);
878 DEC_PYCALLBACK___pure(Reset);
879 DEC_PYCALLBACK__constany(SetSize, wxRect);
880 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
881 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
882 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
883 DEC_PYCALLBACK__(StartingClick);
884 DEC_PYCALLBACK__(Destroy);
885 DEC_PYCALLBACK__STRING(SetParameters);
886 DEC_PYCALLBACK_STRING__constpure(GetValue);
892 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
893 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
894 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
895 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
896 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
897 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
898 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
899 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
900 IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
905 // Let SWIG know about it so it can create the Python version
906 class wxPyGridCellEditor : public wxGridCellEditor {
908 wxPyGridCellEditor();
909 void _setCallbackInfo(PyObject* self, PyObject* _class);
910 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
911 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
913 void base_SetSize(const wxRect& rect);
914 void base_Show(bool show, wxGridCellAttr *attr = NULL);
915 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
916 void base_IsAcceptedKey(wxKeyEvent& event);
917 void base_StartingKey(wxKeyEvent& event);
918 void base_StartingClick();
919 void base_HandleReturn(wxKeyEvent& event);
921 void base_SetParameters(const wxString& params);
924 //---------------------------------------------------------------------------
925 // Predefined Editors
927 class wxGridCellTextEditor : public wxGridCellEditor
930 wxGridCellTextEditor();
931 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
932 virtual wxString GetValue();
936 class wxGridCellNumberEditor : public wxGridCellTextEditor
939 wxGridCellNumberEditor(int min = -1, int max = -1);
940 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
941 virtual wxString GetValue();
945 class wxGridCellFloatEditor : public wxGridCellTextEditor
948 wxGridCellFloatEditor();
949 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
950 virtual wxString GetValue();
954 class wxGridCellBoolEditor : public wxGridCellEditor
957 wxGridCellBoolEditor();
958 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
959 virtual wxString GetValue();
962 class wxGridCellChoiceEditor : public wxGridCellEditor
965 wxGridCellChoiceEditor(int LCOUNT = 0,
966 const wxString* choices = NULL,
967 bool allowOthers = FALSE);
968 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
969 virtual wxString GetValue();
973 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
976 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
977 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
978 virtual wxString GetValue();
982 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
985 wxGridCellAutoWrapStringEditor();
986 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
987 virtual wxString GetValue();
992 //---------------------------------------------------------------------------
1009 void _setOORInfo(PyObject* _self) {
1010 self->SetClientObject(new wxPyOORClientData(_self));
1014 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1015 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1017 wxGridCellAttr *Clone() const;
1018 void MergeWith(wxGridCellAttr *mergefrom);
1021 void SetTextColour(const wxColour& colText);
1022 void SetBackgroundColour(const wxColour& colBack);
1023 void SetFont(const wxFont& font);
1024 void SetAlignment(int hAlign, int vAlign);
1025 void SetSize(int num_rows, int num_cols);
1026 void SetOverflow( bool allow );
1027 void SetReadOnly(bool isReadOnly = TRUE);
1029 void SetRenderer(wxGridCellRenderer *renderer);
1030 void SetEditor(wxGridCellEditor* editor);
1031 void SetKind(wxAttrKind kind);
1033 bool HasTextColour() const;
1034 bool HasBackgroundColour() const;
1035 bool HasFont() const;
1036 bool HasAlignment() const;
1037 bool HasRenderer() const;
1038 bool HasEditor() const;
1039 bool HasReadWriteMode() const;
1041 wxColour GetTextColour() const;
1042 wxColour GetBackgroundColour() const;
1043 wxFont GetFont() const;
1044 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
1045 void GetSize(int *num_rows, int *num_cols) const;
1046 bool GetOverflow() const;
1047 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1048 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1050 bool IsReadOnly() const;
1051 void SetDefAttr(wxGridCellAttr* defAttr);
1054 //---------------------------------------------------------------------------
1056 class wxGridCellAttrProvider
1059 wxGridCellAttrProvider();
1060 // ???? virtual ~wxGridCellAttrProvider();
1061 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1064 void _setOORInfo(PyObject* _self) {
1065 self->SetClientObject(new wxPyOORClientData(_self));
1069 wxGridCellAttr *GetAttr(int row, int col,
1070 wxGridCellAttr::wxAttrKind kind) const;
1071 void SetAttr(wxGridCellAttr *attr, int row, int col);
1072 void SetRowAttr(wxGridCellAttr *attr, int row);
1073 void SetColAttr(wxGridCellAttr *attr, int col);
1075 void UpdateAttrRows( size_t pos, int numRows );
1076 void UpdateAttrCols( size_t pos, int numCols );
1081 // A Python-aware version
1083 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1086 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1088 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1089 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1090 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1091 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1098 // The python-aware version get's SWIGified
1099 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1102 wxPyGridCellAttrProvider();
1103 void _setCallbackInfo(PyObject* self, PyObject* _class);
1104 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
1106 wxGridCellAttr *base_GetAttr(int row, int col,
1107 wxGridCellAttr::wxAttrKind kind);
1108 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1109 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1110 void base_SetColAttr(wxGridCellAttr *attr, int col);
1114 //---------------------------------------------------------------------------
1115 // Grid Table Base class and Python aware version
1118 class wxGridTableBase : public wxObject
1121 // wxGridTableBase(); This is an ABC
1122 //~wxGridTableBase();
1125 void _setOORInfo(PyObject* _self) {
1126 self->SetClientObject(new wxPyOORClientData(_self));
1130 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1131 wxGridCellAttrProvider *GetAttrProvider() const;
1132 void SetView( wxGrid *grid );
1133 wxGrid * GetView() const;
1137 virtual int GetNumberRows() = 0;
1138 virtual int GetNumberCols() = 0;
1139 virtual bool IsEmptyCell( int row, int col ) = 0;
1140 virtual wxString GetValue( int row, int col ) = 0;
1141 virtual void SetValue( int row, int col, const wxString& value ) = 0;
1143 // virtuals overridable in wxPyGridTableBase
1144 virtual wxString GetTypeName( int row, int col );
1145 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1146 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1147 virtual long GetValueAsLong( int row, int col );
1148 virtual double GetValueAsDouble( int row, int col );
1149 virtual bool GetValueAsBool( int row, int col );
1150 virtual void SetValueAsLong( int row, int col, long value );
1151 virtual void SetValueAsDouble( int row, int col, double value );
1152 virtual void SetValueAsBool( int row, int col, bool value );
1154 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1155 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1158 virtual void Clear();
1159 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1160 virtual bool AppendRows( size_t numRows = 1 );
1161 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1162 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1163 virtual bool AppendCols( size_t numCols = 1 );
1164 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1166 virtual wxString GetRowLabelValue( int row );
1167 virtual wxString GetColLabelValue( int col );
1168 virtual void SetRowLabelValue( int row, const wxString& value );
1169 virtual void SetColLabelValue( int col, const wxString& value );
1171 virtual bool CanHaveAttributes();
1173 virtual wxGridCellAttr *GetAttr( int row, int col,
1174 wxGridCellAttr::wxAttrKind kind);
1175 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1176 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1177 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1183 // Python-aware version
1185 class wxPyGridTableBase : public wxGridTableBase
1188 wxPyGridTableBase() : wxGridTableBase() {}
1190 PYCALLBACK_INT__pure(GetNumberRows);
1191 PYCALLBACK_INT__pure(GetNumberCols);
1192 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1193 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1194 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1195 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1196 PYCALLBACK__(wxGridTableBase, Clear);
1197 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1198 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1199 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1200 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1201 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1202 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1203 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1204 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1205 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1206 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1207 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1208 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1209 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1210 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1211 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1214 wxString GetValue(int row, int col) {
1215 wxPyBeginBlockThreads();
1217 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1219 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1221 rval = Py2wxString(ro);
1225 wxPyEndBlockThreads();
1229 void SetValue(int row, int col, const wxString& val) {
1230 wxPyBeginBlockThreads();
1231 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1232 PyObject* s = wx2PyString(val);
1233 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1236 wxPyEndBlockThreads();
1240 // Map the Get/Set methods for the standard non-string types to
1241 // the GetValue and SetValue python methods.
1242 long GetValueAsLong( int row, int col ) {
1244 wxPyBeginBlockThreads();
1245 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1248 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1249 if (ro && PyNumber_Check(ro)) {
1250 num = PyNumber_Int(ro);
1252 rval = PyInt_AsLong(num);
1258 wxPyEndBlockThreads();
1262 double GetValueAsDouble( int row, int col ) {
1264 wxPyBeginBlockThreads();
1265 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1268 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1269 if (ro && PyNumber_Check(ro)) {
1270 num = PyNumber_Float(ro);
1272 rval = PyFloat_AsDouble(num);
1278 wxPyEndBlockThreads();
1282 bool GetValueAsBool( int row, int col ) {
1283 return (bool)GetValueAsLong(row, col);
1286 void SetValueAsLong( int row, int col, long value ) {
1287 wxPyBeginBlockThreads();
1288 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1289 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1291 wxPyEndBlockThreads();
1294 void SetValueAsDouble( int row, int col, double value ) {
1295 wxPyBeginBlockThreads();
1296 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1297 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1299 wxPyEndBlockThreads();
1302 void SetValueAsBool( int row, int col, bool value ) {
1303 SetValueAsLong( row, col, (long)value );
1312 // The python-aware version get's SWIGified
1313 class wxPyGridTableBase : public wxGridTableBase
1316 wxPyGridTableBase();
1317 void _setCallbackInfo(PyObject* self, PyObject* _class);
1318 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1319 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1321 %addmethods { void Destroy() { delete self; } }
1323 wxString base_GetTypeName( int row, int col );
1324 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1325 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1327 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1328 bool base_AppendRows( size_t numRows = 1 );
1329 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1330 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1331 bool base_AppendCols( size_t numCols = 1 );
1332 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1333 wxString base_GetRowLabelValue( int row );
1334 wxString base_GetColLabelValue( int col );
1335 void base_SetRowLabelValue( int row, const wxString& value );
1336 void base_SetColLabelValue( int col, const wxString& value );
1337 bool base_CanHaveAttributes();
1338 wxGridCellAttr *base_GetAttr( int row, int col,
1339 wxGridCellAttr::wxAttrKind kind );
1340 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1341 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1342 void base_SetColAttr(wxGridCellAttr *attr, int col);
1346 //---------------------------------------------------------------------------
1347 // Predefined Tables
1349 class wxGridStringTable : public wxGridTableBase
1352 wxGridStringTable( int numRows=0, int numCols=0 );
1353 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1356 //---------------------------------------------------------------------------
1357 // The Table can pass messages to the grid to tell it to update itself if
1358 // something has changed.
1360 enum wxGridTableRequest
1362 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1363 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1364 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1365 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1366 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1367 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1368 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1369 wxGRIDTABLE_NOTIFY_COLS_DELETED
1373 class wxGridTableMessage
1376 wxGridTableMessage( wxGridTableBase *table, int id,
1379 ~wxGridTableMessage();
1381 void SetTableObject( wxGridTableBase *table );
1382 wxGridTableBase * GetTableObject() const;
1383 void SetId( int id );
1385 void SetCommandInt( int comInt1 );
1386 int GetCommandInt();
1387 void SetCommandInt2( int comInt2 );
1388 int GetCommandInt2();
1392 //---------------------------------------------------------------------------
1394 class wxGridCellCoords
1397 wxGridCellCoords( int r=-1, int c=-1 );
1398 ~wxGridCellCoords();
1400 int GetRow() const { return m_row; }
1401 void SetRow( int n ) { m_row = n; }
1402 int GetCol() const { return m_col; }
1403 void SetCol( int n ) { m_col = n; }
1404 void Set( int row, int col ) { m_row = row; m_col = col; }
1407 PyObject* asTuple() {
1408 PyObject* tup = PyTuple_New(2);
1409 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1410 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1414 int __cmp__( const wxGridCellCoords& other ) {
1415 return *self != other;
1418 %pragma(python) addtoclass = "
1419 def __str__(self): return str(self.asTuple())
1420 def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
1421 def __len__(self): return len(self.asTuple())
1422 def __getitem__(self, index): return self.asTuple()[index]
1423 def __setitem__(self, index, val):
1424 if index == 0: self.SetRow(val)
1425 elif index == 1: self.SetCol(val)
1426 else: raise IndexError
1431 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1432 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1434 if (! wxGridCellCoords_helper($source, &$target))
1438 // ...and here is the associated helper.
1440 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1442 // If source is an object instance then it may already be the right type
1443 if (PyInstance_Check(source)) {
1444 wxGridCellCoords* ptr;
1445 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1450 // otherwise a 2-tuple of integers is expected
1451 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1452 PyObject* o1 = PySequence_GetItem(source, 0);
1453 PyObject* o2 = PySequence_GetItem(source, 1);
1454 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1459 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1466 // Typemap to convert an array of cells coords to a list of tuples...
1467 %typemap(python, out) wxGridCellCoordsArray {
1468 $target = wxGridCellCoordsArray_helper($source);
1471 %typemap(python, ret) wxGridCellCoordsArray {
1476 // ...and the helper function for the above typemap.
1478 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray* source)
1480 PyObject* list = PyList_New(0);
1482 for (idx = 0; idx < source->GetCount(); idx += 1) {
1483 wxGridCellCoords& coord = source->Item(idx);
1484 PyObject* tup = PyTuple_New(2);
1485 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1486 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1487 PyList_Append(list, tup);
1494 //---------------------------------------------------------------------------
1495 //---------------------------------------------------------------------------
1499 // Fool SWIG into treating this enum as an int
1500 typedef int WXGRIDSELECTIONMODES;
1502 // but let the C++ code know what it really is.
1504 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1509 class wxGrid : public wxScrolledWindow
1512 wxGrid( wxWindow *parent,
1514 const wxPoint& pos = wxDefaultPosition,
1515 const wxSize& size = wxDefaultSize,
1516 long style = wxWANTS_CHARS,
1517 const wxString& name = wxPyPanelNameStr);
1519 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1521 enum wxGridSelectionModes {wxGridSelectCells,
1523 wxGridSelectColumns};
1525 bool CreateGrid( int numRows, int numCols,
1526 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1527 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1528 WXGRIDSELECTIONMODES GetSelectionMode();
1531 // ------ grid dimensions
1533 int GetNumberRows();
1534 int GetNumberCols();
1537 bool ProcessTableMessage( wxGridTableMessage& );
1540 wxGridTableBase * GetTable() const;
1541 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1542 WXGRIDSELECTIONMODES selmode =
1543 wxGrid::wxGridSelectCells );
1546 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1547 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1548 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1549 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1550 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1551 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1554 // this function is called when the current cell highlight must be redrawn
1555 // and may be overridden by the user
1556 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1559 // ------ Cell text drawing functions
1561 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1562 int horizontalAlignment = wxLEFT,
1563 int verticalAlignment = wxTOP,
1564 int textOrientation = wxHORIZONTAL );
1566 // // Split a string containing newline chararcters into an array of
1567 // // strings and return the number of lines
1569 // void StringToLines( const wxString& value, wxArrayString& lines );
1571 void GetTextBoxSize( wxDC& dc,
1572 wxArrayString& lines,
1573 long *OUTPUT, long *OUTPUT );
1577 // Code that does a lot of grid modification can be enclosed
1578 // between BeginBatch() and EndBatch() calls to avoid screen
1583 int GetBatchCount();
1584 void ForceRefresh();
1585 void Refresh(bool eraseb=TRUE, const wxRect* rect= NULL);
1588 // ------ edit control functions
1591 void EnableEditing( bool edit );
1593 void EnableCellEditControl( bool enable = TRUE );
1594 void DisableCellEditControl();
1595 bool CanEnableCellControl() const;
1596 bool IsCellEditControlEnabled() const;
1597 bool IsCellEditControlShown() const;
1599 bool IsCurrentCellReadOnly() const;
1601 void ShowCellEditControl();
1602 void HideCellEditControl();
1603 void SaveEditControlValue();
1606 // ------ grid location functions
1607 // Note that all of these functions work with the logical coordinates of
1608 // grid cells and labels so you will need to convert from device
1609 // coordinates for mouse events etc.
1612 //void XYToCell( int x, int y, wxGridCellCoords& );
1614 %new wxGridCellCoords* XYToCell(int x, int y) {
1615 wxGridCellCoords rv;
1616 self->XYToCell(x, y, rv);
1617 return new wxGridCellCoords(rv);
1621 int YToRow( int y );
1622 int XToCol( int x );
1624 int YToEdgeOfRow( int y );
1625 int XToEdgeOfCol( int x );
1627 wxRect CellToRect( int row, int col );
1628 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1631 int GetGridCursorRow();
1632 int GetGridCursorCol();
1634 // check to see if a cell is either wholly visible (the default arg) or
1635 // at least partially visible in the grid window
1637 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1638 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1639 void MakeCellVisible( int row, int col );
1640 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1643 // ------ grid cursor movement functions
1645 void SetGridCursor( int row, int col );
1646 bool MoveCursorUp( bool expandSelection );
1647 bool MoveCursorDown( bool expandSelection );
1648 bool MoveCursorLeft( bool expandSelection );
1649 bool MoveCursorRight( bool expandSelection );
1650 bool MovePageDown();
1652 bool MoveCursorUpBlock( bool expandSelection );
1653 bool MoveCursorDownBlock( bool expandSelection );
1654 bool MoveCursorLeftBlock( bool expandSelection );
1655 bool MoveCursorRightBlock( bool expandSelection );
1658 // ------ label and gridline formatting
1660 int GetDefaultRowLabelSize();
1661 int GetRowLabelSize();
1662 int GetDefaultColLabelSize();
1663 int GetColLabelSize();
1664 wxColour GetLabelBackgroundColour();
1665 wxColour GetLabelTextColour();
1666 wxFont GetLabelFont();
1667 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1668 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1669 int GetColLabelTextOrientation();
1670 wxString GetRowLabelValue( int row );
1671 wxString GetColLabelValue( int col );
1672 wxColour GetGridLineColour();
1673 wxColour GetCellHighlightColour();
1674 int GetCellHighlightPenWidth();
1675 int GetCellHighlightROPenWidth();
1677 void SetRowLabelSize( int width );
1678 void SetColLabelSize( int height );
1679 void SetLabelBackgroundColour( const wxColour& );
1680 void SetLabelTextColour( const wxColour& );
1681 void SetLabelFont( const wxFont& );
1682 void SetRowLabelAlignment( int horiz, int vert );
1683 void SetColLabelAlignment( int horiz, int vert );
1684 void SetColLabelTextOrientation( int textOrientation );
1685 void SetRowLabelValue( int row, const wxString& );
1686 void SetColLabelValue( int col, const wxString& );
1687 void SetGridLineColour( const wxColour& );
1688 void SetCellHighlightColour( const wxColour& );
1689 void SetCellHighlightPenWidth(int width);
1690 void SetCellHighlightROPenWidth(int width);
1692 void EnableDragRowSize( bool enable = TRUE );
1693 void DisableDragRowSize();
1694 bool CanDragRowSize();
1695 void EnableDragColSize( bool enable = TRUE );
1696 void DisableDragColSize();
1697 bool CanDragColSize();
1698 void EnableDragGridSize(bool enable = TRUE);
1699 void DisableDragGridSize();
1700 bool CanDragGridSize();
1702 // this sets the specified attribute for all cells in this row/col
1703 void SetAttr(int row, int col, wxGridCellAttr *attr);
1704 void SetRowAttr(int row, wxGridCellAttr *attr);
1705 void SetColAttr(int col, wxGridCellAttr *attr);
1707 // shortcuts for setting the column parameters
1709 // set the format for the data in the column: default is string
1710 void SetColFormatBool(int col);
1711 void SetColFormatNumber(int col);
1712 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1713 void SetColFormatCustom(int col, const wxString& typeName);
1715 void EnableGridLines( bool enable = TRUE );
1716 bool GridLinesEnabled();
1718 // ------ row and col formatting
1720 int GetDefaultRowSize();
1721 int GetRowSize( int row );
1722 int GetDefaultColSize();
1723 int GetColSize( int col );
1724 wxColour GetDefaultCellBackgroundColour();
1725 wxColour GetCellBackgroundColour( int row, int col );
1726 wxColour GetDefaultCellTextColour();
1727 wxColour GetCellTextColour( int row, int col );
1728 wxFont GetDefaultCellFont();
1729 wxFont GetCellFont( int row, int col );
1730 void GetDefaultCellAlignment( int *horiz, int *vert );
1731 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1732 bool GetDefaultCellOverflow();
1733 bool GetCellOverflow( int row, int col );
1734 void GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT );
1736 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1737 void SetRowSize( int row, int height );
1738 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1740 void SetColSize( int col, int width );
1742 // automatically size the column or row to fit to its contents, if
1743 // setAsMin is TRUE, this optimal width will also be set as minimal width
1745 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1746 void AutoSizeRow( int row, bool setAsMin = TRUE );
1749 // auto size all columns (very ineffective for big grids!)
1750 void AutoSizeColumns( bool setAsMin = TRUE );
1751 void AutoSizeRows( bool setAsMin = TRUE );
1753 // auto size the grid, that is make the columns/rows of the "right" size
1754 // and also set the grid size to just fit its contents
1757 // autosize row height depending on label text
1758 void AutoSizeRowLabelSize( int row );
1760 // autosize column width depending on label text
1761 void AutoSizeColLabelSize( int col );
1764 // column won't be resized to be lesser width - this must be called during
1765 // the grid creation because it won't resize the column if it's already
1766 // narrower than the minimal width
1767 void SetColMinimalWidth( int col, int width );
1768 void SetRowMinimalHeight( int row, int width );
1770 void SetDefaultCellBackgroundColour( const wxColour& );
1771 void SetCellBackgroundColour( int row, int col, const wxColour& );
1772 void SetDefaultCellTextColour( const wxColour& );
1774 void SetCellTextColour( int row, int col, const wxColour& );
1775 void SetDefaultCellFont( const wxFont& );
1776 void SetCellFont( int row, int col, const wxFont& );
1777 void SetDefaultCellAlignment( int horiz, int vert );
1778 void SetCellAlignment( int row, int col, int horiz, int vert );
1779 void SetDefaultCellOverflow( bool allow );
1780 void SetCellOverflow( int row, int col, bool allow );
1781 void SetCellSize( int row, int col, int num_rows, int num_cols );
1783 // takes ownership of the pointer
1784 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1785 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1786 wxGridCellRenderer *GetDefaultRenderer() const;
1787 wxGridCellRenderer* GetCellRenderer(int row, int col);
1789 // takes ownership of the pointer
1790 void SetDefaultEditor(wxGridCellEditor *editor);
1791 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1792 wxGridCellEditor *GetDefaultEditor() const;
1793 wxGridCellEditor* GetCellEditor(int row, int col);
1797 // ------ cell value accessors
1799 wxString GetCellValue( int row, int col );
1800 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1802 void SetCellValue( int row, int col, const wxString& s );
1803 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1805 // returns TRUE if the cell can't be edited
1806 bool IsReadOnly(int row, int col) const;
1808 // make the cell editable/readonly
1809 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1811 // ------ selections of blocks of cells
1813 void SelectRow( int row, bool addToSelected = FALSE );
1814 void SelectCol( int col, bool addToSelected = FALSE );
1816 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1817 bool addToSelected = FALSE );
1818 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1819 // TODO: ??? const wxGridCellCoords& bottomRight )
1823 void ClearSelection();
1824 bool IsInSelection( int row, int col );
1825 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1827 const wxGridCellCoordsArray GetSelectedCells() const;
1828 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1829 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1830 const wxArrayInt GetSelectedRows() const;
1831 const wxArrayInt GetSelectedCols() const;
1833 void DeselectRow( int row );
1834 void DeselectCol( int col );
1835 void DeselectCell( int row, int col );
1838 // This function returns the rectangle that encloses the block of cells
1839 // limited by TopLeft and BottomRight cell in device coords and clipped
1840 // to the client size of the grid window.
1842 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1843 const wxGridCellCoords & bottomRight );
1846 // Access or update the selection fore/back colours
1847 wxColour GetSelectionBackground() const;
1848 wxColour GetSelectionForeground() const;
1850 void SetSelectionBackground(const wxColour& c);
1851 void SetSelectionForeground(const wxColour& c);
1854 // Methods for a registry for mapping data types to Renderers/Editors
1855 void RegisterDataType(const wxString& typeName,
1856 wxGridCellRenderer* renderer,
1857 wxGridCellEditor* editor);
1858 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1859 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1860 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1861 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1862 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1864 // grid may occupy more space than needed for its rows/columns, this
1865 // function allows to set how big this extra space is
1866 void SetMargins(int extraWidth, int extraHeight);
1869 // Accessors for component windows
1870 wxWindow* GetGridWindow();
1871 wxWindow* GetGridRowLabelWindow();
1872 wxWindow* GetGridColLabelWindow();
1873 wxWindow* GetGridCornerLabelWindow();
1879 //---------------------------------------------------------------------------
1880 //---------------------------------------------------------------------------
1881 // Grid events and stuff
1885 class wxGridEvent : public wxNotifyEvent
1888 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1889 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1890 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1892 virtual int GetRow();
1893 virtual int GetCol();
1894 wxPoint GetPosition();
1904 class wxGridSizeEvent : public wxNotifyEvent
1907 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1908 int rowOrCol=-1, int x=-1, int y=-1,
1909 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1912 wxPoint GetPosition();
1921 class wxGridRangeSelectEvent : public wxNotifyEvent
1924 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1925 const wxGridCellCoords& topLeft,
1926 const wxGridCellCoords& bottomRight,
1928 bool control=FALSE, bool shift=FALSE,
1929 bool alt=FALSE, bool meta=FALSE);
1931 wxGridCellCoords GetTopLeftCoords();
1932 wxGridCellCoords GetBottomRightCoords();
1945 class wxGridEditorCreatedEvent : public wxCommandEvent {
1947 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1948 int row, int col, wxControl* ctrl);
1952 wxControl* GetControl();
1953 void SetRow(int row);
1954 void SetCol(int col);
1955 void SetControl(wxControl* ctrl);
1961 wxEVT_GRID_CELL_LEFT_CLICK,
1962 wxEVT_GRID_CELL_RIGHT_CLICK,
1963 wxEVT_GRID_CELL_LEFT_DCLICK,
1964 wxEVT_GRID_CELL_RIGHT_DCLICK,
1965 wxEVT_GRID_LABEL_LEFT_CLICK,
1966 wxEVT_GRID_LABEL_RIGHT_CLICK,
1967 wxEVT_GRID_LABEL_LEFT_DCLICK,
1968 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1969 wxEVT_GRID_ROW_SIZE,
1970 wxEVT_GRID_COL_SIZE,
1971 wxEVT_GRID_RANGE_SELECT,
1972 wxEVT_GRID_CELL_CHANGE,
1973 wxEVT_GRID_SELECT_CELL,
1974 wxEVT_GRID_EDITOR_SHOWN,
1975 wxEVT_GRID_EDITOR_HIDDEN,
1976 wxEVT_GRID_EDITOR_CREATED,
1981 %pragma(python) code = "
1982 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1983 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1985 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1986 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1988 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1989 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1991 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1992 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1994 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1995 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1997 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1998 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
2000 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
2001 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
2003 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
2004 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
2006 def EVT_GRID_ROW_SIZE(win, fn):
2007 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
2009 def EVT_GRID_COL_SIZE(win, fn):
2010 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
2012 def EVT_GRID_RANGE_SELECT(win, fn):
2013 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
2015 def EVT_GRID_CELL_CHANGE(win, fn):
2016 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
2018 def EVT_GRID_SELECT_CELL(win, fn):
2019 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
2021 def EVT_GRID_EDITOR_SHOWN(win, fn):
2022 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
2024 def EVT_GRID_EDITOR_HIDDEN(win, fn):
2025 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
2027 def EVT_GRID_EDITOR_CREATED(win, fn):
2028 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
2032 //---------------------------------------------------------------------------
2035 wxClassInfo::CleanUpClasses();
2036 wxClassInfo::InitializeClasses();
2039 //---------------------------------------------------------------------------
2041 %pragma(python) include="_gridextras.py";
2043 //---------------------------------------------------------------------------