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();
774 virtual wxString GetValue();
778 // The C++ version of wxPyGridCellEditor
780 class wxPyGridCellEditor : public wxGridCellEditor
783 wxPyGridCellEditor() : wxGridCellEditor() {}
785 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
786 wxPyBeginBlockThreads();
787 if (wxPyCBH_findCallback(m_myInst, "Create")) {
788 PyObject* po = wxPyMake_wxObject(parent);
789 PyObject* eo = wxPyMake_wxObject(evtHandler);
791 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
795 wxPyEndBlockThreads();
799 void BeginEdit(int row, int col, wxGrid* grid) {
800 wxPyBeginBlockThreads();
801 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
802 PyObject* go = wxPyMake_wxObject(grid);
803 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
806 wxPyEndBlockThreads();
810 bool EndEdit(int row, int col, wxGrid* grid) {
812 wxPyBeginBlockThreads();
813 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
814 PyObject* go = wxPyMake_wxObject(grid);
815 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
818 wxPyEndBlockThreads();
823 wxGridCellEditor* Clone() const {
824 wxGridCellEditor* rval = NULL;
825 wxPyBeginBlockThreads();
826 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
828 wxGridCellEditor* ptr;
829 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
831 if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxGridCellEditor_p"))
836 wxPyEndBlockThreads();
841 void Show(bool show, wxGridCellAttr *attr) {
843 wxPyBeginBlockThreads();
844 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
845 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
846 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
849 wxPyEndBlockThreads();
851 wxGridCellEditor::Show(show, attr);
853 void base_Show(bool show, wxGridCellAttr *attr) {
854 wxGridCellEditor::Show(show, attr);
858 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
860 wxPyBeginBlockThreads();
861 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
862 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
863 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
865 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
870 wxPyEndBlockThreads();
872 wxGridCellEditor::PaintBackground(rectCell, attr);
874 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
875 wxGridCellEditor::PaintBackground(rectCell, attr);
879 DEC_PYCALLBACK___pure(Reset);
880 DEC_PYCALLBACK__constany(SetSize, wxRect);
881 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
882 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
883 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
884 DEC_PYCALLBACK__(StartingClick);
885 DEC_PYCALLBACK__(Destroy);
886 DEC_PYCALLBACK__STRING(SetParameters);
887 DEC_PYCALLBACK_STRING__const(GetValue);
893 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
894 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
895 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
896 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
897 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
898 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
899 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
900 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
901 IMP_PYCALLBACK_STRING__const(wxPyGridCellEditor, wxGridCellEditor, GetValue);
906 // Let SWIG know about it so it can create the Python version
907 class wxPyGridCellEditor : public wxGridCellEditor {
909 wxPyGridCellEditor();
910 void _setCallbackInfo(PyObject* self, PyObject* _class);
911 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellEditor)"
912 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
914 void base_SetSize(const wxRect& rect);
915 void base_Show(bool show, wxGridCellAttr *attr = NULL);
916 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
917 void base_IsAcceptedKey(wxKeyEvent& event);
918 void base_StartingKey(wxKeyEvent& event);
919 void base_StartingClick();
920 void base_HandleReturn(wxKeyEvent& event);
922 void base_SetParameters(const wxString& params);
923 wxString base_GetValue();
926 //---------------------------------------------------------------------------
927 // Predefined Editors
929 class wxGridCellTextEditor : public wxGridCellEditor
932 wxGridCellTextEditor();
933 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
937 class wxGridCellNumberEditor : public wxGridCellTextEditor
940 wxGridCellNumberEditor(int min = -1, int max = -1);
941 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
945 class wxGridCellFloatEditor : public wxGridCellTextEditor
948 wxGridCellFloatEditor();
949 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
953 class wxGridCellBoolEditor : public wxGridCellEditor
956 wxGridCellBoolEditor();
957 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
960 class wxGridCellChoiceEditor : public wxGridCellEditor
963 wxGridCellChoiceEditor(int LCOUNT = 0,
964 const wxString* choices = NULL,
965 bool allowOthers = FALSE);
966 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
970 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
973 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
974 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
978 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
981 wxGridCellAutoWrapStringEditor();
982 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
987 //---------------------------------------------------------------------------
1004 void _setOORInfo(PyObject* _self) {
1005 self->SetClientObject(new wxPyOORClientData(_self));
1009 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1010 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1012 wxGridCellAttr *Clone() const;
1013 void MergeWith(wxGridCellAttr *mergefrom);
1016 void SetTextColour(const wxColour& colText);
1017 void SetBackgroundColour(const wxColour& colBack);
1018 void SetFont(const wxFont& font);
1019 void SetAlignment(int hAlign, int vAlign);
1020 void SetSize(int num_rows, int num_cols);
1021 void SetOverflow( bool allow );
1022 void SetReadOnly(bool isReadOnly = TRUE);
1024 void SetRenderer(wxGridCellRenderer *renderer);
1025 void SetEditor(wxGridCellEditor* editor);
1026 void SetKind(wxAttrKind kind);
1028 bool HasTextColour() const;
1029 bool HasBackgroundColour() const;
1030 bool HasFont() const;
1031 bool HasAlignment() const;
1032 bool HasRenderer() const;
1033 bool HasEditor() const;
1034 bool HasReadWriteMode() const;
1036 wxColour GetTextColour() const;
1037 wxColour GetBackgroundColour() const;
1038 wxFont GetFont() const;
1039 void GetAlignment(int *OUTPUT, int *OUTPUT) const;
1040 void GetSize(int *num_rows, int *num_cols) const;
1041 bool GetOverflow() const;
1042 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1043 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1045 bool IsReadOnly() const;
1046 void SetDefAttr(wxGridCellAttr* defAttr);
1049 //---------------------------------------------------------------------------
1051 class wxGridCellAttrProvider
1054 wxGridCellAttrProvider();
1055 // ???? virtual ~wxGridCellAttrProvider();
1056 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1059 void _setOORInfo(PyObject* _self) {
1060 self->SetClientObject(new wxPyOORClientData(_self));
1064 wxGridCellAttr *GetAttr(int row, int col,
1065 wxGridCellAttr::wxAttrKind kind) const;
1066 void SetAttr(wxGridCellAttr *attr, int row, int col);
1067 void SetRowAttr(wxGridCellAttr *attr, int row);
1068 void SetColAttr(wxGridCellAttr *attr, int col);
1070 void UpdateAttrRows( size_t pos, int numRows );
1071 void UpdateAttrCols( size_t pos, int numCols );
1076 // A Python-aware version
1078 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1081 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1083 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1084 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1085 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1086 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1093 // The python-aware version get's SWIGified
1094 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1097 wxPyGridCellAttrProvider();
1098 void _setCallbackInfo(PyObject* self, PyObject* _class);
1099 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridCellAttrProvider)"
1101 wxGridCellAttr *base_GetAttr(int row, int col,
1102 wxGridCellAttr::wxAttrKind kind);
1103 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1104 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1105 void base_SetColAttr(wxGridCellAttr *attr, int col);
1109 //---------------------------------------------------------------------------
1110 // Grid Table Base class and Python aware version
1113 class wxGridTableBase : public wxObject
1116 // wxGridTableBase(); This is an ABC
1117 //~wxGridTableBase();
1120 void _setOORInfo(PyObject* _self) {
1121 self->SetClientObject(new wxPyOORClientData(_self));
1125 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1126 wxGridCellAttrProvider *GetAttrProvider() const;
1127 void SetView( wxGrid *grid );
1128 wxGrid * GetView() const;
1132 virtual int GetNumberRows() = 0;
1133 virtual int GetNumberCols() = 0;
1134 virtual bool IsEmptyCell( int row, int col ) = 0;
1135 virtual wxString GetValue( int row, int col ) = 0;
1136 virtual void SetValue( int row, int col, const wxString& value ) = 0;
1138 // virtuals overridable in wxPyGridTableBase
1139 virtual wxString GetTypeName( int row, int col );
1140 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1141 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1142 virtual long GetValueAsLong( int row, int col );
1143 virtual double GetValueAsDouble( int row, int col );
1144 virtual bool GetValueAsBool( int row, int col );
1145 virtual void SetValueAsLong( int row, int col, long value );
1146 virtual void SetValueAsDouble( int row, int col, double value );
1147 virtual void SetValueAsBool( int row, int col, bool value );
1149 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1150 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1153 virtual void Clear();
1154 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1155 virtual bool AppendRows( size_t numRows = 1 );
1156 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1157 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1158 virtual bool AppendCols( size_t numCols = 1 );
1159 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1161 virtual wxString GetRowLabelValue( int row );
1162 virtual wxString GetColLabelValue( int col );
1163 virtual void SetRowLabelValue( int row, const wxString& value );
1164 virtual void SetColLabelValue( int col, const wxString& value );
1166 virtual bool CanHaveAttributes();
1168 virtual wxGridCellAttr *GetAttr( int row, int col,
1169 wxGridCellAttr::wxAttrKind kind);
1170 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1171 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1172 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1178 // Python-aware version
1180 class wxPyGridTableBase : public wxGridTableBase
1183 wxPyGridTableBase() : wxGridTableBase() {}
1185 PYCALLBACK_INT__pure(GetNumberRows);
1186 PYCALLBACK_INT__pure(GetNumberCols);
1187 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1188 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1189 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1190 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1191 PYCALLBACK__(wxGridTableBase, Clear);
1192 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1193 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1194 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1195 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1196 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1197 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1198 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1199 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1200 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1201 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1202 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1203 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1204 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1205 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1206 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1209 wxString GetValue(int row, int col) {
1210 wxPyBeginBlockThreads();
1212 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1214 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1216 rval = Py2wxString(ro);
1220 wxPyEndBlockThreads();
1224 void SetValue(int row, int col, const wxString& val) {
1225 wxPyBeginBlockThreads();
1226 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1227 PyObject* s = wx2PyString(val);
1228 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1231 wxPyEndBlockThreads();
1235 // Map the Get/Set methods for the standard non-string types to
1236 // the GetValue and SetValue python methods.
1237 long GetValueAsLong( int row, int col ) {
1239 wxPyBeginBlockThreads();
1240 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1243 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1244 if (ro && PyNumber_Check(ro)) {
1245 num = PyNumber_Int(ro);
1247 rval = PyInt_AsLong(num);
1253 wxPyEndBlockThreads();
1257 double GetValueAsDouble( int row, int col ) {
1259 wxPyBeginBlockThreads();
1260 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1263 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1264 if (ro && PyNumber_Check(ro)) {
1265 num = PyNumber_Float(ro);
1267 rval = PyFloat_AsDouble(num);
1273 wxPyEndBlockThreads();
1277 bool GetValueAsBool( int row, int col ) {
1278 return (bool)GetValueAsLong(row, col);
1281 void SetValueAsLong( int row, int col, long value ) {
1282 wxPyBeginBlockThreads();
1283 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1284 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1286 wxPyEndBlockThreads();
1289 void SetValueAsDouble( int row, int col, double value ) {
1290 wxPyBeginBlockThreads();
1291 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1292 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1294 wxPyEndBlockThreads();
1297 void SetValueAsBool( int row, int col, bool value ) {
1298 SetValueAsLong( row, col, (long)value );
1307 // The python-aware version get's SWIGified
1308 class wxPyGridTableBase : public wxGridTableBase
1311 wxPyGridTableBase();
1312 void _setCallbackInfo(PyObject* self, PyObject* _class);
1313 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyGridTableBase)"
1314 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1316 %addmethods { void Destroy() { delete self; } }
1318 wxString base_GetTypeName( int row, int col );
1319 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1320 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1322 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1323 bool base_AppendRows( size_t numRows = 1 );
1324 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1325 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1326 bool base_AppendCols( size_t numCols = 1 );
1327 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1328 wxString base_GetRowLabelValue( int row );
1329 wxString base_GetColLabelValue( int col );
1330 void base_SetRowLabelValue( int row, const wxString& value );
1331 void base_SetColLabelValue( int col, const wxString& value );
1332 bool base_CanHaveAttributes();
1333 wxGridCellAttr *base_GetAttr( int row, int col,
1334 wxGridCellAttr::wxAttrKind kind );
1335 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1336 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1337 void base_SetColAttr(wxGridCellAttr *attr, int col);
1341 //---------------------------------------------------------------------------
1342 // Predefined Tables
1344 class wxGridStringTable : public wxGridTableBase
1347 wxGridStringTable( int numRows=0, int numCols=0 );
1348 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1351 //---------------------------------------------------------------------------
1352 // The Table can pass messages to the grid to tell it to update itself if
1353 // something has changed.
1355 enum wxGridTableRequest
1357 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1358 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1359 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1360 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1361 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1362 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1363 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1364 wxGRIDTABLE_NOTIFY_COLS_DELETED
1368 class wxGridTableMessage
1371 wxGridTableMessage( wxGridTableBase *table, int id,
1374 ~wxGridTableMessage();
1376 void SetTableObject( wxGridTableBase *table );
1377 wxGridTableBase * GetTableObject() const;
1378 void SetId( int id );
1380 void SetCommandInt( int comInt1 );
1381 int GetCommandInt();
1382 void SetCommandInt2( int comInt2 );
1383 int GetCommandInt2();
1387 //---------------------------------------------------------------------------
1389 class wxGridCellCoords
1392 wxGridCellCoords( int r=-1, int c=-1 );
1393 ~wxGridCellCoords();
1395 int GetRow() const { return m_row; }
1396 void SetRow( int n ) { m_row = n; }
1397 int GetCol() const { return m_col; }
1398 void SetCol( int n ) { m_col = n; }
1399 void Set( int row, int col ) { m_row = row; m_col = col; }
1402 PyObject* asTuple() {
1403 PyObject* tup = PyTuple_New(2);
1404 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1405 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1409 int __cmp__( const wxGridCellCoords& other ) {
1410 return *self != other;
1413 %pragma(python) addtoclass = "
1414 def __str__(self): return str(self.asTuple())
1415 def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
1416 def __len__(self): return len(self.asTuple())
1417 def __getitem__(self, index): return self.asTuple()[index]
1418 def __setitem__(self, index, val):
1419 if index == 0: self.SetRow(val)
1420 elif index == 1: self.SetCol(val)
1421 else: raise IndexError
1426 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1427 %typemap(python,in) wxGridCellCoords& (wxGridCellCoords temp) {
1429 if (! wxGridCellCoords_helper($source, &$target))
1433 // ...and here is the associated helper.
1435 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1437 // If source is an object instance then it may already be the right type
1438 if (PyInstance_Check(source)) {
1439 wxGridCellCoords* ptr;
1440 if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxGridCellCoords_p"))
1445 // otherwise a 2-tuple of integers is expected
1446 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1447 PyObject* o1 = PySequence_GetItem(source, 0);
1448 PyObject* o2 = PySequence_GetItem(source, 1);
1449 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1454 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1461 // Typemap to convert an array of cells coords to a list of tuples...
1462 %typemap(python, out) wxGridCellCoordsArray {
1463 $target = wxGridCellCoordsArray_helper($source);
1466 %typemap(python, ret) wxGridCellCoordsArray {
1471 // ...and the helper function for the above typemap.
1473 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray* source)
1475 PyObject* list = PyList_New(0);
1477 for (idx = 0; idx < source->GetCount(); idx += 1) {
1478 wxGridCellCoords& coord = source->Item(idx);
1479 PyObject* tup = PyTuple_New(2);
1480 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1481 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1482 PyList_Append(list, tup);
1489 //---------------------------------------------------------------------------
1490 //---------------------------------------------------------------------------
1494 // Fool SWIG into treating this enum as an int
1495 typedef int WXGRIDSELECTIONMODES;
1497 // but let the C++ code know what it really is.
1499 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1504 class wxGrid : public wxScrolledWindow
1507 wxGrid( wxWindow *parent,
1509 const wxPoint& pos = wxDefaultPosition,
1510 const wxSize& size = wxDefaultSize,
1511 long style = wxWANTS_CHARS,
1512 const wxString& name = wxPyPanelNameStr);
1514 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1516 enum wxGridSelectionModes {wxGridSelectCells,
1518 wxGridSelectColumns};
1520 bool CreateGrid( int numRows, int numCols,
1521 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1522 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1523 WXGRIDSELECTIONMODES GetSelectionMode();
1526 // ------ grid dimensions
1528 int GetNumberRows();
1529 int GetNumberCols();
1532 bool ProcessTableMessage( wxGridTableMessage& );
1535 wxGridTableBase * GetTable() const;
1536 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
1537 WXGRIDSELECTIONMODES selmode =
1538 wxGrid::wxGridSelectCells );
1541 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1542 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1543 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1544 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1545 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
1546 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1549 // this function is called when the current cell highlight must be redrawn
1550 // and may be overridden by the user
1551 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1554 // ------ Cell text drawing functions
1556 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1557 int horizontalAlignment = wxLEFT,
1558 int verticalAlignment = wxTOP,
1559 int textOrientation = wxHORIZONTAL );
1561 // // Split a string containing newline chararcters into an array of
1562 // // strings and return the number of lines
1564 // void StringToLines( const wxString& value, wxArrayString& lines );
1566 void GetTextBoxSize( wxDC& dc,
1567 wxArrayString& lines,
1568 long *OUTPUT, long *OUTPUT );
1572 // Code that does a lot of grid modification can be enclosed
1573 // between BeginBatch() and EndBatch() calls to avoid screen
1578 int GetBatchCount();
1579 void ForceRefresh();
1580 void Refresh(bool eraseb=TRUE, const wxRect* rect= NULL);
1583 // ------ edit control functions
1586 void EnableEditing( bool edit );
1588 void EnableCellEditControl( bool enable = TRUE );
1589 void DisableCellEditControl();
1590 bool CanEnableCellControl() const;
1591 bool IsCellEditControlEnabled() const;
1592 bool IsCellEditControlShown() const;
1594 bool IsCurrentCellReadOnly() const;
1596 void ShowCellEditControl();
1597 void HideCellEditControl();
1598 void SaveEditControlValue();
1601 // ------ grid location functions
1602 // Note that all of these functions work with the logical coordinates of
1603 // grid cells and labels so you will need to convert from device
1604 // coordinates for mouse events etc.
1607 //void XYToCell( int x, int y, wxGridCellCoords& );
1609 %new wxGridCellCoords* XYToCell(int x, int y) {
1610 wxGridCellCoords rv;
1611 self->XYToCell(x, y, rv);
1612 return new wxGridCellCoords(rv);
1616 int YToRow( int y );
1617 int XToCol( int x );
1619 int YToEdgeOfRow( int y );
1620 int XToEdgeOfCol( int x );
1622 wxRect CellToRect( int row, int col );
1623 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1626 int GetGridCursorRow();
1627 int GetGridCursorCol();
1629 // check to see if a cell is either wholly visible (the default arg) or
1630 // at least partially visible in the grid window
1632 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1633 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE );
1634 void MakeCellVisible( int row, int col );
1635 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1638 // ------ grid cursor movement functions
1640 void SetGridCursor( int row, int col );
1641 bool MoveCursorUp( bool expandSelection );
1642 bool MoveCursorDown( bool expandSelection );
1643 bool MoveCursorLeft( bool expandSelection );
1644 bool MoveCursorRight( bool expandSelection );
1645 bool MovePageDown();
1647 bool MoveCursorUpBlock( bool expandSelection );
1648 bool MoveCursorDownBlock( bool expandSelection );
1649 bool MoveCursorLeftBlock( bool expandSelection );
1650 bool MoveCursorRightBlock( bool expandSelection );
1653 // ------ label and gridline formatting
1655 int GetDefaultRowLabelSize();
1656 int GetRowLabelSize();
1657 int GetDefaultColLabelSize();
1658 int GetColLabelSize();
1659 wxColour GetLabelBackgroundColour();
1660 wxColour GetLabelTextColour();
1661 wxFont GetLabelFont();
1662 void GetRowLabelAlignment( int *OUTPUT, int *OUTPUT );
1663 void GetColLabelAlignment( int *OUTPUT, int *OUTPUT );
1664 int GetColLabelTextOrientation();
1665 wxString GetRowLabelValue( int row );
1666 wxString GetColLabelValue( int col );
1667 wxColour GetGridLineColour();
1668 wxColour GetCellHighlightColour();
1669 int GetCellHighlightPenWidth();
1670 int GetCellHighlightROPenWidth();
1672 void SetRowLabelSize( int width );
1673 void SetColLabelSize( int height );
1674 void SetLabelBackgroundColour( const wxColour& );
1675 void SetLabelTextColour( const wxColour& );
1676 void SetLabelFont( const wxFont& );
1677 void SetRowLabelAlignment( int horiz, int vert );
1678 void SetColLabelAlignment( int horiz, int vert );
1679 void SetColLabelTextOrientation( int textOrientation );
1680 void SetRowLabelValue( int row, const wxString& );
1681 void SetColLabelValue( int col, const wxString& );
1682 void SetGridLineColour( const wxColour& );
1683 void SetCellHighlightColour( const wxColour& );
1684 void SetCellHighlightPenWidth(int width);
1685 void SetCellHighlightROPenWidth(int width);
1687 void EnableDragRowSize( bool enable = TRUE );
1688 void DisableDragRowSize();
1689 bool CanDragRowSize();
1690 void EnableDragColSize( bool enable = TRUE );
1691 void DisableDragColSize();
1692 bool CanDragColSize();
1693 void EnableDragGridSize(bool enable = TRUE);
1694 void DisableDragGridSize();
1695 bool CanDragGridSize();
1697 // this sets the specified attribute for all cells in this row/col
1698 void SetAttr(int row, int col, wxGridCellAttr *attr);
1699 void SetRowAttr(int row, wxGridCellAttr *attr);
1700 void SetColAttr(int col, wxGridCellAttr *attr);
1702 // shortcuts for setting the column parameters
1704 // set the format for the data in the column: default is string
1705 void SetColFormatBool(int col);
1706 void SetColFormatNumber(int col);
1707 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1708 void SetColFormatCustom(int col, const wxString& typeName);
1710 void EnableGridLines( bool enable = TRUE );
1711 bool GridLinesEnabled();
1713 // ------ row and col formatting
1715 int GetDefaultRowSize();
1716 int GetRowSize( int row );
1717 int GetDefaultColSize();
1718 int GetColSize( int col );
1719 wxColour GetDefaultCellBackgroundColour();
1720 wxColour GetCellBackgroundColour( int row, int col );
1721 wxColour GetDefaultCellTextColour();
1722 wxColour GetCellTextColour( int row, int col );
1723 wxFont GetDefaultCellFont();
1724 wxFont GetCellFont( int row, int col );
1725 void GetDefaultCellAlignment( int *horiz, int *vert );
1726 void GetCellAlignment( int row, int col, int *horiz, int *vert );
1727 bool GetDefaultCellOverflow();
1728 bool GetCellOverflow( int row, int col );
1729 void GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT );
1731 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1732 void SetRowSize( int row, int height );
1733 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
1735 void SetColSize( int col, int width );
1737 // automatically size the column or row to fit to its contents, if
1738 // setAsMin is TRUE, this optimal width will also be set as minimal width
1740 void AutoSizeColumn( int col, bool setAsMin = TRUE );
1741 void AutoSizeRow( int row, bool setAsMin = TRUE );
1744 // auto size all columns (very ineffective for big grids!)
1745 void AutoSizeColumns( bool setAsMin = TRUE );
1746 void AutoSizeRows( bool setAsMin = TRUE );
1748 // auto size the grid, that is make the columns/rows of the "right" size
1749 // and also set the grid size to just fit its contents
1752 // autosize row height depending on label text
1753 void AutoSizeRowLabelSize( int row );
1755 // autosize column width depending on label text
1756 void AutoSizeColLabelSize( int col );
1759 // column won't be resized to be lesser width - this must be called during
1760 // the grid creation because it won't resize the column if it's already
1761 // narrower than the minimal width
1762 void SetColMinimalWidth( int col, int width );
1763 void SetRowMinimalHeight( int row, int width );
1765 void SetDefaultCellBackgroundColour( const wxColour& );
1766 void SetCellBackgroundColour( int row, int col, const wxColour& );
1767 void SetDefaultCellTextColour( const wxColour& );
1769 void SetCellTextColour( int row, int col, const wxColour& );
1770 void SetDefaultCellFont( const wxFont& );
1771 void SetCellFont( int row, int col, const wxFont& );
1772 void SetDefaultCellAlignment( int horiz, int vert );
1773 void SetCellAlignment( int row, int col, int horiz, int vert );
1774 void SetDefaultCellOverflow( bool allow );
1775 void SetCellOverflow( int row, int col, bool allow );
1776 void SetCellSize( int row, int col, int num_rows, int num_cols );
1778 // takes ownership of the pointer
1779 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1780 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1781 wxGridCellRenderer *GetDefaultRenderer() const;
1782 wxGridCellRenderer* GetCellRenderer(int row, int col);
1784 // takes ownership of the pointer
1785 void SetDefaultEditor(wxGridCellEditor *editor);
1786 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1787 wxGridCellEditor *GetDefaultEditor() const;
1788 wxGridCellEditor* GetCellEditor(int row, int col);
1792 // ------ cell value accessors
1794 wxString GetCellValue( int row, int col );
1795 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1797 void SetCellValue( int row, int col, const wxString& s );
1798 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1800 // returns TRUE if the cell can't be edited
1801 bool IsReadOnly(int row, int col) const;
1803 // make the cell editable/readonly
1804 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
1806 // ------ selections of blocks of cells
1808 void SelectRow( int row, bool addToSelected = FALSE );
1809 void SelectCol( int col, bool addToSelected = FALSE );
1811 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1812 bool addToSelected = FALSE );
1813 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1814 // TODO: ??? const wxGridCellCoords& bottomRight )
1818 void ClearSelection();
1819 bool IsInSelection( int row, int col );
1820 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1822 const wxGridCellCoordsArray GetSelectedCells() const;
1823 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1824 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1825 const wxArrayInt GetSelectedRows() const;
1826 const wxArrayInt GetSelectedCols() const;
1828 void DeselectRow( int row );
1829 void DeselectCol( int col );
1830 void DeselectCell( int row, int col );
1833 // This function returns the rectangle that encloses the block of cells
1834 // limited by TopLeft and BottomRight cell in device coords and clipped
1835 // to the client size of the grid window.
1837 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1838 const wxGridCellCoords & bottomRight );
1841 // Access or update the selection fore/back colours
1842 wxColour GetSelectionBackground() const;
1843 wxColour GetSelectionForeground() const;
1845 void SetSelectionBackground(const wxColour& c);
1846 void SetSelectionForeground(const wxColour& c);
1849 // Methods for a registry for mapping data types to Renderers/Editors
1850 void RegisterDataType(const wxString& typeName,
1851 wxGridCellRenderer* renderer,
1852 wxGridCellEditor* editor);
1853 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1854 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1855 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1856 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1857 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1859 // grid may occupy more space than needed for its rows/columns, this
1860 // function allows to set how big this extra space is
1861 void SetMargins(int extraWidth, int extraHeight);
1864 // Accessors for component windows
1865 wxWindow* GetGridWindow();
1866 wxWindow* GetGridRowLabelWindow();
1867 wxWindow* GetGridColLabelWindow();
1868 wxWindow* GetGridCornerLabelWindow();
1874 //---------------------------------------------------------------------------
1875 //---------------------------------------------------------------------------
1876 // Grid events and stuff
1880 class wxGridEvent : public wxNotifyEvent
1883 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1884 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
1885 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1887 virtual int GetRow();
1888 virtual int GetCol();
1889 wxPoint GetPosition();
1899 class wxGridSizeEvent : public wxNotifyEvent
1902 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1903 int rowOrCol=-1, int x=-1, int y=-1,
1904 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1907 wxPoint GetPosition();
1916 class wxGridRangeSelectEvent : public wxNotifyEvent
1919 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1920 const wxGridCellCoords& topLeft,
1921 const wxGridCellCoords& bottomRight,
1923 bool control=FALSE, bool shift=FALSE,
1924 bool alt=FALSE, bool meta=FALSE);
1926 wxGridCellCoords GetTopLeftCoords();
1927 wxGridCellCoords GetBottomRightCoords();
1940 class wxGridEditorCreatedEvent : public wxCommandEvent {
1942 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1943 int row, int col, wxControl* ctrl);
1947 wxControl* GetControl();
1948 void SetRow(int row);
1949 void SetCol(int col);
1950 void SetControl(wxControl* ctrl);
1956 wxEVT_GRID_CELL_LEFT_CLICK,
1957 wxEVT_GRID_CELL_RIGHT_CLICK,
1958 wxEVT_GRID_CELL_LEFT_DCLICK,
1959 wxEVT_GRID_CELL_RIGHT_DCLICK,
1960 wxEVT_GRID_LABEL_LEFT_CLICK,
1961 wxEVT_GRID_LABEL_RIGHT_CLICK,
1962 wxEVT_GRID_LABEL_LEFT_DCLICK,
1963 wxEVT_GRID_LABEL_RIGHT_DCLICK,
1964 wxEVT_GRID_ROW_SIZE,
1965 wxEVT_GRID_COL_SIZE,
1966 wxEVT_GRID_RANGE_SELECT,
1967 wxEVT_GRID_CELL_CHANGE,
1968 wxEVT_GRID_SELECT_CELL,
1969 wxEVT_GRID_EDITOR_SHOWN,
1970 wxEVT_GRID_EDITOR_HIDDEN,
1971 wxEVT_GRID_EDITOR_CREATED,
1976 %pragma(python) code = "
1977 def EVT_GRID_CELL_LEFT_CLICK(win, fn):
1978 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_CLICK, fn)
1980 def EVT_GRID_CELL_RIGHT_CLICK(win, fn):
1981 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_CLICK, fn)
1983 def EVT_GRID_CELL_LEFT_DCLICK(win, fn):
1984 win.Connect(-1, -1, wxEVT_GRID_CELL_LEFT_DCLICK, fn)
1986 def EVT_GRID_CELL_RIGHT_DCLICK(win, fn):
1987 win.Connect(-1, -1, wxEVT_GRID_CELL_RIGHT_DCLICK, fn)
1989 def EVT_GRID_LABEL_LEFT_CLICK(win, fn):
1990 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_CLICK, fn)
1992 def EVT_GRID_LABEL_RIGHT_CLICK(win, fn):
1993 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_CLICK, fn)
1995 def EVT_GRID_LABEL_LEFT_DCLICK(win, fn):
1996 win.Connect(-1, -1, wxEVT_GRID_LABEL_LEFT_DCLICK, fn)
1998 def EVT_GRID_LABEL_RIGHT_DCLICK(win, fn):
1999 win.Connect(-1, -1, wxEVT_GRID_LABEL_RIGHT_DCLICK, fn)
2001 def EVT_GRID_ROW_SIZE(win, fn):
2002 win.Connect(-1, -1, wxEVT_GRID_ROW_SIZE, fn)
2004 def EVT_GRID_COL_SIZE(win, fn):
2005 win.Connect(-1, -1, wxEVT_GRID_COL_SIZE, fn)
2007 def EVT_GRID_RANGE_SELECT(win, fn):
2008 win.Connect(-1, -1, wxEVT_GRID_RANGE_SELECT, fn)
2010 def EVT_GRID_CELL_CHANGE(win, fn):
2011 win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn)
2013 def EVT_GRID_SELECT_CELL(win, fn):
2014 win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn)
2016 def EVT_GRID_EDITOR_SHOWN(win, fn):
2017 win.Connect(-1, -1, wxEVT_GRID_EDITOR_SHOWN, fn)
2019 def EVT_GRID_EDITOR_HIDDEN(win, fn):
2020 win.Connect(-1, -1, wxEVT_GRID_EDITOR_HIDDEN, fn)
2022 def EVT_GRID_EDITOR_CREATED(win, fn):
2023 win.Connect(-1, -1, wxEVT_GRID_EDITOR_CREATED, fn)
2027 //---------------------------------------------------------------------------
2030 wxClassInfo::CleanUpClasses();
2031 wxClassInfo::InitializeClasses();
2034 //---------------------------------------------------------------------------
2036 %pragma(python) include="_gridextras.py";
2038 //---------------------------------------------------------------------------