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>
23 DECLARE_DEF_STRING(PanelNameStr);
24 DECLARE_DEF_STRING2(DateTimeFormatStr, wxT("%c"));
25 static const wxString wxPyEmptyString(wxT(""));
29 //---------------------------------------------------------------------------
32 %pythoncode { wx = core }
34 %include _grid_rename.i
36 //---------------------------------------------------------------------------
37 // OOR related typemaps and helper functions
39 %typemap(out) wxGridCellRenderer* { $result = wxPyMake_wxGridCellRenderer($1); }
40 %typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1); }
41 %typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1); }
42 %typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1); }
43 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1); }
48 #define wxPyMake_TEMPLATE(TYPE) \
49 PyObject* wxPyMake_##TYPE(TYPE* source) { \
50 PyObject* target = NULL; \
52 /* Check if there is already a pointer to a Python object in the \
53 OOR data that we can use. */ \
54 wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \
56 target = data->m_obj; \
59 /* Otherwise make a new wrapper for it the old fashioned way and \
60 give it the OOR treatment */ \
62 target = wxPyConstructObject(source, wxT(#TYPE), False); \
64 source->SetClientObject(new wxPyOORClientData(target)); \
66 } else { /* source was NULL so return None. */ \
67 Py_INCREF(Py_None); target = Py_None; \
73 wxPyMake_TEMPLATE(wxGridCellRenderer)
74 wxPyMake_TEMPLATE(wxGridCellEditor)
75 wxPyMake_TEMPLATE(wxGridCellAttr)
76 wxPyMake_TEMPLATE(wxGridCellAttrProvider)
77 wxPyMake_TEMPLATE(wxGridTableBase)
81 //---------------------------------------------------------------------------
82 // Macros, similar to what's in helpers.h, to aid in the creation of
83 // virtual methods that are able to make callbacks to Python. Many of these
84 // are specific to wxGrid and so are kept here to reduce the mess in helpers.h
89 #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \
90 wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
91 wxGridCellAttr* rval = NULL; \
93 wxPyBeginBlockThreads(); \
94 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
96 wxGridCellAttr* ptr; \
97 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iii)", a, b, c)); \
99 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellAttr"))) \
104 wxPyEndBlockThreads(); \
106 rval = PCLASS::CBNAME(a, b, c); \
109 wxGridCellAttr *base_##CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \
110 return PCLASS::CBNAME(a, b, c); \
115 #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \
116 void CBNAME(wxGridCellAttr *attr, int a, int b) { \
117 wxPyBeginBlockThreads(); \
119 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
120 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
121 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \
124 wxPyEndBlockThreads(); \
126 PCLASS::CBNAME(attr, a, b); \
128 void base_##CBNAME(wxGridCellAttr *attr, int a, int b) { \
129 PCLASS::CBNAME(attr, a, b); \
134 #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \
135 void CBNAME(wxGridCellAttr *attr, int val) { \
136 wxPyBeginBlockThreads(); \
138 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
139 PyObject* obj = wxPyMake_wxGridCellAttr(attr); \
140 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \
143 wxPyEndBlockThreads(); \
145 PCLASS::CBNAME(attr, val); \
147 void base_##CBNAME(wxGridCellAttr *attr, int val) { \
148 PCLASS::CBNAME(attr, val); \
153 #define PYCALLBACK_INT__pure(CBNAME) \
155 wxPyBeginBlockThreads(); \
157 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
158 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
159 wxPyEndBlockThreads(); \
165 #define PYCALLBACK_BOOL_INTINT_pure(CBNAME) \
166 bool CBNAME(int a, int b) { \
167 wxPyBeginBlockThreads(); \
169 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \
170 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
171 wxPyEndBlockThreads(); \
176 #define PYCALLBACK_STRING_INTINT_pure(CBNAME) \
177 wxString CBNAME(int a, int b) { \
178 wxPyBeginBlockThreads(); \
180 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
182 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
184 rval = Py2wxString(ro); \
188 wxPyEndBlockThreads(); \
193 #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \
194 void CBNAME(int a, int b, const wxString& c) { \
195 wxPyBeginBlockThreads(); \
196 if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
197 PyObject* s = wx2PyString(c); \
198 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
201 wxPyEndBlockThreads(); \
205 #define PYCALLBACK_STRING_INTINT(PCLASS, CBNAME) \
206 wxString CBNAME(int a, int b) { \
208 wxPyBeginBlockThreads(); \
210 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
212 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
214 rval = Py2wxString(ro); \
218 wxPyEndBlockThreads(); \
220 rval = PCLASS::CBNAME(a, b); \
223 wxString base_##CBNAME(int a, int b) { \
224 return PCLASS::CBNAME(a, b); \
228 #define PYCALLBACK_BOOL_INTINTSTRING(PCLASS, CBNAME) \
229 bool CBNAME(int a, int b, const wxString& c) { \
232 wxPyBeginBlockThreads(); \
233 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
234 PyObject* s = wx2PyString(c); \
235 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\
238 wxPyEndBlockThreads(); \
240 rval = PCLASS::CBNAME(a,b,c); \
243 bool base_##CBNAME(int a, int b, const wxString& c) { \
244 return PCLASS::CBNAME(a,b,c); \
250 #define PYCALLBACK_LONG_INTINT(PCLASS, CBNAME) \
251 long CBNAME(int a, int b) { \
254 wxPyBeginBlockThreads(); \
255 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
256 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
257 wxPyEndBlockThreads(); \
259 rval = PCLASS::CBNAME(a,b); \
262 long base_##CBNAME(int a, int b) { \
263 return PCLASS::CBNAME(a,b); \
268 #define PYCALLBACK_BOOL_INTINT(PCLASS, CBNAME) \
269 bool CBNAME(int a, int b) { \
272 wxPyBeginBlockThreads(); \
273 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
274 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
275 wxPyEndBlockThreads(); \
277 rval = PCLASS::CBNAME(a,b); \
280 bool base_##CBNAME(int a, int b) { \
281 return PCLASS::CBNAME(a,b); \
286 #define PYCALLBACK_DOUBLE_INTINT(PCLASS, CBNAME) \
287 double CBNAME(int a, int b) { \
289 wxPyBeginBlockThreads(); \
291 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
293 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",a,b)); \
295 PyObject* str = PyObject_Str(ro); \
296 rval = PyFloat_AsDouble(str); \
297 Py_DECREF(ro); Py_DECREF(str); \
300 wxPyEndBlockThreads(); \
302 rval = PCLASS::CBNAME(a, b); \
305 double base_##CBNAME(int a, int b) { \
306 return PCLASS::CBNAME(a, b); \
311 #define PYCALLBACK__(PCLASS, CBNAME) \
314 wxPyBeginBlockThreads(); \
315 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
316 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
317 wxPyEndBlockThreads(); \
321 void base_##CBNAME() { \
328 #define PYCALLBACK_BOOL_SIZETSIZET(PCLASS, CBNAME) \
329 bool CBNAME(size_t a, size_t b) { \
332 wxPyBeginBlockThreads(); \
333 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
334 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
335 wxPyEndBlockThreads(); \
337 rval = PCLASS::CBNAME(a,b); \
340 bool base_##CBNAME(size_t a, size_t b) { \
341 return PCLASS::CBNAME(a,b); \
346 #define PYCALLBACK_BOOL_SIZET(PCLASS, CBNAME) \
347 bool CBNAME(size_t a) { \
350 wxPyBeginBlockThreads(); \
351 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
352 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \
353 wxPyEndBlockThreads(); \
355 rval = PCLASS::CBNAME(a); \
358 bool base_##CBNAME(size_t a) { \
359 return PCLASS::CBNAME(a); \
363 #define PYCALLBACK_STRING_INT(PCLASS, CBNAME) \
364 wxString CBNAME(int a) { \
366 wxPyBeginBlockThreads(); \
368 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
370 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(i)",a)); \
372 rval = Py2wxString(ro); \
376 wxPyEndBlockThreads(); \
378 rval = PCLASS::CBNAME(a); \
381 wxString base_##CBNAME(int a) { \
382 return PCLASS::CBNAME(a); \
386 #define PYCALLBACK__INTSTRING(PCLASS, CBNAME) \
387 void CBNAME(int a, const wxString& c) { \
389 wxPyBeginBlockThreads(); \
390 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
391 PyObject* s = wx2PyString(c); \
392 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \
395 wxPyEndBlockThreads(); \
397 PCLASS::CBNAME(a,c); \
399 void base_##CBNAME(int a, const wxString& c) { \
400 PCLASS::CBNAME(a,c); \
406 #define PYCALLBACK_BOOL_(PCLASS, CBNAME) \
410 wxPyBeginBlockThreads(); \
411 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
412 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
413 wxPyEndBlockThreads(); \
415 rval = PCLASS::CBNAME(); \
418 bool base_##CBNAME() { \
419 return PCLASS::CBNAME(); \
424 #define PYCALLBACK__SIZETINT(PCLASS, CBNAME) \
425 void CBNAME(size_t a, int b) { \
427 wxPyBeginBlockThreads(); \
428 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
429 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \
430 wxPyEndBlockThreads(); \
432 PCLASS::CBNAME(a,b); \
434 void base_##CBNAME(size_t a, int b) { \
435 PCLASS::CBNAME(a,b); \
441 #define PYCALLBACK__INTINTLONG(PCLASS, CBNAME) \
442 void CBNAME(int a, int b, long c) { \
444 wxPyBeginBlockThreads(); \
445 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
446 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
447 wxPyEndBlockThreads(); \
449 PCLASS::CBNAME(a,b,c); \
451 void base_##CBNAME(int a, int b, long c) { \
452 PCLASS::CBNAME(a,b,c); \
458 #define PYCALLBACK__INTINTDOUBLE(PCLASS, CBNAME) \
459 void CBNAME(int a, int b, double c) { \
461 wxPyBeginBlockThreads(); \
462 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
463 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iif)", a,b,c)); \
464 wxPyEndBlockThreads(); \
466 PCLASS::CBNAME(a,b,c); \
468 void base_##CBNAME(int a, int b, double c) { \
469 PCLASS::CBNAME(a,b,c); \
474 #define PYCALLBACK__INTINTBOOL(PCLASS, CBNAME) \
475 void CBNAME(int a, int b, bool c) { \
477 wxPyBeginBlockThreads(); \
478 if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
479 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c)); \
480 wxPyEndBlockThreads(); \
482 PCLASS::CBNAME(a,b,c); \
484 void base_##CBNAME(int a, int b, bool c) { \
485 PCLASS::CBNAME(a,b,c); \
493 //---------------------------------------------------------------------------
495 class wxGridCellCoords;
496 class wxGridCellAttr;
498 #define wxGRID_VALUE_STRING "string"
499 #define wxGRID_VALUE_BOOL "bool"
500 #define wxGRID_VALUE_NUMBER "long"
501 #define wxGRID_VALUE_FLOAT "double"
502 #define wxGRID_VALUE_CHOICE "choice"
503 #define wxGRID_VALUE_TEXT "string"
504 #define wxGRID_VALUE_LONG "long"
505 #define wxGRID_VALUE_CHOICEINT "choiceint"
506 #define wxGRID_VALUE_DATETIME "datetime"
510 const wxGridCellCoords wxGridNoCellCoords;
511 const wxRect wxGridNoCellRect;
515 //---------------------------------------------------------------------------
516 // wxGridCellRenderer is an ABC, and several derived classes are available.
517 // Classes implemented in Python should be derived from wxPyGridCellRenderer.
520 class wxGridCellRenderer
524 void _setOORInfo(PyObject* _self) {
525 self->SetClientObject(new wxPyOORClientData(_self));
529 void SetParameters(const wxString& params);
533 virtual void Draw(wxGrid& grid,
534 wxGridCellAttr& attr,
539 virtual wxSize GetBestSize(wxGrid& grid,
540 wxGridCellAttr& attr,
543 virtual wxGridCellRenderer *Clone() const;
547 // The C++ version of wxPyGridCellRenderer
549 class wxPyGridCellRenderer : public wxGridCellRenderer
552 wxPyGridCellRenderer() : wxGridCellRenderer() {};
554 // Implement Python callback aware virtual methods
555 void Draw(wxGrid& grid, wxGridCellAttr& attr,
556 wxDC& dc, const wxRect& rect,
557 int row, int col, bool isSelected) {
558 wxPyBeginBlockThreads();
559 if (wxPyCBH_findCallback(m_myInst, "Draw")) {
560 PyObject* go = wxPyMake_wxObject(&grid);
561 PyObject* dco = wxPyMake_wxObject(&dc);
562 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
563 PyObject* ro = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
565 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro,
566 row, col, isSelected));
572 wxPyEndBlockThreads();
575 wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
578 wxPyBeginBlockThreads();
579 if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) {
582 PyObject* go = wxPyMake_wxObject(&grid);
583 PyObject* dco = wxPyMake_wxObject(&dc);
584 PyObject* ao = wxPyMake_wxGridCellAttr(&attr);
586 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)",
594 const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object.";
595 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxSize"))) {
598 else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
599 PyObject* o1 = PySequence_GetItem(ro, 0);
600 PyObject* o2 = PySequence_GetItem(ro, 1);
601 if (PyNumber_Check(o1) && PyNumber_Check(o2))
602 rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2));
604 PyErr_SetString(PyExc_TypeError, errmsg);
609 PyErr_SetString(PyExc_TypeError, errmsg);
614 wxPyEndBlockThreads();
619 wxGridCellRenderer *Clone() const {
620 wxGridCellRenderer* rval = NULL;
621 wxPyBeginBlockThreads();
622 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
624 wxGridCellRenderer* ptr;
625 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
627 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellRenderer")))
632 wxPyEndBlockThreads();
636 DEC_PYCALLBACK__STRING(SetParameters);
641 IMP_PYCALLBACK__STRING( wxPyGridCellRenderer, wxGridCellRenderer, SetParameters);
646 // Let SWIG know about it so it can create the Python version
647 class wxPyGridCellRenderer : public wxGridCellRenderer {
649 %addtofunc wxPyGridCellRenderer "self._setCallbackInfo(self, PyGridCellRenderer);self._setOORInfo(self)"
651 wxPyGridCellRenderer();
652 void _setCallbackInfo(PyObject* self, PyObject* _class);
654 void base_SetParameters(const wxString& params);
657 //---------------------------------------------------------------------------
658 // Predefined Renderers
660 class wxGridCellStringRenderer : public wxGridCellRenderer
663 %addtofunc wxGridCellStringRenderer "self._setOORInfo(self)"
664 wxGridCellStringRenderer();
668 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
671 %addtofunc wxGridCellNumberRenderer "self._setOORInfo(self)"
672 wxGridCellNumberRenderer();
676 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
679 %addtofunc wxGridCellFloatRenderer "self._setOORInfo(self)"
680 wxGridCellFloatRenderer(int width = -1, int precision = -1);
682 int GetWidth() const;
683 void SetWidth(int width);
684 int GetPrecision() const;
685 void SetPrecision(int precision);
689 class wxGridCellBoolRenderer : public wxGridCellRenderer
692 %addtofunc wxGridCellBoolRenderer "self._setOORInfo(self)"
693 wxGridCellBoolRenderer();
697 class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
700 %addtofunc wxGridCellDateTimeRenderer "self._setOORInfo(self)"
701 wxGridCellDateTimeRenderer(wxString outformat = wxPyDateTimeFormatStr,
702 wxString informat = wxPyDateTimeFormatStr);
706 class wxGridCellEnumRenderer : public wxGridCellStringRenderer
709 %addtofunc wxGridCellEnumRenderer "self._setOORInfo(self)"
710 wxGridCellEnumRenderer( const wxString& choices = wxPyEmptyString );
714 class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
717 %addtofunc wxGridCellAutoWrapStringRenderer "self._setOORInfo(self)"
718 wxGridCellAutoWrapStringRenderer();
722 //---------------------------------------------------------------------------
723 // wxGridCellEditor is an ABC, and several derived classes are available.
724 // Classes implemented in Python should be derived from wxPyGridCellEditor.
726 class wxGridCellEditor
730 void _setOORInfo(PyObject* _self) {
731 self->SetClientObject(new wxPyOORClientData(_self));
736 wxControl* GetControl();
737 void SetControl(wxControl* control);
739 wxGridCellAttr* GetCellAttr();
740 void SetCellAttr(wxGridCellAttr* attr);
742 void SetParameters(const wxString& params);
746 virtual void Create(wxWindow* parent,
748 wxEvtHandler* evtHandler);
749 virtual void BeginEdit(int row, int col, wxGrid* grid);
750 virtual bool EndEdit(int row, int col, wxGrid* grid);
751 virtual void Reset();
752 virtual wxGridCellEditor *Clone() const;
754 virtual void SetSize(const wxRect& rect);
755 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
756 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
757 virtual bool IsAcceptedKey(wxKeyEvent& event);
758 virtual void StartingKey(wxKeyEvent& event);
759 virtual void StartingClick();
760 virtual void HandleReturn(wxKeyEvent& event);
761 virtual void Destroy();
766 // The C++ version of wxPyGridCellEditor
768 class wxPyGridCellEditor : public wxGridCellEditor
771 wxPyGridCellEditor() : wxGridCellEditor() {}
773 void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) {
774 wxPyBeginBlockThreads();
775 if (wxPyCBH_findCallback(m_myInst, "Create")) {
776 PyObject* po = wxPyMake_wxObject(parent);
777 PyObject* eo = wxPyMake_wxObject(evtHandler);
779 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo));
783 wxPyEndBlockThreads();
787 void BeginEdit(int row, int col, wxGrid* grid) {
788 wxPyBeginBlockThreads();
789 if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) {
790 PyObject* go = wxPyMake_wxObject(grid);
791 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
794 wxPyEndBlockThreads();
798 bool EndEdit(int row, int col, wxGrid* grid) {
800 wxPyBeginBlockThreads();
801 if (wxPyCBH_findCallback(m_myInst, "EndEdit")) {
802 PyObject* go = wxPyMake_wxObject(grid);
803 rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go));
806 wxPyEndBlockThreads();
811 wxGridCellEditor* Clone() const {
812 wxGridCellEditor* rval = NULL;
813 wxPyBeginBlockThreads();
814 if (wxPyCBH_findCallback(m_myInst, "Clone")) {
816 wxGridCellEditor* ptr;
817 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
819 if (wxPyConvertSwigPtr(ro, (void **)&ptr, wxT("wxGridCellEditor")))
824 wxPyEndBlockThreads();
829 void Show(bool show, wxGridCellAttr *attr) {
831 wxPyBeginBlockThreads();
832 if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) {
833 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
834 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao));
837 wxPyEndBlockThreads();
839 wxGridCellEditor::Show(show, attr);
841 void base_Show(bool show, wxGridCellAttr *attr) {
842 wxGridCellEditor::Show(show, attr);
846 void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
848 wxPyBeginBlockThreads();
849 if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) {
850 PyObject* ao = wxPyMake_wxGridCellAttr(attr);
851 PyObject* ro = wxPyConstructObject((void*)&rectCell, wxT("wxRect"), 0);
853 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao));
858 wxPyEndBlockThreads();
860 wxGridCellEditor::PaintBackground(rectCell, attr);
862 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) {
863 wxGridCellEditor::PaintBackground(rectCell, attr);
867 DEC_PYCALLBACK___pure(Reset);
868 DEC_PYCALLBACK__constany(SetSize, wxRect);
869 DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
870 DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
871 DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
872 DEC_PYCALLBACK__(StartingClick);
873 DEC_PYCALLBACK__(Destroy);
874 DEC_PYCALLBACK__STRING(SetParameters);
875 DEC_PYCALLBACK_STRING__constpure(GetValue);
881 IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
882 IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
883 IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
884 IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
885 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
886 IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
887 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
888 IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, Destroy);
889 IMP_PYCALLBACK_STRING__constpure(wxPyGridCellEditor, wxGridCellEditor, GetValue);
894 // Let SWIG know about it so it can create the Python version
895 class wxPyGridCellEditor : public wxGridCellEditor {
897 %addtofunc wxPyGridCellEditor "self._setCallbackInfo(self, PyGridCellEditor);self._setOORInfo(self)"
899 wxPyGridCellEditor();
900 void _setCallbackInfo(PyObject* self, PyObject* _class);
902 void base_SetSize(const wxRect& rect);
903 void base_Show(bool show, wxGridCellAttr *attr = NULL);
904 void base_PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
905 bool base_IsAcceptedKey(wxKeyEvent& event);
906 void base_StartingKey(wxKeyEvent& event);
907 void base_StartingClick();
908 void base_HandleReturn(wxKeyEvent& event);
910 void base_SetParameters(const wxString& params);
913 //---------------------------------------------------------------------------
914 // Predefined Editors
916 class wxGridCellTextEditor : public wxGridCellEditor
919 %addtofunc wxGridCellTextEditor "self._setOORInfo(self)"
920 wxGridCellTextEditor();
921 virtual wxString GetValue();
925 class wxGridCellNumberEditor : public wxGridCellTextEditor
928 %addtofunc wxGridCellNumberEditor "self._setOORInfo(self)"
929 wxGridCellNumberEditor(int min = -1, int max = -1);
930 virtual wxString GetValue();
934 class wxGridCellFloatEditor : public wxGridCellTextEditor
937 %addtofunc wxGridCellFloatEditor "self._setOORInfo(self)"
938 wxGridCellFloatEditor();
939 virtual wxString GetValue();
943 class wxGridCellBoolEditor : public wxGridCellEditor
946 %addtofunc wxGridCellBoolEditor "self._setOORInfo(self)"
947 wxGridCellBoolEditor();
948 virtual wxString GetValue();
951 class wxGridCellChoiceEditor : public wxGridCellEditor
954 %addtofunc wxGridCellChoiceEditor "self._setOORInfo(self)"
955 wxGridCellChoiceEditor(int choices = 0,
956 const wxString* choices_array = NULL,
957 bool allowOthers = False);
958 virtual wxString GetValue();
962 class wxGridCellEnumEditor : public wxGridCellChoiceEditor
965 %addtofunc wxGridCellEnumEditor "self._setOORInfo(self)"
966 wxGridCellEnumEditor( const wxString& choices = wxPyEmptyString );
967 virtual wxString GetValue();
971 class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
974 %addtofunc wxGridCellAutoWrapStringEditor "self._setOORInfo(self)"
975 wxGridCellAutoWrapStringEditor();
976 virtual wxString GetValue();
981 //---------------------------------------------------------------------------
998 void _setOORInfo(PyObject* _self) {
999 self->SetClientObject(new wxPyOORClientData(_self));
1003 %addtofunc wxGridCellAttr "self._setOORInfo(self)"
1005 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL);
1007 wxGridCellAttr *Clone() const;
1008 void MergeWith(wxGridCellAttr *mergefrom);
1011 void SetTextColour(const wxColour& colText);
1012 void SetBackgroundColour(const wxColour& colBack);
1013 void SetFont(const wxFont& font);
1014 void SetAlignment(int hAlign, int vAlign);
1015 void SetSize(int num_rows, int num_cols);
1016 void SetOverflow( bool allow = True );
1017 void SetReadOnly(bool isReadOnly = True);
1019 void SetRenderer(wxGridCellRenderer *renderer);
1020 void SetEditor(wxGridCellEditor* editor);
1021 void SetKind(wxAttrKind kind);
1023 bool HasTextColour() const;
1024 bool HasBackgroundColour() const;
1025 bool HasFont() const;
1026 bool HasAlignment() const;
1027 bool HasRenderer() const;
1028 bool HasEditor() const;
1029 bool HasReadWriteMode() const;
1030 bool HasOverflowMode() const;
1032 wxColour GetTextColour() const;
1033 wxColour GetBackgroundColour() const;
1034 wxFont GetFont() const;
1037 void, GetAlignment(int *OUTPUT, int *OUTPUT) const,
1038 "GetAlignment() -> (hAlign, vAlign)");
1041 void, GetSize(int *OUTPUT, int *OUTPUT) const,
1042 "GetSize() -> (num_rows, num_cols)");
1044 bool GetOverflow() const;
1045 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
1046 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
1048 bool IsReadOnly() const;
1049 void SetDefAttr(wxGridCellAttr* defAttr);
1052 //---------------------------------------------------------------------------
1054 class wxGridCellAttrProvider
1057 %addtofunc wxGridCellAttrProvider "self._setOORInfo(self)"
1058 wxGridCellAttrProvider();
1059 // ???? virtual ~wxGridCellAttrProvider();
1062 void _setOORInfo(PyObject* _self) {
1063 self->SetClientObject(new wxPyOORClientData(_self));
1067 wxGridCellAttr *GetAttr(int row, int col,
1068 wxGridCellAttr::wxAttrKind kind) const;
1069 void SetAttr(wxGridCellAttr *attr, int row, int col);
1070 void SetRowAttr(wxGridCellAttr *attr, int row);
1071 void SetColAttr(wxGridCellAttr *attr, int col);
1073 void UpdateAttrRows( size_t pos, int numRows );
1074 void UpdateAttrCols( size_t pos, int numCols );
1079 // A Python-aware version
1081 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1084 wxPyGridCellAttrProvider() : wxGridCellAttrProvider() {};
1086 PYCALLBACK_GCA_INTINTKIND(wxGridCellAttrProvider, GetAttr);
1087 PYCALLBACK__GCAINTINT(wxGridCellAttrProvider, SetAttr);
1088 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetRowAttr);
1089 PYCALLBACK__GCAINT(wxGridCellAttrProvider, SetColAttr);
1096 // The python-aware version get's SWIGified
1097 class wxPyGridCellAttrProvider : public wxGridCellAttrProvider
1100 %addtofunc wxPyGridCellAttrProvider "self._setCallbackInfo(self, PyGridCellAttrProvider)"
1101 wxPyGridCellAttrProvider();
1102 void _setCallbackInfo(PyObject* self, PyObject* _class);
1104 wxGridCellAttr *base_GetAttr(int row, int col,
1105 wxGridCellAttr::wxAttrKind kind);
1106 void base_SetAttr(wxGridCellAttr *attr, int row, int col);
1107 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1108 void base_SetColAttr(wxGridCellAttr *attr, int col);
1112 //---------------------------------------------------------------------------
1113 // Grid Table Base class and Python aware version
1116 class wxGridTableBase : public wxObject
1119 // wxGridTableBase(); This is an ABC
1120 //~wxGridTableBase();
1123 void _setOORInfo(PyObject* _self) {
1124 self->SetClientObject(new wxPyOORClientData(_self));
1128 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
1129 wxGridCellAttrProvider *GetAttrProvider() const;
1130 void SetView( wxGrid *grid );
1131 wxGrid * GetView() const;
1135 virtual int GetNumberRows();
1136 virtual int GetNumberCols();
1137 virtual bool IsEmptyCell( int row, int col );
1138 virtual wxString GetValue( int row, int col );
1139 virtual void SetValue( int row, int col, const wxString& value );
1141 // virtuals overridable in wxPyGridTableBase
1142 virtual wxString GetTypeName( int row, int col );
1143 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
1144 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
1145 virtual long GetValueAsLong( int row, int col );
1146 virtual double GetValueAsDouble( int row, int col );
1147 virtual bool GetValueAsBool( int row, int col );
1148 virtual void SetValueAsLong( int row, int col, long value );
1149 virtual void SetValueAsDouble( int row, int col, double value );
1150 virtual void SetValueAsBool( int row, int col, bool value );
1152 //virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
1153 //virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
1156 virtual void Clear();
1157 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1158 virtual bool AppendRows( size_t numRows = 1 );
1159 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1160 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1161 virtual bool AppendCols( size_t numCols = 1 );
1162 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1164 virtual wxString GetRowLabelValue( int row );
1165 virtual wxString GetColLabelValue( int col );
1166 virtual void SetRowLabelValue( int row, const wxString& value );
1167 virtual void SetColLabelValue( int col, const wxString& value );
1169 virtual bool CanHaveAttributes();
1171 virtual wxGridCellAttr *GetAttr( int row, int col,
1172 wxGridCellAttr::wxAttrKind kind);
1173 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
1174 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
1175 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1181 // Python-aware version
1183 class wxPyGridTableBase : public wxGridTableBase
1186 wxPyGridTableBase() : wxGridTableBase() {}
1188 PYCALLBACK_INT__pure(GetNumberRows);
1189 PYCALLBACK_INT__pure(GetNumberCols);
1190 PYCALLBACK_BOOL_INTINT_pure(IsEmptyCell);
1191 PYCALLBACK_STRING_INTINT(wxGridTableBase, GetTypeName);
1192 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanGetValueAs);
1193 PYCALLBACK_BOOL_INTINTSTRING(wxGridTableBase, CanSetValueAs);
1194 PYCALLBACK__(wxGridTableBase, Clear);
1195 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertRows);
1196 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteRows);
1197 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, InsertCols);
1198 PYCALLBACK_BOOL_SIZETSIZET(wxGridTableBase, DeleteCols);
1199 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendRows);
1200 PYCALLBACK_BOOL_SIZET(wxGridTableBase, AppendCols);
1201 PYCALLBACK_STRING_INT(wxGridTableBase, GetRowLabelValue);
1202 PYCALLBACK_STRING_INT(wxGridTableBase, GetColLabelValue);
1203 PYCALLBACK__INTSTRING(wxGridTableBase, SetRowLabelValue);
1204 PYCALLBACK__INTSTRING(wxGridTableBase, SetColLabelValue);
1205 PYCALLBACK_BOOL_(wxGridTableBase, CanHaveAttributes);
1206 PYCALLBACK_GCA_INTINTKIND(wxGridTableBase, GetAttr);
1207 PYCALLBACK__GCAINTINT(wxGridTableBase, SetAttr);
1208 PYCALLBACK__GCAINT(wxGridTableBase, SetRowAttr);
1209 PYCALLBACK__GCAINT(wxGridTableBase, SetColAttr);
1212 wxString GetValue(int row, int col) {
1213 wxPyBeginBlockThreads();
1215 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1217 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)",row,col));
1219 rval = Py2wxString(ro);
1223 wxPyEndBlockThreads();
1227 void SetValue(int row, int col, const wxString& val) {
1228 wxPyBeginBlockThreads();
1229 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1230 PyObject* s = wx2PyString(val);
1231 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s));
1234 wxPyEndBlockThreads();
1238 // Map the Get/Set methods for the standard non-string types to
1239 // the GetValue and SetValue python methods.
1240 long GetValueAsLong( int row, int col ) {
1242 wxPyBeginBlockThreads();
1243 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1246 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1247 if (ro && PyNumber_Check(ro)) {
1248 num = PyNumber_Int(ro);
1250 rval = PyInt_AsLong(num);
1256 wxPyEndBlockThreads();
1260 double GetValueAsDouble( int row, int col ) {
1262 wxPyBeginBlockThreads();
1263 if (wxPyCBH_findCallback(m_myInst, "GetValue")) {
1266 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(ii)", row, col));
1267 if (ro && PyNumber_Check(ro)) {
1268 num = PyNumber_Float(ro);
1270 rval = PyFloat_AsDouble(num);
1276 wxPyEndBlockThreads();
1280 bool GetValueAsBool( int row, int col ) {
1281 return (bool)GetValueAsLong(row, col);
1284 void SetValueAsLong( int row, int col, long value ) {
1285 wxPyBeginBlockThreads();
1286 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1287 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", row, col, value));
1289 wxPyEndBlockThreads();
1292 void SetValueAsDouble( int row, int col, double value ) {
1293 wxPyBeginBlockThreads();
1294 if (wxPyCBH_findCallback(m_myInst, "SetValue")) {
1295 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iid)", row, col, value));
1297 wxPyEndBlockThreads();
1300 void SetValueAsBool( int row, int col, bool value ) {
1301 SetValueAsLong( row, col, (long)value );
1310 // The python-aware version get's SWIGified
1311 class wxPyGridTableBase : public wxGridTableBase
1314 %addtofunc wxPyGridTableBase "self._setCallbackInfo(self, PyGridTableBase);self._setOORInfo(self)"
1315 wxPyGridTableBase();
1316 void _setCallbackInfo(PyObject* self, PyObject* _class);
1318 %extend { void Destroy() { delete self; } }
1320 wxString base_GetTypeName( int row, int col );
1321 bool base_CanGetValueAs( int row, int col, const wxString& typeName );
1322 bool base_CanSetValueAs( int row, int col, const wxString& typeName );
1324 bool base_InsertRows( size_t pos = 0, size_t numRows = 1 );
1325 bool base_AppendRows( size_t numRows = 1 );
1326 bool base_DeleteRows( size_t pos = 0, size_t numRows = 1 );
1327 bool base_InsertCols( size_t pos = 0, size_t numCols = 1 );
1328 bool base_AppendCols( size_t numCols = 1 );
1329 bool base_DeleteCols( size_t pos = 0, size_t numCols = 1 );
1330 wxString base_GetRowLabelValue( int row );
1331 wxString base_GetColLabelValue( int col );
1332 void base_SetRowLabelValue( int row, const wxString& value );
1333 void base_SetColLabelValue( int col, const wxString& value );
1334 bool base_CanHaveAttributes();
1335 wxGridCellAttr *base_GetAttr( int row, int col,
1336 wxGridCellAttr::wxAttrKind kind );
1337 void base_SetAttr(wxGridCellAttr* attr, int row, int col);
1338 void base_SetRowAttr(wxGridCellAttr *attr, int row);
1339 void base_SetColAttr(wxGridCellAttr *attr, int col);
1343 //---------------------------------------------------------------------------
1344 // Predefined Tables
1346 class wxGridStringTable : public wxGridTableBase
1349 %addtofunc wxGridStringTable "self._setOORInfo(self)"
1350 wxGridStringTable( int numRows=0, int numCols=0 );
1353 //---------------------------------------------------------------------------
1354 // The Table can pass messages to the grid to tell it to update itself if
1355 // something has changed.
1357 enum wxGridTableRequest
1359 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1360 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1361 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1362 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1363 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1364 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1365 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1366 wxGRIDTABLE_NOTIFY_COLS_DELETED
1370 class wxGridTableMessage
1373 wxGridTableMessage( wxGridTableBase *table, int id,
1376 ~wxGridTableMessage();
1378 void SetTableObject( wxGridTableBase *table );
1379 wxGridTableBase * GetTableObject() const;
1380 void SetId( int id );
1382 void SetCommandInt( int comInt1 );
1383 int GetCommandInt();
1384 void SetCommandInt2( int comInt2 );
1385 int GetCommandInt2();
1389 //---------------------------------------------------------------------------
1392 class wxGridCellCoords
1395 wxGridCellCoords( int r=-1, int c=-1 );
1396 ~wxGridCellCoords();
1399 void SetRow( int n );
1401 void SetCol( int n );
1402 void Set( int row, int col );
1404 bool operator==( const wxGridCellCoords& other ) const;
1405 bool operator!=( const wxGridCellCoords& other ) const;
1408 PyObject* asTuple() {
1409 PyObject* tup = PyTuple_New(2);
1410 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
1411 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
1416 def __str__(self): return str(self.asTuple())
1417 def __repr__(self): return 'wxGridCellCoords'+str(self.asTuple())
1418 def __len__(self): return len(self.asTuple())
1419 def __getitem__(self, index): return self.asTuple()[index]
1420 def __setitem__(self, index, val):
1421 if index == 0: self.SetRow(val)
1422 elif index == 1: self.SetCol(val)
1423 else: raise IndexError
1428 // Typemap to allow conversion of sequence objects to wxGridCellCoords...
1429 %typemap(in) wxGridCellCoords& (wxGridCellCoords temp) {
1431 if (! wxGridCellCoords_helper($input, &$1)) SWIG_fail;
1433 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGridCellCoords& {
1434 $1 = wxGridCellCoords_typecheck($input);
1438 // ...and here is the associated helper.
1440 bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) {
1442 // If source is an object instance then it may already be the right type
1443 if (wxPySwigInstance_Check(source)) {
1444 wxGridCellCoords* ptr;
1445 if (! wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1450 // otherwise a 2-tuple of integers is expected
1451 else if (PySequence_Check(source) && PyObject_Length(source) == 2) {
1452 PyObject* o1 = PySequence_GetItem(source, 0);
1453 PyObject* o2 = PySequence_GetItem(source, 1);
1454 if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
1459 **obj = wxGridCellCoords(PyInt_AsLong(o1), PyInt_AsLong(o2));
1466 PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of integers or a wxGridCellCoords object.");
1471 bool wxGridCellCoords_typecheck(PyObject* source) {
1474 if (wxPySwigInstance_Check(source) &&
1475 wxPyConvertSwigPtr(source, (void **)&ptr, wxT("wxGridCellCoords")))
1479 if (PySequence_Check(source) && PySequence_Length(source) == 2)
1487 // Typemap to convert an array of cells coords to a list of tuples...
1488 %typemap(out) wxGridCellCoordsArray {
1489 $result = wxGridCellCoordsArray_helper($1);
1492 // %typemap(ret) wxGridCellCoordsArray {
1497 // ...and the helper function for the above typemap.
1499 PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray& source)
1501 PyObject* list = PyList_New(0);
1503 for (idx = 0; idx < source.GetCount(); idx += 1) {
1504 wxGridCellCoords& coord = source.Item(idx);
1505 PyObject* tup = PyTuple_New(2);
1506 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow()));
1507 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol()));
1508 PyList_Append(list, tup);
1515 //---------------------------------------------------------------------------
1516 //---------------------------------------------------------------------------
1520 // Fool SWIG into treating this enum as an int
1521 typedef int WXGRIDSELECTIONMODES;
1523 // but let the C++ code know what it really is.
1525 typedef wxGrid::wxGridSelectionModes WXGRIDSELECTIONMODES;
1530 class wxGrid : public wxScrolledWindow
1533 %addtofunc wxGrid "self._setOORInfo(self)"
1535 wxGrid( wxWindow *parent,
1537 const wxPoint& pos = wxDefaultPosition,
1538 const wxSize& size = wxDefaultSize,
1539 long style = wxWANTS_CHARS,
1540 const wxString& name = wxPyPanelNameStr);
1543 enum wxGridSelectionModes {wxGridSelectCells,
1545 wxGridSelectColumns};
1547 bool CreateGrid( int numRows, int numCols,
1548 WXGRIDSELECTIONMODES selmode = wxGrid::wxGridSelectCells );
1549 void SetSelectionMode(WXGRIDSELECTIONMODES selmode);
1550 WXGRIDSELECTIONMODES GetSelectionMode();
1553 // ------ grid dimensions
1555 int GetNumberRows();
1556 int GetNumberCols();
1559 bool ProcessTableMessage( wxGridTableMessage& );
1562 wxGridTableBase * GetTable() const;
1563 bool SetTable( wxGridTableBase *table, bool takeOwnership=False,
1564 WXGRIDSELECTIONMODES selmode =
1565 wxGrid::wxGridSelectCells );
1568 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1569 bool AppendRows( int numRows = 1, bool updateLabels=True );
1570 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=True );
1571 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1572 bool AppendCols( int numCols = 1, bool updateLabels=True );
1573 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=True );
1576 // this function is called when the current cell highlight must be redrawn
1577 // and may be overridden by the user
1578 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1581 // ------ Cell text drawing functions
1583 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
1584 int horizontalAlignment = wxLEFT,
1585 int verticalAlignment = wxTOP,
1586 int textOrientation = wxHORIZONTAL );
1588 // // Split a string containing newline chararcters into an array of
1589 // // strings and return the number of lines
1591 // void StringToLines( const wxString& value, wxArrayString& lines );
1594 void, GetTextBoxSize( wxDC& dc, wxArrayString& lines,
1595 long *OUTPUT, long *OUTPUT ),
1596 "GetTextBoxSize(DC dc, list lines) -> (width, height)");
1600 // Code that does a lot of grid modification can be enclosed
1601 // between BeginBatch() and EndBatch() calls to avoid screen
1606 int GetBatchCount();
1607 void ForceRefresh();
1608 void Refresh(bool eraseb=True, const wxRect* rect= NULL);
1611 // ------ edit control functions
1614 void EnableEditing( bool edit );
1616 void EnableCellEditControl( bool enable = True );
1617 void DisableCellEditControl();
1618 bool CanEnableCellControl() const;
1619 bool IsCellEditControlEnabled() const;
1620 bool IsCellEditControlShown() const;
1622 bool IsCurrentCellReadOnly() const;
1624 void ShowCellEditControl();
1625 void HideCellEditControl();
1626 void SaveEditControlValue();
1629 // ------ grid location functions
1630 // Note that all of these functions work with the logical coordinates of
1631 // grid cells and labels so you will need to convert from device
1632 // coordinates for mouse events etc.
1635 //void XYToCell( int x, int y, wxGridCellCoords& );
1637 wxGridCellCoords XYToCell(int x, int y) {
1638 wxGridCellCoords rv;
1639 self->XYToCell(x, y, rv);
1644 int YToRow( int y );
1645 int XToCol( int x );
1647 int YToEdgeOfRow( int y );
1648 int XToEdgeOfCol( int x );
1650 wxRect CellToRect( int row, int col );
1651 // TODO: ??? wxRect CellToRect( const wxGridCellCoords& coords );
1654 int GetGridCursorRow();
1655 int GetGridCursorCol();
1657 // check to see if a cell is either wholly visible (the default arg) or
1658 // at least partially visible in the grid window
1660 bool IsVisible( int row, int col, bool wholeCellVisible = True );
1661 // TODO: ??? bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = True );
1662 void MakeCellVisible( int row, int col );
1663 // TODO: ??? void MakeCellVisible( const wxGridCellCoords& coords );
1666 // ------ grid cursor movement functions
1668 void SetGridCursor( int row, int col );
1669 bool MoveCursorUp( bool expandSelection );
1670 bool MoveCursorDown( bool expandSelection );
1671 bool MoveCursorLeft( bool expandSelection );
1672 bool MoveCursorRight( bool expandSelection );
1673 bool MovePageDown();
1675 bool MoveCursorUpBlock( bool expandSelection );
1676 bool MoveCursorDownBlock( bool expandSelection );
1677 bool MoveCursorLeftBlock( bool expandSelection );
1678 bool MoveCursorRightBlock( bool expandSelection );
1681 // ------ label and gridline formatting
1683 int GetDefaultRowLabelSize();
1684 int GetRowLabelSize();
1685 int GetDefaultColLabelSize();
1686 int GetColLabelSize();
1687 wxColour GetLabelBackgroundColour();
1688 wxColour GetLabelTextColour();
1689 wxFont GetLabelFont();
1692 void, GetRowLabelAlignment( int *OUTPUT, int *OUTPUT ),
1693 "GetRowLabelAlignment() -> (horiz, vert)");
1696 void, GetColLabelAlignment( int *OUTPUT, int *OUTPUT ),
1697 "GetColLabelAlignment() -> (horiz, vert)");
1699 int GetColLabelTextOrientation();
1700 wxString GetRowLabelValue( int row );
1701 wxString GetColLabelValue( int col );
1702 wxColour GetGridLineColour();
1703 wxColour GetCellHighlightColour();
1704 int GetCellHighlightPenWidth();
1705 int GetCellHighlightROPenWidth();
1707 void SetRowLabelSize( int width );
1708 void SetColLabelSize( int height );
1709 void SetLabelBackgroundColour( const wxColour& );
1710 void SetLabelTextColour( const wxColour& );
1711 void SetLabelFont( const wxFont& );
1712 void SetRowLabelAlignment( int horiz, int vert );
1713 void SetColLabelAlignment( int horiz, int vert );
1714 void SetColLabelTextOrientation( int textOrientation );
1715 void SetRowLabelValue( int row, const wxString& );
1716 void SetColLabelValue( int col, const wxString& );
1717 void SetGridLineColour( const wxColour& );
1718 void SetCellHighlightColour( const wxColour& );
1719 void SetCellHighlightPenWidth(int width);
1720 void SetCellHighlightROPenWidth(int width);
1722 void EnableDragRowSize( bool enable = True );
1723 void DisableDragRowSize();
1724 bool CanDragRowSize();
1725 void EnableDragColSize( bool enable = True );
1726 void DisableDragColSize();
1727 bool CanDragColSize();
1728 void EnableDragGridSize(bool enable = True);
1729 void DisableDragGridSize();
1730 bool CanDragGridSize();
1732 // this sets the specified attribute for all cells in this row/col
1733 void SetAttr(int row, int col, wxGridCellAttr *attr);
1734 void SetRowAttr(int row, wxGridCellAttr *attr);
1735 void SetColAttr(int col, wxGridCellAttr *attr);
1737 // shortcuts for setting the column parameters
1739 // set the format for the data in the column: default is string
1740 void SetColFormatBool(int col);
1741 void SetColFormatNumber(int col);
1742 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1743 void SetColFormatCustom(int col, const wxString& typeName);
1745 void EnableGridLines( bool enable = True );
1746 bool GridLinesEnabled();
1748 // ------ row and col formatting
1750 int GetDefaultRowSize();
1751 int GetRowSize( int row );
1752 int GetDefaultColSize();
1753 int GetColSize( int col );
1754 wxColour GetDefaultCellBackgroundColour();
1755 wxColour GetCellBackgroundColour( int row, int col );
1756 wxColour GetDefaultCellTextColour();
1757 wxColour GetCellTextColour( int row, int col );
1758 wxFont GetDefaultCellFont();
1759 wxFont GetCellFont( int row, int col );
1762 void, GetDefaultCellAlignment( int *OUTPUT, int *OUTPUT ),
1763 "GetDefaultCellAlignment() -> (horiz, vert)");
1766 void, GetCellAlignment( int row, int col, int *OUTPUT, int *OUTPUT ),
1767 "GetCellAlignment() -> (horiz, vert)");
1769 bool GetDefaultCellOverflow();
1770 bool GetCellOverflow( int row, int col );
1773 void, GetCellSize( int row, int col, int *OUTPUT, int *OUTPUT ),
1774 "GetCellSize(int row, int col) -> (num_rows, num_cols)");
1776 void SetDefaultRowSize( int height, bool resizeExistingRows = False );
1777 void SetRowSize( int row, int height );
1778 void SetDefaultColSize( int width, bool resizeExistingCols = False );
1780 void SetColSize( int col, int width );
1782 // automatically size the column or row to fit to its contents, if
1783 // setAsMin is True, this optimal width will also be set as minimal width
1785 void AutoSizeColumn( int col, bool setAsMin = True );
1786 void AutoSizeRow( int row, bool setAsMin = True );
1789 // auto size all columns (very ineffective for big grids!)
1790 void AutoSizeColumns( bool setAsMin = True );
1791 void AutoSizeRows( bool setAsMin = True );
1793 // auto size the grid, that is make the columns/rows of the "right" size
1794 // and also set the grid size to just fit its contents
1797 // autosize row height depending on label text
1798 void AutoSizeRowLabelSize( int row );
1800 // autosize column width depending on label text
1801 void AutoSizeColLabelSize( int col );
1804 // column won't be resized to be lesser width - this must be called during
1805 // the grid creation because it won't resize the column if it's already
1806 // narrower than the minimal width
1807 void SetColMinimalWidth( int col, int width );
1808 void SetRowMinimalHeight( int row, int width );
1810 void SetColMinimalAcceptableWidth( int width );
1811 void SetRowMinimalAcceptableHeight( int width );
1812 int GetColMinimalAcceptableWidth() const;
1813 int GetRowMinimalAcceptableHeight() const;
1815 void SetDefaultCellBackgroundColour( const wxColour& );
1816 void SetCellBackgroundColour( int row, int col, const wxColour& );
1817 void SetDefaultCellTextColour( const wxColour& );
1819 void SetCellTextColour( int row, int col, const wxColour& );
1820 void SetDefaultCellFont( const wxFont& );
1821 void SetCellFont( int row, int col, const wxFont& );
1822 void SetDefaultCellAlignment( int horiz, int vert );
1823 void SetCellAlignment( int row, int col, int horiz, int vert );
1824 void SetDefaultCellOverflow( bool allow );
1825 void SetCellOverflow( int row, int col, bool allow );
1826 void SetCellSize( int row, int col, int num_rows, int num_cols );
1828 // takes ownership of the pointer
1829 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1830 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1831 wxGridCellRenderer *GetDefaultRenderer() const;
1832 wxGridCellRenderer* GetCellRenderer(int row, int col);
1834 // takes ownership of the pointer
1835 void SetDefaultEditor(wxGridCellEditor *editor);
1836 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1837 wxGridCellEditor *GetDefaultEditor() const;
1838 wxGridCellEditor* GetCellEditor(int row, int col);
1842 // ------ cell value accessors
1844 wxString GetCellValue( int row, int col );
1845 // TODO: ??? wxString GetCellValue( const wxGridCellCoords& coords )
1847 void SetCellValue( int row, int col, const wxString& s );
1848 // TODO: ??? void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1850 // returns True if the cell can't be edited
1851 bool IsReadOnly(int row, int col) const;
1853 // make the cell editable/readonly
1854 void SetReadOnly(int row, int col, bool isReadOnly = True);
1856 // ------ selections of blocks of cells
1858 void SelectRow( int row, bool addToSelected = False );
1859 void SelectCol( int col, bool addToSelected = False );
1861 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1862 bool addToSelected = False );
1863 // TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
1864 // TODO: ??? const wxGridCellCoords& bottomRight )
1868 void ClearSelection();
1869 bool IsInSelection( int row, int col );
1870 // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords )
1872 const wxGridCellCoordsArray GetSelectedCells() const;
1873 const wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1874 const wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1875 const wxArrayInt GetSelectedRows() const;
1876 const wxArrayInt GetSelectedCols() const;
1878 void DeselectRow( int row );
1879 void DeselectCol( int col );
1880 void DeselectCell( int row, int col );
1883 // This function returns the rectangle that encloses the block of cells
1884 // limited by TopLeft and BottomRight cell in device coords and clipped
1885 // to the client size of the grid window.
1887 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1888 const wxGridCellCoords & bottomRight );
1891 // Access or update the selection fore/back colours
1892 wxColour GetSelectionBackground() const;
1893 wxColour GetSelectionForeground() const;
1895 void SetSelectionBackground(const wxColour& c);
1896 void SetSelectionForeground(const wxColour& c);
1899 // Methods for a registry for mapping data types to Renderers/Editors
1900 void RegisterDataType(const wxString& typeName,
1901 wxGridCellRenderer* renderer,
1902 wxGridCellEditor* editor);
1903 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1904 // TODO: ??? wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1905 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1906 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1907 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1909 // grid may occupy more space than needed for its rows/columns, this
1910 // function allows to set how big this extra space is
1911 void SetMargins(int extraWidth, int extraHeight);
1914 // Accessors for component windows
1915 wxWindow* GetGridWindow();
1916 wxWindow* GetGridRowLabelWindow();
1917 wxWindow* GetGridColLabelWindow();
1918 wxWindow* GetGridCornerLabelWindow();
1924 //---------------------------------------------------------------------------
1925 //---------------------------------------------------------------------------
1926 // Grid events and stuff
1930 class wxGridEvent : public wxNotifyEvent
1933 wxGridEvent(int id, wxEventType type, wxGrid* obj,
1934 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = True,
1935 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1937 virtual int GetRow();
1938 virtual int GetCol();
1939 wxPoint GetPosition();
1949 class wxGridSizeEvent : public wxNotifyEvent
1952 wxGridSizeEvent(int id, wxEventType type, wxGrid* obj,
1953 int rowOrCol=-1, int x=-1, int y=-1,
1954 bool control=False, bool shift=False, bool alt=False, bool meta=False);
1957 wxPoint GetPosition();
1966 class wxGridRangeSelectEvent : public wxNotifyEvent
1969 wxGridRangeSelectEvent(int id, wxEventType type, wxGrid* obj,
1970 const wxGridCellCoords& topLeft,
1971 const wxGridCellCoords& bottomRight,
1973 bool control=False, bool shift=False,
1974 bool alt=False, bool meta=False);
1976 wxGridCellCoords GetTopLeftCoords();
1977 wxGridCellCoords GetBottomRightCoords();
1990 class wxGridEditorCreatedEvent : public wxCommandEvent {
1992 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1993 int row, int col, wxControl* ctrl);
1997 wxControl* GetControl();
1998 void SetRow(int row);
1999 void SetCol(int col);
2000 void SetControl(wxControl* ctrl);
2005 %constant wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2006 %constant wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2007 %constant wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2008 %constant wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2009 %constant wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2010 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2011 %constant wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2012 %constant wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2013 %constant wxEventType wxEVT_GRID_ROW_SIZE;
2014 %constant wxEventType wxEVT_GRID_COL_SIZE;
2015 %constant wxEventType wxEVT_GRID_RANGE_SELECT;
2016 %constant wxEventType wxEVT_GRID_CELL_CHANGE;
2017 %constant wxEventType wxEVT_GRID_SELECT_CELL;
2018 %constant wxEventType wxEVT_GRID_EDITOR_SHOWN;
2019 %constant wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2020 %constant wxEventType wxEVT_GRID_EDITOR_CREATED;
2025 EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
2026 EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
2027 EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
2028 EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
2029 EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
2030 EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
2031 EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
2032 EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
2033 EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
2034 EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
2035 EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
2036 EVT_GRID_CELL_CHANGE = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGE )
2037 EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
2038 EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
2039 EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
2040 EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
2043 //---------------------------------------------------------------------------
2048 //---------------------------------------------------------------------------
2049 //---------------------------------------------------------------------------