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 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/wxPython/wxPython.h"
17 #include "wx/wxPython/pyclasses.h"
18 #include "wx/wxPython/printfw.h"
21 #include <wx/generic/gridctrl.h>
26 //---------------------------------------------------------------------------
29 %pythoncode { wx = core }
32 %include _grid_rename.i
34 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
35 MAKE_CONST_WXSTRING_NOSWIG(PanelNameStr);
36 MAKE_CONST_WXSTRING2(DateTimeFormatStr, wxT("%c"));
39 //---------------------------------------------------------------------------
40 // OOR related typemaps and helper functions
42 %typemap(out) wxGridCellRenderer* { $result = wxPyMake_wxGridCellRenderer($1); }
43 %typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1); }
44 %typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1); }
45 %typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1); }
46 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1); }
51 #define wxPyMake_TEMPLATE(TYPE) \
52 PyObject* wxPyMake_##TYPE(TYPE* source) { \
53 PyObject* target = NULL; \
55 /* Check if there is already a pointer to a Python object in the \
56 OOR data that we can use. */ \
57 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
59 target = data->m_obj; \
62 /* Otherwise make a new wrapper for it the old fashioned way and \
63 give it the OOR treatment */ \
65 target = wxPyConstructObject(source, wxT(#TYPE), False); \
67 source->SetClientObject(new wxPyOORClientData(target)); \
69 } else { /* source was NULL so return None. */ \
70 Py_INCREF(Py_None); target = Py_None; \
76 wxPyMake_TEMPLATE(wxGridCellRenderer)
77 wxPyMake_TEMPLATE(wxGridCellEditor)
78 wxPyMake_TEMPLATE(wxGridCellAttr)
79 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
80 wxPyMake_TEMPLATE(wxGridTableBase)
84 //---------------------------------------------------------------------------
85 // Macros, similar to what's in helpers.h, to aid in the creation of
86 // virtual methods that are able to make callbacks to Python. Many of these
87 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
92 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
93 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
94 wxGridCellAttr* rval = NULL; \
96 wxPyBeginBlockThreads(); \
97 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
99 wxGridCellAttr* ptr; \
100 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
102 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellAttr"))) \
107 wxPyEndBlockThreads(); \
109 rval = PCLASS::CBNAME(a, b, c); \
112 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
113 return PCLASS::CBNAME(a, b, c); \
118 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
119 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
120 wxPyBeginBlockThreads(); \
122 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
123 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
124 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
127 wxPyEndBlockThreads(); \
129 PCLASS::CBNAME(attr, a, b); \
131 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
132 PCLASS::CBNAME(attr, a, b); \
137 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
138 void CBNAME(wxGridCellAttr *attr, int val) { \
139 wxPyBeginBlockThreads(); \
141 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
142 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
143 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
146 wxPyEndBlockThreads(); \
148 PCLASS::CBNAME(attr, val); \
150 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
151 PCLASS::CBNAME(attr, val); \
156 #define PYCALLBACK_INT__pure(CBNAME) \
158 wxPyBeginBlockThreads(); \
160 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
161 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
162 wxPyEndBlockThreads(); \
168 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
169 bool CBNAME(int a, int b) { \
170 wxPyBeginBlockThreads(); \
172 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
173 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
174 wxPyEndBlockThreads(); \
179 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
180 wxString CBNAME(int a, int b) { \
181 wxPyBeginBlockThreads(); \
183 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
185 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
187 rval = Py2wxString(ro); \
191 wxPyEndBlockThreads(); \
196 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
197 void CBNAME(int a, int b, const wxString& c) { \
198 wxPyBeginBlockThreads(); \
199 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
200 PyObject* s = wx2PyString(c); \
201 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
204 wxPyEndBlockThreads(); \
208 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
209 wxString CBNAME(int a, int b) { \
211 wxPyBeginBlockThreads(); \
213 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
215 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
217 rval = Py2wxString(ro); \
221 wxPyEndBlockThreads(); \
223 rval = PCLASS::CBNAME(a, b); \
226 wxString base_##CBNAME(int a, int b) { \
227 return PCLASS::CBNAME(a, b); \
231 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
232 bool CBNAME(int a, int b, const wxString& c) { \
235 wxPyBeginBlockThreads(); \
236 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
237 PyObject* s = wx2PyString(c); \
238 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
241 wxPyEndBlockThreads(); \
243 rval = PCLASS::CBNAME(a,b,c); \
246 bool base_##CBNAME(int a, int b, const wxString& c) { \
247 return PCLASS::CBNAME(a,b,c); \
253 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
254 long CBNAME(int a, int b) { \
257 wxPyBeginBlockThreads(); \
258 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
259 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
260 wxPyEndBlockThreads(); \
262 rval = PCLASS::CBNAME(a,b); \
265 long base_##CBNAME(int a, int b) { \
266 return PCLASS::CBNAME(a,b); \
271 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
272 bool CBNAME(int a, int b) { \
275 wxPyBeginBlockThreads(); \
276 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
277 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
278 wxPyEndBlockThreads(); \
280 rval = PCLASS::CBNAME(a,b); \
283 bool base_##CBNAME(int a, int b) { \
284 return PCLASS::CBNAME(a,b); \
289 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
290 double CBNAME(int a, int b) { \
292 wxPyBeginBlockThreads(); \
294 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
296 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
298 PyObject* str = PyObject_Str(ro); \
299 rval = PyFloat_AsDouble(str); \
300 Py_DECREF(ro); Py_DECREF(str); \
303 wxPyEndBlockThreads(); \
305 rval = PCLASS::CBNAME(a, b); \
308 double base_##CBNAME(int a, int b) { \
309 return PCLASS::CBNAME(a, b); \
314 #define PYCALLBACK__(PCLASS, CBNAME) \
317 wxPyBeginBlockThreads(); \
318 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
319 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
320 wxPyEndBlockThreads(); \
324 void base_##CBNAME() { \
331 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
332 bool CBNAME(size_t a, size_t b) { \
335 wxPyBeginBlockThreads(); \
336 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
337 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
338 wxPyEndBlockThreads(); \
340 rval = PCLASS::CBNAME(a,b); \
343 bool base_##CBNAME(size_t a, size_t b) { \
344 return PCLASS::CBNAME(a,b); \
349 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
350 bool CBNAME(size_t a) { \
353 wxPyBeginBlockThreads(); \
354 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
355 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
356 wxPyEndBlockThreads(); \
358 rval = PCLASS::CBNAME(a); \
361 bool base_##CBNAME(size_t a) { \
362 return PCLASS::CBNAME(a); \
366 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
367 wxString CBNAME(int a) { \
369 wxPyBeginBlockThreads(); \
371 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
373 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
375 rval = Py2wxString(ro); \
379 wxPyEndBlockThreads(); \
381 rval = PCLASS::CBNAME(a); \
384 wxString base_##CBNAME(int a) { \
385 return PCLASS::CBNAME(a); \
389 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
390 void CBNAME(int a, const wxString& c) { \
392 wxPyBeginBlockThreads(); \
393 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
394 PyObject* s = wx2PyString(c); \
395 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \
398 wxPyEndBlockThreads(); \
400 PCLASS::CBNAME(a,c); \
402 void base_##CBNAME(int a, const wxString& c) { \
403 PCLASS::CBNAME(a,c); \
409 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
413 wxPyBeginBlockThreads(); \
414 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
415 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
416 wxPyEndBlockThreads(); \
418 rval = PCLASS::CBNAME(); \
421 bool base_##CBNAME() { \
422 return PCLASS::CBNAME(); \
427 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
428 void CBNAME(size_t a, int b) { \
430 wxPyBeginBlockThreads(); \
431 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
432 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
433 wxPyEndBlockThreads(); \
435 PCLASS::CBNAME(a,b); \
437 void base_##CBNAME(size_t a, int b) { \
438 PCLASS::CBNAME(a,b); \
444 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
445 void CBNAME(int a, int b, long c) { \
447 wxPyBeginBlockThreads(); \
448 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
449 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
450 wxPyEndBlockThreads(); \
452 PCLASS::CBNAME(a,b,c); \
454 void base_##CBNAME(int a, int b, long c) { \
455 PCLASS::CBNAME(a,b,c); \
461 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
462 void CBNAME(int a, int b, double c) { \
464 wxPyBeginBlockThreads(); \
465 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
466 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
467 wxPyEndBlockThreads(); \
469 PCLASS::CBNAME(a,b,c); \
471 void base_##CBNAME(int a, int b, double c) { \
472 PCLASS::CBNAME(a,b,c); \
477 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
478 void CBNAME(int a, int b, bool c) { \
480 wxPyBeginBlockThreads(); \
481 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
482 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
483 wxPyEndBlockThreads(); \
485 PCLASS::CBNAME(a,b,c); \
487 void base_##CBNAME(int a, int b, bool c) { \
488 PCLASS::CBNAME(a,b,c); \
496 //---------------------------------------------------------------------------
498 class wxGridCellCoords;
499 class wxGridCellAttr;
501 #define wxGRID_VALUE_STRING "string"
502 #define wxGRID_VALUE_BOOL "bool"
503 #define wxGRID_VALUE_NUMBER "long"
504 #define wxGRID_VALUE_FLOAT "double"
505 #define wxGRID_VALUE_CHOICE "choice"
506 #define wxGRID_VALUE_TEXT "string"
507 #define wxGRID_VALUE_LONG "long"
508 #define wxGRID_VALUE_CHOICEINT "choiceint"
509 #define wxGRID_VALUE_DATETIME "datetime"
513 const wxGridCellCoords wxGridNoCellCoords;
514 const wxRect wxGridNoCellRect;
518 //---------------------------------------------------------------------------
519 // wxGridCellRenderer is an ABC, and several derived classes are available.
520 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
523 class wxGridCellRenderer
527 void _setOORInfo(PyObject* _self) {
528 self->SetClientObject(new wxPyOORClientData(_self));
532 void SetParameters(const wxString& params);
536 virtual void Draw(wxGrid& grid,
537 wxGridCellAttr& attr,
542 virtual wxSize GetBestSize(wxGrid& grid,
543 wxGridCellAttr& attr,
546 virtual wxGridCellRenderer *Clone() const;
550 // The C++ version of wxPyGridCellRenderer
552 class wxPyGridCellRenderer : public wxGridCellRenderer
555 wxPyGridCellRenderer() : wxGridCellRenderer() {};
557 // Implement Python callback aware virtual methods
558 void Draw(wxGrid& grid, wxGridCellAttr& attr,
559 wxDC& dc, const wxRect& rect,
560 int row, int col, bool isSelected) {
561 wxPyBeginBlockThreads();
562 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
563 PyObject* go = wxPyMake_wxObject(&grid);
564 PyObject* dco = wxPyMake_wxObject(&dc);
565 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
566 PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
568 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
569 row, col, isSelected));
575 wxPyEndBlockThreads();
578 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
581 wxPyBeginBlockThreads();
582 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
585 PyObject* go = wxPyMake_wxObject(&grid);
586 PyObject* dco = wxPyMake_wxObject(&dc);
587 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
589 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
597 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
598 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) {
601 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
602 PyObject* o1 = PySequence_GetItem(ro, 0);
603 PyObject* o2 = PySequence_GetItem(ro, 1);
604 if (PyNumber_Check(o1) && PyNumber_Check(o2))
605 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
607 PyErr_SetString(PyExc_TypeError, errmsg);
612 PyErr_SetString(PyExc_TypeError, errmsg);
617 wxPyEndBlockThreads();
622 wxGridCellRenderer *Clone() const {
623 wxGridCellRenderer* rval = NULL;
624 wxPyBeginBlockThreads();
625 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
627 wxGridCellRenderer* ptr;
628 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
630 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellRenderer")))
635 wxPyEndBlockThreads();
639 DEC_PYCALLBACK__STRING(SetParameters);
644 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
649 // Let SWIG know about it so it can create the Python version
650 class wxPyGridCellRenderer : public wxGridCellRenderer {
652 %pythonAppend wxPyGridCellRenderer "self._setCallbackInfo(self, PyGridCellRenderer);self._setOORInfo(self)"
654 wxPyGridCellRenderer();
655 void _setCallbackInfo(PyObject* self, PyObject* _class);
657 void base_SetParameters(const wxString& params);
660 //---------------------------------------------------------------------------
661 // Predefined Renderers
663 class wxGridCellStringRenderer : public wxGridCellRenderer
666 %pythonAppend wxGridCellStringRenderer "self._setOORInfo(self)"
667 wxGridCellStringRenderer();
671 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
674 %pythonAppend wxGridCellNumberRenderer "self._setOORInfo(self)"
675 wxGridCellNumberRenderer();
679 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
682 %pythonAppend wxGridCellFloatRenderer "self._setOORInfo(self)"
683 wxGridCellFloatRenderer(int width = -1, int precision = -1);
685 int GetWidth() const;
686 void SetWidth(int width);
687 int GetPrecision() const;
688 void SetPrecision(int precision);
692 class wxGridCellBoolRenderer : public wxGridCellRenderer
695 %pythonAppend wxGridCellBoolRenderer "self._setOORInfo(self)"
696 wxGridCellBoolRenderer();
700 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
703 %pythonAppend wxGridCellDateTimeRenderer "self._setOORInfo(self)"
704 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
705 wxString informat = wxPyDateTimeFormatStr);
709 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
712 %pythonAppend wxGridCellEnumRenderer "self._setOORInfo(self)"
713 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
717 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
720 %pythonAppend wxGridCellAutoWrapStringRenderer "self._setOORInfo(self)"
721 wxGridCellAutoWrapStringRenderer();
725 //---------------------------------------------------------------------------
726 // wxGridCellEditor is an ABC, and several derived classes are available.
727 // Classes implemented in Python should be derived from wxPyGridCellEditor.
729 class wxGridCellEditor
733 void _setOORInfo(PyObject* _self) {
734 self->SetClientObject(new wxPyOORClientData(_self));
739 wxControl* GetControl();
740 void SetControl(wxControl* control);
742 wxGridCellAttr* GetCellAttr();
743 void SetCellAttr(wxGridCellAttr* attr);
745 void SetParameters(const wxString& params);
749 virtual void Create(wxWindow* parent,
751 wxEvtHandler* evtHandler);
752 virtual void BeginEdit(int row, int col, wxGrid* grid);
753 virtual bool EndEdit(int row, int col, wxGrid* grid);
754 virtual void Reset();
755 virtual wxGridCellEditor *Clone() const;
757 virtual void SetSize(const wxRect& rect);
758 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
759 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
760 virtual bool IsAcceptedKey(wxKeyEvent& event);
761 virtual void StartingKey(wxKeyEvent& event);
762 virtual void StartingClick();
763 virtual void HandleReturn(wxKeyEvent& event);
764 virtual void Destroy();
769 // The C++ version of wxPyGridCellEditor
771 class wxPyGridCellEditor : public wxGridCellEditor
774 wxPyGridCellEditor() : wxGridCellEditor() {}
776 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
777 wxPyBeginBlockThreads();
778 if (wxPyCBH_findCallback(m_myInst, "Create")) {
779 PyObject* po = wxPyMake_wxObject(parent);
780 PyObject* eo = wxPyMake_wxObject(evtHandler);
782 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
786 wxPyEndBlockThreads();
790 void BeginEdit(int row, int col, wxGrid* grid) {
791 wxPyBeginBlockThreads();
792 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
793 PyObject* go = wxPyMake_wxObject(grid);
794 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
797 wxPyEndBlockThreads();
801 bool EndEdit(int row, int col, wxGrid* grid) {
803 wxPyBeginBlockThreads();
804 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
805 PyObject* go = wxPyMake_wxObject(grid);
806 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
809 wxPyEndBlockThreads();
814 wxGridCellEditor* Clone() const {
815 wxGridCellEditor* rval = NULL;
816 wxPyBeginBlockThreads();
817 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
819 wxGridCellEditor* ptr;
820 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
822 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellEditor")))
827 wxPyEndBlockThreads();
832 void Show(bool show, wxGridCellAttr *attr) {
834 wxPyBeginBlockThreads();
835 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
836 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
837 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
840 wxPyEndBlockThreads();
842 wxGridCellEditor::Show(show, attr);
844 void base_Show(bool show, wxGridCellAttr *attr) {
845 wxGridCellEditor::Show(show, attr);
849 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
851 wxPyBeginBlockThreads();
852 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
853 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
854 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
856 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
861 wxPyEndBlockThreads();
863 wxGridCellEditor::PaintBackground(rectCell, attr);
865 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
866 wxGridCellEditor::PaintBackground(rectCell, attr);
870 DEC_PYCALLBACK___pure(Reset);
871 DEC_PYCALLBACK__constany(SetSize, wxRect);
872 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
873 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
874 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
875 DEC_PYCALLBACK__(StartingClick);
876 DEC_PYCALLBACK__(Destroy);
877 DEC_PYCALLBACK__STRING(SetParameters);
878 DEC_PYCALLBACK_STRING__constpure(GetValue);
884 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
885 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
886 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
887 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
888 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
889 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
890 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
891 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
892 IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
897 // Let SWIG know about it so it can create the Python version
898 class wxPyGridCellEditor : public wxGridCellEditor {
900 %pythonAppend wxPyGridCellEditor "self._setCallbackInfo(self, PyGridCellEditor);self._setOORInfo(self)"
902 wxPyGridCellEditor();
903 void _setCallbackInfo(PyObject* self, PyObject* _class);
905 void base_SetSize(const wxRect& rect);
906 void base_Show(bool show, wxGridCellAttr *attr = NULL);
907 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
908 bool base_IsAcceptedKey(wxKeyEvent& event);
909 void base_StartingKey(wxKeyEvent& event);
910 void base_StartingClick();
911 void base_HandleReturn(wxKeyEvent& event);
913 void base_SetParameters(const wxString& params);
916 //---------------------------------------------------------------------------
917 // Predefined Editors
919 class wxGridCellTextEditor : public wxGridCellEditor
922 %pythonAppend wxGridCellTextEditor "self._setOORInfo(self)"
923 wxGridCellTextEditor();
924 virtual wxString GetValue();
928 class wxGridCellNumberEditor : public wxGridCellTextEditor
931 %pythonAppend wxGridCellNumberEditor "self._setOORInfo(self)"
932 wxGridCellNumberEditor(int min = -1, int max = -1);
933 virtual wxString GetValue();
937 class wxGridCellFloatEditor : public wxGridCellTextEditor
940 %pythonAppend wxGridCellFloatEditor "self._setOORInfo(self)"
941 wxGridCellFloatEditor();
942 virtual wxString GetValue();
946 class wxGridCellBoolEditor : public wxGridCellEditor
949 %pythonAppend wxGridCellBoolEditor "self._setOORInfo(self)"
950 wxGridCellBoolEditor();
951 virtual wxString GetValue();
954 class wxGridCellChoiceEditor : public wxGridCellEditor
957 %pythonAppend wxGridCellChoiceEditor "self._setOORInfo(self)"
958 wxGridCellChoiceEditor(int choices = 0,
959 const wxString* choices_array = NULL,
960 bool allowOthers = False);
961 virtual wxString GetValue();
965 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
968 %pythonAppend wxGridCellEnumEditor "self._setOORInfo(self)"
969 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
970 virtual wxString GetValue();
974 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
977 %pythonAppend wxGridCellAutoWrapStringEditor "self._setOORInfo(self)"
978 wxGridCellAutoWrapStringEditor();
979 virtual wxString GetValue();
984 //---------------------------------------------------------------------------
1001 void _setOORInfo(PyObject* _self) {
1002 self->SetClientObject(new wxPyOORClientData(_self));
1006 %pythonAppend wxGridCellAttr "self._setOORInfo(self)"
1008 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1010 wxGridCellAttr *Clone() const;
1011 void MergeWith(wxGridCellAttr *mergefrom);
1014 void SetTextColour(const wxColour& colText);
1015 void SetBackgroundColour(const wxColour& colBack);
1016 void SetFont(const wxFont& font);
1017 void SetAlignment(int hAlign, int vAlign);
1018 void SetSize(int num_rows, int num_cols);
1019 void SetOverflow( bool allow = True );
1020 void SetReadOnly(bool isReadOnly = True);
1022 void SetRenderer(wxGridCellRenderer *renderer);
1023 void SetEditor(wxGridCellEditor* editor);
1024 void SetKind(wxAttrKind kind);
1026 bool HasTextColour() const;
1027 bool HasBackgroundColour() const;
1028 bool HasFont() const;
1029 bool HasAlignment() const;
1030 bool HasRenderer() const;
1031 bool HasEditor() const;
1032 bool HasReadWriteMode() const;
1033 bool HasOverflowMode() const;
1035 wxColour GetTextColour() const;
1036 wxColour GetBackgroundColour() const;
1037 wxFont GetFont() const;
1040 void, GetAlignment(int *OUTPUT, int *OUTPUT) const,
1041 "GetAlignment() -> (hAlign, vAlign)");
1044 void, GetSize(int *OUTPUT, int *OUTPUT) const,
1045 "GetSize() -> (num_rows, num_cols)");
1047 bool GetOverflow() const;
1048 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1049 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1051 bool IsReadOnly() const;
1052 void SetDefAttr(wxGridCellAttr* defAttr);
1055 //---------------------------------------------------------------------------
1057 class wxGridCellAttrProvider
1060 %pythonAppend wxGridCellAttrProvider "self._setOORInfo(self)"
1061 wxGridCellAttrProvider();
1062 // ???? virtual ~wxGridCellAttrProvider();
1065 void _setOORInfo(PyObject* _self) {
1066 self->SetClientObject(new wxPyOORClientData(_self));
1070 wxGridCellAttr *GetAttr(int row, int col,
1071 wxGridCellAttr::wxAttrKind kind) const;
1072 void SetAttr(wxGridCellAttr *attr, int row, int col);
1073 void SetRowAttr(wxGridCellAttr *attr, int row);
1074 void SetColAttr(wxGridCellAttr *attr, int col);
1076 void UpdateAttrRows( size_t pos, int numRows );
1077 void UpdateAttrCols( size_t pos, int numCols );
1082 // A Python-aware version
1084 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1087 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1089 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1090 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1091 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1092 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1099 // The python-aware version get's SWIGified
1100 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1103 %pythonAppend wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
1104 wxPyGridCellAttrProvider();
1105 void _setCallbackInfo(PyObject* self, PyObject* _class);
1107 wxGridCellAttr *base_GetAttr(int row, int col,
1108 wxGridCellAttr::wxAttrKind kind);
1109 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1110 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1111 void base_SetColAttr(wxGridCellAttr *attr, int col);
1115 //---------------------------------------------------------------------------
1116 // Grid Table Base class and Python aware version
1119 class wxGridTableBase : public wxObject
1122 // wxGridTableBase(); This is an ABC
1123 //~wxGridTableBase();
1126 void _setOORInfo(PyObject* _self) {
1127 self->SetClientObject(new wxPyOORClientData(_self));
1131 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1132 wxGridCellAttrProvider *GetAttrProvider() const;
1133 void SetView( wxGrid *grid );
1134 wxGrid * GetView() const;
1138 virtual int GetNumberRows();
1139 virtual int GetNumberCols();
1140 virtual bool IsEmptyCell( int row, int col );
1141 virtual wxString GetValue( int row, int col );
1142 virtual void SetValue( int row, int col, const wxString& value );
1144 // virtuals overridable in wxPyGridTableBase
1145 virtual wxString GetTypeName( int row, int col );
1146 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1147 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1148 virtual long GetValueAsLong( int row, int col );
1149 virtual double GetValueAsDouble( int row, int col );
1150 virtual bool GetValueAsBool( int row, int col );
1151 virtual void SetValueAsLong( int row, int col, long value );
1152 virtual void SetValueAsDouble( int row, int col, double value );
1153 virtual void SetValueAsBool( int row, int col, bool value );
1155 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1156 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1159 virtual void Clear();
1160 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1161 virtual bool AppendRows( size_t numRows = 1 );
1162 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1163 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1164 virtual bool AppendCols( size_t numCols = 1 );
1165 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1167 virtual wxString GetRowLabelValue( int row );
1168 virtual wxString GetColLabelValue( int col );
1169 virtual void SetRowLabelValue( int row, const wxString& value );
1170 virtual void SetColLabelValue( int col, const wxString& value );
1172 virtual bool CanHaveAttributes();
1174 virtual wxGridCellAttr *GetAttr( int row, int col,
1175 wxGridCellAttr::wxAttrKind kind);
1176 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1177 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1178 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1184 // Python-aware version
1186 class wxPyGridTableBase : public wxGridTableBase
1189 wxPyGridTableBase() : wxGridTableBase() {}
1191 PYCALLBACK_INT__pure(GetNumberRows);
1192 PYCALLBACK_INT__pure(GetNumberCols);
1193 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1194 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1195 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1196 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1197 PYCALLBACK__(wxGridTableBase, Clear);
1198 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1199 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1200 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1201 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1202 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1203 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1204 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1205 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1206 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1207 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1208 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1209 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1210 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1211 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1212 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1215 wxString GetValue(int row, int col) {
1216 wxPyBeginBlockThreads();
1218 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1220 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1222 rval = Py2wxString(ro);
1226 wxPyEndBlockThreads();
1230 void SetValue(int row, int col, const wxString& val) {
1231 wxPyBeginBlockThreads();
1232 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1233 PyObject* s = wx2PyString(val);
1234 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1237 wxPyEndBlockThreads();
1241 // Map the Get/Set methods for the standard non-string types to
1242 // the GetValue and SetValue python methods.
1243 long GetValueAsLong( int row, int col ) {
1245 wxPyBeginBlockThreads();
1246 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1249 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1250 if (ro && PyNumber_Check(ro)) {
1251 num = PyNumber_Int(ro);
1253 rval = PyInt_AsLong(num);
1259 wxPyEndBlockThreads();
1263 double GetValueAsDouble( int row, int col ) {
1265 wxPyBeginBlockThreads();
1266 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1269 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1270 if (ro && PyNumber_Check(ro)) {
1271 num = PyNumber_Float(ro);
1273 rval = PyFloat_AsDouble(num);
1279 wxPyEndBlockThreads();
1283 bool GetValueAsBool( int row, int col ) {
1284 return (bool)GetValueAsLong(row, col);
1287 void SetValueAsLong( int row, int col, long value ) {
1288 wxPyBeginBlockThreads();
1289 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1290 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1292 wxPyEndBlockThreads();
1295 void SetValueAsDouble( int row, int col, double value ) {
1296 wxPyBeginBlockThreads();
1297 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1298 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1300 wxPyEndBlockThreads();
1303 void SetValueAsBool( int row, int col, bool value ) {
1304 SetValueAsLong( row, col, (long)value );
1313 // The python-aware version get's SWIGified
1314 class wxPyGridTableBase : public wxGridTableBase
1317 %pythonAppend wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
1318 wxPyGridTableBase();
1319 void _setCallbackInfo(PyObject* self, PyObject* _class);
1321 %extend { 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 %pythonAppend wxGridStringTable "self._setOORInfo(self)"
1353 wxGridStringTable( int numRows=0, int numCols=0 );
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 //---------------------------------------------------------------------------
1395 class wxGridCellCoords
1398 wxGridCellCoords( int r=-1, int c=-1 );
1399 ~wxGridCellCoords();
1402 void SetRow( int n );
1404 void SetCol( int n );
1405 void Set( int row, int col );
1407 bool operator==( const wxGridCellCoords& other ) const;
1408 bool operator!=( const wxGridCellCoords& other ) const;
1411 PyObject* asTuple() {
1412 PyObject* tup = PyTuple_New(2);
1413 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1414 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
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(in) wxGridCellCoords& (wxGridCellCoords temp) {
1434 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1436 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1437 $1 = wxGridCellCoords_typecheck($input);
1441 // ...and here is the associated helper.
1443 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1445 // If source is an object instance then it may already be the right type
1446 if (wxPySwigInstance_Check(source)) {
1447 wxGridCellCoords* ptr;
1448 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1453 // otherwise a 2-tuple of integers is expected
1454 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1455 PyObject* o1 = PySequence_GetItem(source, 0);
1456 PyObject* o2 = PySequence_GetItem(source, 1);
1457 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1462 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1469 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1474 bool wxGridCellCoords_typecheck(PyObject* source) {
1477 if (wxPySwigInstance_Check(source) &&
1478 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1482 if (PySequence_Check(source) && PySequence_Length(source) == 2)
1490 // Typemap to convert an array of cells coords to a list of tuples...
1491 %typemap(out) wxGridCellCoordsArray {
1492 $result = wxGridCellCoordsArray_helper($1);
1495 // %typemap(ret) wxGridCellCoordsArray {
1500 // ...and the helper function for the above typemap.
1502 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1504 PyObject* list = PyList_New(0);
1506 for (idx = 0; idx < source.GetCount(); idx += 1) {
1507 wxGridCellCoords& coord = source.Item(idx);
1508 PyObject* tup = PyTuple_New(2);
1509 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1510 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1511 PyList_Append(list, tup);
1518 //---------------------------------------------------------------------------
1519 //---------------------------------------------------------------------------
1523 // Fool SWIG into treating this enum as an int
1524 typedef int WXGRIDSELECTIONMODES;
1526 // but let the C++ code know what it really is.
1528 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1533 class wxGrid : public wxScrolledWindow
1536 %pythonAppend wxGrid "self._setOORInfo(self)"
1538 wxGrid( wxWindow *parent,
1540 const wxPoint& pos = wxDefaultPosition,
1541 const wxSize& size = wxDefaultSize,
1542 long style = wxWANTS_CHARS,
1543 const wxString& name = wxPyPanelNameStr);
1546 enum wxGridSelectionModes {
1552 SelectCells = wxGridSelectCells
1553 SelectRows = wxGridSelectRows
1554 SelectColumns = wxGridSelectColumns,
1557 bool CreateGrid( int numRows, int numCols,
1558 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1559 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1560 WXGRIDSELECTIONMODES GetSelectionMode();
1563 // ------ grid dimensions
1565 int GetNumberRows();
1566 int GetNumberCols();
1569 bool ProcessTableMessage( wxGridTableMessage& );
1572 wxGridTableBase * GetTable() const;
1573 bool SetTable( wxGridTableBase *table, bool takeOwnership=False,
1574 WXGRIDSELECTIONMODES selmode =
1575 wxGrid::wxGridSelectCells );
1578 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1579 bool AppendRows( int numRows = 1, bool updateLabels=True );
1580 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1581 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1582 bool AppendCols( int numCols = 1, bool updateLabels=True );
1583 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1586 // this function is called when the current cell highlight must be redrawn
1587 // and may be overridden by the user
1588 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1591 // ------ Cell text drawing functions
1593 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1594 int horizontalAlignment = wxLEFT,
1595 int verticalAlignment = wxTOP,
1596 int textOrientation = wxHORIZONTAL );
1598 // // Split a string containing newline chararcters into an array of
1599 // // strings and return the number of lines
1601 // void StringToLines( const wxString& value, wxArrayString& lines );
1604 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1605 long *OUTPUT, long *OUTPUT ),
1606 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1610 // Code that does a lot of grid modification can be enclosed
1611 // between BeginBatch() and EndBatch() calls to avoid screen
1616 int GetBatchCount();
1617 void ForceRefresh();
1618 void Refresh(bool eraseb=True, const wxRect* rect= NULL);
1621 // ------ edit control functions
1624 void EnableEditing( bool edit );
1626 void EnableCellEditControl( bool enable = True );
1627 void DisableCellEditControl();
1628 bool CanEnableCellControl() const;
1629 bool IsCellEditControlEnabled() const;
1630 bool IsCellEditControlShown() const;
1632 bool IsCurrentCellReadOnly() const;
1634 void ShowCellEditControl();
1635 void HideCellEditControl();
1636 void SaveEditControlValue();
1639 // ------ grid location functions
1640 // Note that all of these functions work with the logical coordinates of
1641 // grid cells and labels so you will need to convert from device
1642 // coordinates for mouse events etc.
1645 //void XYToCell( int x, int y, wxGridCellCoords& );
1647 wxGridCellCoords XYToCell(int x, int y) {
1648 wxGridCellCoords rv;
1649 self->XYToCell(x, y, rv);
1654 int YToRow( int y );
1655 int XToCol( int x );
1657 int YToEdgeOfRow( int y );
1658 int XToEdgeOfCol( int x );
1660 wxRect CellToRect( int row, int col );
1661 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1664 int GetGridCursorRow();
1665 int GetGridCursorCol();
1667 // check to see if a cell is either wholly visible (the default arg) or
1668 // at least partially visible in the grid window
1670 bool IsVisible( int row, int col, bool wholeCellVisible = True );
1671 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = True );
1672 void MakeCellVisible( int row, int col );
1673 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1676 // ------ grid cursor movement functions
1678 void SetGridCursor( int row, int col );
1679 bool MoveCursorUp( bool expandSelection );
1680 bool MoveCursorDown( bool expandSelection );
1681 bool MoveCursorLeft( bool expandSelection );
1682 bool MoveCursorRight( bool expandSelection );
1683 bool MovePageDown();
1685 bool MoveCursorUpBlock( bool expandSelection );
1686 bool MoveCursorDownBlock( bool expandSelection );
1687 bool MoveCursorLeftBlock( bool expandSelection );
1688 bool MoveCursorRightBlock( bool expandSelection );
1691 // ------ label and gridline formatting
1693 int GetDefaultRowLabelSize();
1694 int GetRowLabelSize();
1695 int GetDefaultColLabelSize();
1696 int GetColLabelSize();
1697 wxColour GetLabelBackgroundColour();
1698 wxColour GetLabelTextColour();
1699 wxFont GetLabelFont();
1702 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1703 "GetRowLabelAlignment() -> (horiz, vert)");
1706 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1707 "GetColLabelAlignment() -> (horiz, vert)");
1709 int GetColLabelTextOrientation();
1710 wxString GetRowLabelValue( int row );
1711 wxString GetColLabelValue( int col );
1712 wxColour GetGridLineColour();
1713 wxColour GetCellHighlightColour();
1714 int GetCellHighlightPenWidth();
1715 int GetCellHighlightROPenWidth();
1717 void SetRowLabelSize( int width );
1718 void SetColLabelSize( int height );
1719 void SetLabelBackgroundColour( const wxColour& );
1720 void SetLabelTextColour( const wxColour& );
1721 void SetLabelFont( const wxFont& );
1722 void SetRowLabelAlignment( int horiz, int vert );
1723 void SetColLabelAlignment( int horiz, int vert );
1724 void SetColLabelTextOrientation( int textOrientation );
1725 void SetRowLabelValue( int row, const wxString& );
1726 void SetColLabelValue( int col, const wxString& );
1727 void SetGridLineColour( const wxColour& );
1728 void SetCellHighlightColour( const wxColour& );
1729 void SetCellHighlightPenWidth(int width);
1730 void SetCellHighlightROPenWidth(int width);
1732 void EnableDragRowSize( bool enable = True );
1733 void DisableDragRowSize();
1734 bool CanDragRowSize();
1735 void EnableDragColSize( bool enable = True );
1736 void DisableDragColSize();
1737 bool CanDragColSize();
1738 void EnableDragGridSize(bool enable = True);
1739 void DisableDragGridSize();
1740 bool CanDragGridSize();
1742 // this sets the specified attribute for all cells in this row/col
1743 void SetAttr(int row, int col, wxGridCellAttr *attr);
1744 void SetRowAttr(int row, wxGridCellAttr *attr);
1745 void SetColAttr(int col, wxGridCellAttr *attr);
1747 // shortcuts for setting the column parameters
1749 // set the format for the data in the column: default is string
1750 void SetColFormatBool(int col);
1751 void SetColFormatNumber(int col);
1752 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1753 void SetColFormatCustom(int col, const wxString& typeName);
1755 void EnableGridLines( bool enable = True );
1756 bool GridLinesEnabled();
1758 // ------ row and col formatting
1760 int GetDefaultRowSize();
1761 int GetRowSize( int row );
1762 int GetDefaultColSize();
1763 int GetColSize( int col );
1764 wxColour GetDefaultCellBackgroundColour();
1765 wxColour GetCellBackgroundColour( int row, int col );
1766 wxColour GetDefaultCellTextColour();
1767 wxColour GetCellTextColour( int row, int col );
1768 wxFont GetDefaultCellFont();
1769 wxFont GetCellFont( int row, int col );
1772 void, GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT ),
1773 "GetDefaultCellAlignment() -> (horiz, vert)");
1776 void, GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT ),
1777 "GetCellAlignment() -> (horiz, vert)");
1779 bool GetDefaultCellOverflow();
1780 bool GetCellOverflow( int row, int col );
1783 void, GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT ),
1784 "GetCellSize(int row, int col) -> (num_rows, num_cols)");
1786 void SetDefaultRowSize( int height, bool resizeExistingRows = False );
1787 void SetRowSize( int row, int height );
1788 void SetDefaultColSize( int width, bool resizeExistingCols = False );
1790 void SetColSize( int col, int width );
1792 // automatically size the column or row to fit to its contents, if
1793 // setAsMin is True, this optimal width will also be set as minimal width
1795 void AutoSizeColumn( int col, bool setAsMin = True );
1796 void AutoSizeRow( int row, bool setAsMin = True );
1799 // auto size all columns (very ineffective for big grids!)
1800 void AutoSizeColumns( bool setAsMin = True );
1801 void AutoSizeRows( bool setAsMin = True );
1803 // auto size the grid, that is make the columns/rows of the "right" size
1804 // and also set the grid size to just fit its contents
1807 // autosize row height depending on label text
1808 void AutoSizeRowLabelSize( int row );
1810 // autosize column width depending on label text
1811 void AutoSizeColLabelSize( int col );
1814 // column won't be resized to be lesser width - this must be called during
1815 // the grid creation because it won't resize the column if it's already
1816 // narrower than the minimal width
1817 void SetColMinimalWidth( int col, int width );
1818 void SetRowMinimalHeight( int row, int width );
1820 void SetColMinimalAcceptableWidth( int width );
1821 void SetRowMinimalAcceptableHeight( int width );
1822 int GetColMinimalAcceptableWidth() const;
1823 int GetRowMinimalAcceptableHeight() const;
1825 void SetDefaultCellBackgroundColour( const wxColour& );
1826 void SetCellBackgroundColour( int row, int col, const wxColour& );
1827 void SetDefaultCellTextColour( const wxColour& );
1829 void SetCellTextColour( int row, int col, const wxColour& );
1830 void SetDefaultCellFont( const wxFont& );
1831 void SetCellFont( int row, int col, const wxFont& );
1832 void SetDefaultCellAlignment( int horiz, int vert );
1833 void SetCellAlignment( int row, int col, int horiz, int vert );
1834 void SetDefaultCellOverflow( bool allow );
1835 void SetCellOverflow( int row, int col, bool allow );
1836 void SetCellSize( int row, int col, int num_rows, int num_cols );
1838 // takes ownership of the pointer
1839 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1840 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1841 wxGridCellRenderer *GetDefaultRenderer() const;
1842 wxGridCellRenderer* GetCellRenderer(int row, int col);
1844 // takes ownership of the pointer
1845 void SetDefaultEditor(wxGridCellEditor *editor);
1846 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1847 wxGridCellEditor *GetDefaultEditor() const;
1848 wxGridCellEditor* GetCellEditor(int row, int col);
1852 // ------ cell value accessors
1854 wxString GetCellValue( int row, int col );
1855 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1857 void SetCellValue( int row, int col, const wxString& s );
1858 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1860 // returns True if the cell can't be edited
1861 bool IsReadOnly(int row, int col) const;
1863 // make the cell editable/readonly
1864 void SetReadOnly(int row, int col, bool isReadOnly = True);
1866 // ------ selections of blocks of cells
1868 void SelectRow( int row, bool addToSelected = False );
1869 void SelectCol( int col, bool addToSelected = False );
1871 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1872 bool addToSelected = False );
1873 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1874 // TODO: ??? const wxGridCellCoords& bottomRight )
1878 void ClearSelection();
1879 bool IsInSelection( int row, int col );
1880 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1882 const wxGridCellCoordsArray GetSelectedCells() const;
1883 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1884 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1885 const wxArrayInt GetSelectedRows() const;
1886 const wxArrayInt GetSelectedCols() const;
1888 void DeselectRow( int row );
1889 void DeselectCol( int col );
1890 void DeselectCell( int row, int col );
1893 // This function returns the rectangle that encloses the block of cells
1894 // limited by TopLeft and BottomRight cell in device coords and clipped
1895 // to the client size of the grid window.
1897 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1898 const wxGridCellCoords & bottomRight );
1901 // Access or update the selection fore/back colours
1902 wxColour GetSelectionBackground() const;
1903 wxColour GetSelectionForeground() const;
1905 void SetSelectionBackground(const wxColour& c);
1906 void SetSelectionForeground(const wxColour& c);
1909 // Methods for a registry for mapping data types to Renderers/Editors
1910 void RegisterDataType(const wxString& typeName,
1911 wxGridCellRenderer* renderer,
1912 wxGridCellEditor* editor);
1913 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1914 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1915 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1916 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1917 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1919 // grid may occupy more space than needed for its rows/columns, this
1920 // function allows to set how big this extra space is
1921 void SetMargins(int extraWidth, int extraHeight);
1924 // Accessors for component windows
1925 wxWindow* GetGridWindow();
1926 wxWindow* GetGridRowLabelWindow();
1927 wxWindow* GetGridColLabelWindow();
1928 wxWindow* GetGridCornerLabelWindow();
1934 //---------------------------------------------------------------------------
1935 //---------------------------------------------------------------------------
1936 // Grid events and stuff
1940 class wxGridEvent : public wxNotifyEvent
1943 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1944 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = True,
1945 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1947 virtual int GetRow();
1948 virtual int GetCol();
1949 wxPoint GetPosition();
1959 class wxGridSizeEvent : public wxNotifyEvent
1962 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1963 int rowOrCol=-1, int x=-1, int y=-1,
1964 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1967 wxPoint GetPosition();
1976 class wxGridRangeSelectEvent : public wxNotifyEvent
1979 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1980 const wxGridCellCoords& topLeft,
1981 const wxGridCellCoords& bottomRight,
1983 bool control=False, bool shift=False,
1984 bool alt=False, bool meta=False);
1986 wxGridCellCoords GetTopLeftCoords();
1987 wxGridCellCoords GetBottomRightCoords();
2000 class wxGridEditorCreatedEvent : public wxCommandEvent {
2002 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2003 int row, int col, wxControl* ctrl);
2007 wxControl* GetControl();
2008 void SetRow(int row);
2009 void SetCol(int col);
2010 void SetControl(wxControl* ctrl);
2015 %constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2016 %constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2017 %constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2018 %constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2019 %constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2020 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2021 %constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2022 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2023 %constant wxEventType wxEVT_GRID_ROW_SIZE;
2024 %constant wxEventType wxEVT_GRID_COL_SIZE;
2025 %constant wxEventType wxEVT_GRID_RANGE_SELECT;
2026 %constant wxEventType wxEVT_GRID_CELL_CHANGE;
2027 %constant wxEventType wxEVT_GRID_SELECT_CELL;
2028 %constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2029 %constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2030 %constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2035 EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2036 EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2037 EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2038 EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2039 EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2040 EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2041 EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2042 EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2043 EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2044 EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2045 EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2046 EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2047 EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2048 EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2049 EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2050 EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2053 //---------------------------------------------------------------------------
2058 //---------------------------------------------------------------------------
2059 //---------------------------------------------------------------------------